8352748: Remove com.sun.tools.classfile from the JDK
Reviewed-by: ihse, jlahoda, vromero
This commit is contained in:
parent
e87ff328d5
commit
5c438c5e6b
@ -60,7 +60,7 @@ $(eval $(call SetupJavaCompilation, COMPILE_CREATE_SYMBOLS, \
|
||||
TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK), \
|
||||
COMPILER := buildjdk, \
|
||||
SRC := $(TOPDIR)/make/langtools/src/classes, \
|
||||
INCLUDES := build/tools/symbolgenerator com/sun/tools/classfile, \
|
||||
INCLUDES := build/tools/symbolgenerator, \
|
||||
BIN := $(BUILDTOOLS_OUTPUTDIR)/create_symbols_javac, \
|
||||
DISABLED_WARNINGS := options, \
|
||||
JAVAC_FLAGS := \
|
||||
|
@ -51,7 +51,7 @@ $(eval $(call SetupJavaCompilation, COMPILE_CREATE_SYMBOLS, \
|
||||
TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \
|
||||
SRC := $(TOPDIR)/make/langtools/src/classes \
|
||||
$(TOPDIR)/src/jdk.jdeps/share/classes, \
|
||||
INCLUDES := build/tools/symbolgenerator com/sun/tools/classfile, \
|
||||
INCLUDES := build/tools/symbolgenerator, \
|
||||
BIN := $(BUILDTOOLS_OUTPUTDIR)/create_symbols_javadoc, \
|
||||
DISABLED_WARNINGS := options, \
|
||||
JAVAC_FLAGS := \
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -41,7 +41,6 @@ import com.sun.tools.javac.util.Assert;
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
// Code duplicated in com.sun.tools.classfile.TypeAnnotation.TargetType
|
||||
public enum TargetType {
|
||||
/** For annotations on a class type parameter declaration. */
|
||||
CLASS_TYPE_PARAMETER(0x00),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -37,7 +37,6 @@ import com.sun.tools.javac.util.*;
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
// Code duplicated in com.sun.tools.classfile.TypeAnnotation.Position
|
||||
public class TypeAnnotationPosition {
|
||||
|
||||
public enum TypePathEntryKind {
|
||||
|
@ -1,259 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* See JVMS, sections 4.2, 4.6, 4.7.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class AccessFlags {
|
||||
public static final int ACC_PUBLIC = 0x0001; // class, inner, field, method
|
||||
public static final int ACC_PRIVATE = 0x0002; // inner, field, method
|
||||
public static final int ACC_PROTECTED = 0x0004; // inner, field, method
|
||||
public static final int ACC_STATIC = 0x0008; // inner, field, method
|
||||
public static final int ACC_FINAL = 0x0010; // class, inner, field, method
|
||||
public static final int ACC_SUPER = 0x0020; // class
|
||||
public static final int ACC_SYNCHRONIZED = 0x0020; // method
|
||||
public static final int ACC_VOLATILE = 0x0040; // field
|
||||
public static final int ACC_BRIDGE = 0x0040; // method
|
||||
public static final int ACC_TRANSIENT = 0x0080; // field
|
||||
public static final int ACC_VARARGS = 0x0080; // method
|
||||
public static final int ACC_NATIVE = 0x0100; // method
|
||||
public static final int ACC_INTERFACE = 0x0200; // class, inner
|
||||
public static final int ACC_ABSTRACT = 0x0400; // class, inner, method
|
||||
public static final int ACC_STRICT = 0x0800; // method
|
||||
public static final int ACC_SYNTHETIC = 0x1000; // class, inner, field, method
|
||||
public static final int ACC_ANNOTATION = 0x2000; // class, inner
|
||||
public static final int ACC_ENUM = 0x4000; // class, inner, field
|
||||
public static final int ACC_MANDATED = 0x8000; // method parameter
|
||||
public static final int ACC_MODULE = 0x8000; // class
|
||||
|
||||
public static enum Kind { Class, InnerClass, Field, Method}
|
||||
|
||||
AccessFlags(ClassReader cr) throws IOException {
|
||||
this(cr.readUnsignedShort());
|
||||
}
|
||||
|
||||
public AccessFlags(int flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public AccessFlags ignore(int mask) {
|
||||
return new AccessFlags(flags & ~mask);
|
||||
}
|
||||
|
||||
public boolean is(int mask) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
|
||||
public int byteLength() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
private static final int[] classModifiers = {
|
||||
ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT
|
||||
};
|
||||
|
||||
private static final int[] classFlags = {
|
||||
ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, ACC_ABSTRACT,
|
||||
ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE
|
||||
};
|
||||
|
||||
public Set<String> getClassModifiers() {
|
||||
int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
|
||||
return getModifiers(f, classModifiers, Kind.Class);
|
||||
}
|
||||
|
||||
public Set<String> getClassFlags() {
|
||||
return getFlags(classFlags, Kind.Class);
|
||||
}
|
||||
|
||||
private static final int[] innerClassModifiers = {
|
||||
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
|
||||
ACC_ABSTRACT
|
||||
};
|
||||
|
||||
private static final int[] innerClassFlags = {
|
||||
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER,
|
||||
ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM
|
||||
};
|
||||
|
||||
public Set<String> getInnerClassModifiers() {
|
||||
int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
|
||||
return getModifiers(f, innerClassModifiers, Kind.InnerClass);
|
||||
}
|
||||
|
||||
public Set<String> getInnerClassFlags() {
|
||||
return getFlags(innerClassFlags, Kind.InnerClass);
|
||||
}
|
||||
|
||||
private static final int[] fieldModifiers = {
|
||||
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
|
||||
ACC_VOLATILE, ACC_TRANSIENT
|
||||
};
|
||||
|
||||
private static final int[] fieldFlags = {
|
||||
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
|
||||
ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM
|
||||
};
|
||||
|
||||
public Set<String> getFieldModifiers() {
|
||||
return getModifiers(fieldModifiers, Kind.Field);
|
||||
}
|
||||
|
||||
public Set<String> getFieldFlags() {
|
||||
return getFlags(fieldFlags, Kind.Field);
|
||||
}
|
||||
|
||||
private static final int[] methodModifiers = {
|
||||
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
|
||||
ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT
|
||||
};
|
||||
|
||||
private static final int[] methodFlags = {
|
||||
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
|
||||
ACC_SYNCHRONIZED, ACC_BRIDGE, ACC_VARARGS, ACC_NATIVE, ACC_ABSTRACT,
|
||||
ACC_STRICT, ACC_SYNTHETIC
|
||||
};
|
||||
|
||||
public Set<String> getMethodModifiers() {
|
||||
return getModifiers(methodModifiers, Kind.Method);
|
||||
}
|
||||
|
||||
public Set<String> getMethodFlags() {
|
||||
return getFlags(methodFlags, Kind.Method);
|
||||
}
|
||||
|
||||
private Set<String> getModifiers(int[] modifierFlags, Kind t) {
|
||||
return getModifiers(flags, modifierFlags, t);
|
||||
}
|
||||
|
||||
private static Set<String> getModifiers(int flags, int[] modifierFlags, Kind t) {
|
||||
Set<String> s = new LinkedHashSet<>();
|
||||
for (int m: modifierFlags) {
|
||||
if ((flags & m) != 0)
|
||||
s.add(flagToModifier(m, t));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private Set<String> getFlags(int[] expectedFlags, Kind t) {
|
||||
Set<String> s = new LinkedHashSet<>();
|
||||
int f = flags;
|
||||
for (int e: expectedFlags) {
|
||||
if ((f & e) != 0) {
|
||||
s.add(flagToName(e, t));
|
||||
f = f & ~e;
|
||||
}
|
||||
}
|
||||
while (f != 0) {
|
||||
int bit = Integer.highestOneBit(f);
|
||||
s.add("0x" + Integer.toHexString(bit));
|
||||
f = f & ~bit;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static String flagToModifier(int flag, Kind t) {
|
||||
switch (flag) {
|
||||
case ACC_PUBLIC:
|
||||
return "public";
|
||||
case ACC_PRIVATE:
|
||||
return "private";
|
||||
case ACC_PROTECTED:
|
||||
return "protected";
|
||||
case ACC_STATIC:
|
||||
return "static";
|
||||
case ACC_FINAL:
|
||||
return "final";
|
||||
case ACC_SYNCHRONIZED:
|
||||
return "synchronized";
|
||||
case 0x80:
|
||||
return (t == Kind.Field ? "transient" : null);
|
||||
case ACC_VOLATILE:
|
||||
return "volatile";
|
||||
case ACC_NATIVE:
|
||||
return "native";
|
||||
case ACC_ABSTRACT:
|
||||
return "abstract";
|
||||
case ACC_STRICT:
|
||||
return "strictfp";
|
||||
case ACC_MANDATED:
|
||||
return "mandated";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String flagToName(int flag, Kind t) {
|
||||
switch (flag) {
|
||||
case ACC_PUBLIC:
|
||||
return "ACC_PUBLIC";
|
||||
case ACC_PRIVATE:
|
||||
return "ACC_PRIVATE";
|
||||
case ACC_PROTECTED:
|
||||
return "ACC_PROTECTED";
|
||||
case ACC_STATIC:
|
||||
return "ACC_STATIC";
|
||||
case ACC_FINAL:
|
||||
return "ACC_FINAL";
|
||||
case 0x20:
|
||||
return (t == Kind.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED");
|
||||
case 0x40:
|
||||
return (t == Kind.Field ? "ACC_VOLATILE" : "ACC_BRIDGE");
|
||||
case 0x80:
|
||||
return (t == Kind.Field ? "ACC_TRANSIENT" : "ACC_VARARGS");
|
||||
case ACC_NATIVE:
|
||||
return "ACC_NATIVE";
|
||||
case ACC_INTERFACE:
|
||||
return "ACC_INTERFACE";
|
||||
case ACC_ABSTRACT:
|
||||
return "ACC_ABSTRACT";
|
||||
case ACC_STRICT:
|
||||
return "ACC_STRICT";
|
||||
case ACC_SYNTHETIC:
|
||||
return "ACC_SYNTHETIC";
|
||||
case ACC_ANNOTATION:
|
||||
return "ACC_ANNOTATION";
|
||||
case ACC_ENUM:
|
||||
return "ACC_ENUM";
|
||||
case 0x8000:
|
||||
return (t == Kind.Class ? "ACC_MODULE" : "ACC_MANDATED");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final int flags;
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.16.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Annotation {
|
||||
static class InvalidAnnotation extends AttributeException {
|
||||
private static final long serialVersionUID = -4620480740735772708L;
|
||||
InvalidAnnotation(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
Annotation(ClassReader cr) throws IOException, InvalidAnnotation {
|
||||
type_index = cr.readUnsignedShort();
|
||||
num_element_value_pairs = cr.readUnsignedShort();
|
||||
element_value_pairs = new element_value_pair[num_element_value_pairs];
|
||||
for (int i = 0; i < element_value_pairs.length; i++)
|
||||
element_value_pairs[i] = new element_value_pair(cr);
|
||||
}
|
||||
|
||||
public Annotation(ConstantPool constant_pool,
|
||||
int type_index,
|
||||
element_value_pair[] element_value_pairs) {
|
||||
this.type_index = type_index;
|
||||
num_element_value_pairs = element_value_pairs.length;
|
||||
this.element_value_pairs = element_value_pairs;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
int n = 2 /*type_index*/ + 2 /*num_element_value_pairs*/;
|
||||
for (element_value_pair pair: element_value_pairs)
|
||||
n += pair.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public final int type_index;
|
||||
public final int num_element_value_pairs;
|
||||
public final element_value_pair element_value_pairs[];
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.16.1.
|
||||
*/
|
||||
public abstract static class element_value {
|
||||
public static element_value read(ClassReader cr)
|
||||
throws IOException, InvalidAnnotation {
|
||||
int tag = cr.readUnsignedByte();
|
||||
switch (tag) {
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'F':
|
||||
case 'I':
|
||||
case 'J':
|
||||
case 'S':
|
||||
case 'Z':
|
||||
case 's':
|
||||
return new Primitive_element_value(cr, tag);
|
||||
|
||||
case 'e':
|
||||
return new Enum_element_value(cr, tag);
|
||||
|
||||
case 'c':
|
||||
return new Class_element_value(cr, tag);
|
||||
|
||||
case '@':
|
||||
return new Annotation_element_value(cr, tag);
|
||||
|
||||
case '[':
|
||||
return new Array_element_value(cr, tag);
|
||||
|
||||
default:
|
||||
throw new InvalidAnnotation("unrecognized tag: " + tag);
|
||||
}
|
||||
}
|
||||
|
||||
protected element_value(int tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public abstract int length();
|
||||
|
||||
public abstract <R,P> R accept(Visitor<R,P> visitor, P p);
|
||||
|
||||
public interface Visitor<R,P> {
|
||||
R visitPrimitive(Primitive_element_value ev, P p);
|
||||
R visitEnum(Enum_element_value ev, P p);
|
||||
R visitClass(Class_element_value ev, P p);
|
||||
R visitAnnotation(Annotation_element_value ev, P p);
|
||||
R visitArray(Array_element_value ev, P p);
|
||||
}
|
||||
|
||||
public final int tag;
|
||||
}
|
||||
|
||||
public static class Primitive_element_value extends element_value {
|
||||
Primitive_element_value(ClassReader cr, int tag) throws IOException {
|
||||
super(tag);
|
||||
const_value_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Primitive_element_value(int const_value_index, int tag) {
|
||||
super(tag);
|
||||
this.const_value_index = const_value_index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public <R,P> R accept(Visitor<R,P> visitor, P p) {
|
||||
return visitor.visitPrimitive(this, p);
|
||||
}
|
||||
|
||||
public final int const_value_index;
|
||||
|
||||
}
|
||||
|
||||
public static class Enum_element_value extends element_value {
|
||||
Enum_element_value(ClassReader cr, int tag) throws IOException {
|
||||
super(tag);
|
||||
type_name_index = cr.readUnsignedShort();
|
||||
const_name_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Enum_element_value(int type_name_index, int const_name_index, int tag) {
|
||||
super(tag);
|
||||
this.type_name_index = type_name_index;
|
||||
this.const_name_index = const_name_index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
public <R,P> R accept(Visitor<R,P> visitor, P p) {
|
||||
return visitor.visitEnum(this, p);
|
||||
}
|
||||
|
||||
public final int type_name_index;
|
||||
public final int const_name_index;
|
||||
}
|
||||
|
||||
public static class Class_element_value extends element_value {
|
||||
Class_element_value(ClassReader cr, int tag) throws IOException {
|
||||
super(tag);
|
||||
class_info_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Class_element_value(int class_info_index, int tag) {
|
||||
super(tag);
|
||||
this.class_info_index = class_info_index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public <R,P> R accept(Visitor<R,P> visitor, P p) {
|
||||
return visitor.visitClass(this, p);
|
||||
}
|
||||
|
||||
public final int class_info_index;
|
||||
}
|
||||
|
||||
public static class Annotation_element_value extends element_value {
|
||||
Annotation_element_value(ClassReader cr, int tag)
|
||||
throws IOException, InvalidAnnotation {
|
||||
super(tag);
|
||||
annotation_value = new Annotation(cr);
|
||||
}
|
||||
|
||||
public Annotation_element_value(Annotation annotation_value, int tag) {
|
||||
super(tag);
|
||||
this.annotation_value = annotation_value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return annotation_value.length();
|
||||
}
|
||||
|
||||
public <R,P> R accept(Visitor<R,P> visitor, P p) {
|
||||
return visitor.visitAnnotation(this, p);
|
||||
}
|
||||
|
||||
public final Annotation annotation_value;
|
||||
}
|
||||
|
||||
public static class Array_element_value extends element_value {
|
||||
Array_element_value(ClassReader cr, int tag)
|
||||
throws IOException, InvalidAnnotation {
|
||||
super(tag);
|
||||
num_values = cr.readUnsignedShort();
|
||||
values = new element_value[num_values];
|
||||
for (int i = 0; i < values.length; i++)
|
||||
values[i] = element_value.read(cr);
|
||||
}
|
||||
|
||||
public Array_element_value(element_value[] values, int tag) {
|
||||
super(tag);
|
||||
this.num_values = values.length;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
int n = 2;
|
||||
for (int i = 0; i < values.length; i++)
|
||||
n += values[i].length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public <R,P> R accept(Visitor<R,P> visitor, P p) {
|
||||
return visitor.visitArray(this, p);
|
||||
}
|
||||
|
||||
public final int num_values;
|
||||
public final element_value[] values;
|
||||
}
|
||||
|
||||
public static class element_value_pair {
|
||||
element_value_pair(ClassReader cr)
|
||||
throws IOException, InvalidAnnotation {
|
||||
element_name_index = cr.readUnsignedShort();
|
||||
value = element_value.read(cr);
|
||||
}
|
||||
|
||||
public element_value_pair(int element_name_index, element_value value) {
|
||||
this.element_name_index = element_name_index;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return 2 + value.length();
|
||||
}
|
||||
|
||||
public final int element_name_index;
|
||||
public final element_value value;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class AnnotationDefault_attribute extends Attribute {
|
||||
AnnotationDefault_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(name_index, length);
|
||||
default_value = Annotation.element_value.read(cr);
|
||||
}
|
||||
|
||||
public AnnotationDefault_attribute(ConstantPool constant_pool, Annotation.element_value default_value)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.AnnotationDefault), default_value);
|
||||
}
|
||||
|
||||
public AnnotationDefault_attribute(int name_index, Annotation.element_value default_value) {
|
||||
super(name_index, default_value.length());
|
||||
this.default_value = default_value;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitAnnotationDefault(this, data);
|
||||
}
|
||||
|
||||
public final Annotation.element_value default_value;
|
||||
}
|
||||
|
@ -1,222 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
|
||||
public abstract class Attribute {
|
||||
public static final String AnnotationDefault = "AnnotationDefault";
|
||||
public static final String BootstrapMethods = "BootstrapMethods";
|
||||
public static final String CharacterRangeTable = "CharacterRangeTable";
|
||||
public static final String Code = "Code";
|
||||
public static final String ConstantValue = "ConstantValue";
|
||||
public static final String CompilationID = "CompilationID";
|
||||
public static final String Deprecated = "Deprecated";
|
||||
public static final String EnclosingMethod = "EnclosingMethod";
|
||||
public static final String Exceptions = "Exceptions";
|
||||
public static final String InnerClasses = "InnerClasses";
|
||||
public static final String LineNumberTable = "LineNumberTable";
|
||||
public static final String LocalVariableTable = "LocalVariableTable";
|
||||
public static final String LocalVariableTypeTable = "LocalVariableTypeTable";
|
||||
public static final String MethodParameters = "MethodParameters";
|
||||
public static final String Module = "Module";
|
||||
public static final String ModuleHashes = "ModuleHashes";
|
||||
public static final String ModuleMainClass = "ModuleMainClass";
|
||||
public static final String ModulePackages = "ModulePackages";
|
||||
public static final String ModuleResolution = "ModuleResolution";
|
||||
public static final String ModuleTarget = "ModuleTarget";
|
||||
public static final String NestHost = "NestHost";
|
||||
public static final String NestMembers = "NestMembers";
|
||||
public static final String Record = "Record";
|
||||
public static final String RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations";
|
||||
public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
|
||||
public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
|
||||
public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations";
|
||||
public static final String RuntimeVisibleTypeAnnotations = "RuntimeVisibleTypeAnnotations";
|
||||
public static final String RuntimeInvisibleTypeAnnotations = "RuntimeInvisibleTypeAnnotations";
|
||||
public static final String PermittedSubclasses = "PermittedSubclasses";
|
||||
public static final String Signature = "Signature";
|
||||
public static final String SourceDebugExtension = "SourceDebugExtension";
|
||||
public static final String SourceFile = "SourceFile";
|
||||
public static final String SourceID = "SourceID";
|
||||
public static final String StackMap = "StackMap";
|
||||
public static final String StackMapTable = "StackMapTable";
|
||||
public static final String Synthetic = "Synthetic";
|
||||
|
||||
public static class Factory {
|
||||
public Factory() {
|
||||
// defer init of standardAttributeClasses until after options set up
|
||||
}
|
||||
|
||||
public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
|
||||
throws IOException {
|
||||
if (standardAttributes == null) {
|
||||
init();
|
||||
}
|
||||
|
||||
ConstantPool cp = cr.getConstantPool();
|
||||
String reasonForDefaultAttr;
|
||||
try {
|
||||
String name = cp.getUTF8Value(name_index);
|
||||
Class<? extends Attribute> attrClass = standardAttributes.get(name);
|
||||
if (attrClass != null) {
|
||||
try {
|
||||
Class<?>[] constrArgTypes = {ClassReader.class, int.class, int.class};
|
||||
Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
|
||||
return constr.newInstance(cr, name_index, data.length);
|
||||
} catch (Throwable t) {
|
||||
reasonForDefaultAttr = t.toString();
|
||||
// fall through and use DefaultAttribute
|
||||
// t.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
reasonForDefaultAttr = "unknown attribute";
|
||||
}
|
||||
} catch (ConstantPoolException e) {
|
||||
reasonForDefaultAttr = e.toString();
|
||||
// fall through and use DefaultAttribute
|
||||
}
|
||||
return new DefaultAttribute(cr, name_index, data, reasonForDefaultAttr);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
standardAttributes = new HashMap<>();
|
||||
standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class);
|
||||
standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class);
|
||||
standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
|
||||
standardAttributes.put(Code, Code_attribute.class);
|
||||
standardAttributes.put(CompilationID, CompilationID_attribute.class);
|
||||
standardAttributes.put(ConstantValue, ConstantValue_attribute.class);
|
||||
standardAttributes.put(Deprecated, Deprecated_attribute.class);
|
||||
standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class);
|
||||
standardAttributes.put(Exceptions, Exceptions_attribute.class);
|
||||
standardAttributes.put(InnerClasses, InnerClasses_attribute.class);
|
||||
standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class);
|
||||
standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class);
|
||||
standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_attribute.class);
|
||||
standardAttributes.put(MethodParameters, MethodParameters_attribute.class);
|
||||
standardAttributes.put(Module, Module_attribute.class);
|
||||
standardAttributes.put(ModuleHashes, ModuleHashes_attribute.class);
|
||||
standardAttributes.put(ModuleMainClass, ModuleMainClass_attribute.class);
|
||||
standardAttributes.put(ModulePackages, ModulePackages_attribute.class);
|
||||
standardAttributes.put(ModuleResolution, ModuleResolution_attribute.class);
|
||||
standardAttributes.put(ModuleTarget, ModuleTarget_attribute.class);
|
||||
standardAttributes.put(NestHost, NestHost_attribute.class);
|
||||
standardAttributes.put(NestMembers, NestMembers_attribute.class);
|
||||
standardAttributes.put(Record, Record_attribute.class);
|
||||
standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class);
|
||||
standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
|
||||
standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
|
||||
standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class);
|
||||
standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class);
|
||||
standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class);
|
||||
standardAttributes.put(PermittedSubclasses, PermittedSubclasses_attribute.class);
|
||||
standardAttributes.put(Signature, Signature_attribute.class);
|
||||
standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class);
|
||||
standardAttributes.put(SourceFile, SourceFile_attribute.class);
|
||||
standardAttributes.put(SourceID, SourceID_attribute.class);
|
||||
standardAttributes.put(StackMap, StackMap_attribute.class);
|
||||
standardAttributes.put(StackMapTable, StackMapTable_attribute.class);
|
||||
standardAttributes.put(Synthetic, Synthetic_attribute.class);
|
||||
}
|
||||
|
||||
private Map<String,Class<? extends Attribute>> standardAttributes;
|
||||
}
|
||||
|
||||
public static Attribute read(ClassReader cr) throws IOException {
|
||||
return cr.readAttribute();
|
||||
}
|
||||
|
||||
protected Attribute(int name_index, int length) {
|
||||
attribute_name_index = name_index;
|
||||
attribute_length = length;
|
||||
}
|
||||
|
||||
public String getName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(attribute_name_index);
|
||||
}
|
||||
|
||||
public abstract <R,D> R accept(Attribute.Visitor<R,D> visitor, D data);
|
||||
|
||||
public int byteLength() {
|
||||
return 6 + attribute_length;
|
||||
}
|
||||
|
||||
public final int attribute_name_index;
|
||||
public final int attribute_length;
|
||||
|
||||
|
||||
public interface Visitor<R,P> {
|
||||
R visitBootstrapMethods(BootstrapMethods_attribute attr, P p);
|
||||
R visitDefault(DefaultAttribute attr, P p);
|
||||
R visitAnnotationDefault(AnnotationDefault_attribute attr, P p);
|
||||
R visitCharacterRangeTable(CharacterRangeTable_attribute attr, P p);
|
||||
R visitCode(Code_attribute attr, P p);
|
||||
R visitCompilationID(CompilationID_attribute attr, P p);
|
||||
R visitConstantValue(ConstantValue_attribute attr, P p);
|
||||
R visitDeprecated(Deprecated_attribute attr, P p);
|
||||
R visitEnclosingMethod(EnclosingMethod_attribute attr, P p);
|
||||
R visitExceptions(Exceptions_attribute attr, P p);
|
||||
R visitInnerClasses(InnerClasses_attribute attr, P p);
|
||||
R visitLineNumberTable(LineNumberTable_attribute attr, P p);
|
||||
R visitLocalVariableTable(LocalVariableTable_attribute attr, P p);
|
||||
R visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, P p);
|
||||
R visitMethodParameters(MethodParameters_attribute attr, P p);
|
||||
R visitModule(Module_attribute attr, P p);
|
||||
R visitModuleHashes(ModuleHashes_attribute attr, P p);
|
||||
R visitModuleMainClass(ModuleMainClass_attribute attr, P p);
|
||||
R visitModulePackages(ModulePackages_attribute attr, P p);
|
||||
R visitModuleResolution(ModuleResolution_attribute attr, P p);
|
||||
R visitModuleTarget(ModuleTarget_attribute attr, P p);
|
||||
R visitNestHost(NestHost_attribute attr, P p);
|
||||
R visitNestMembers(NestMembers_attribute attr, P p);
|
||||
R visitRecord(Record_attribute attr, P p);
|
||||
R visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, P p);
|
||||
R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p);
|
||||
R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p);
|
||||
R visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, P p);
|
||||
R visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, P p);
|
||||
R visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, P p);
|
||||
R visitPermittedSubclasses(PermittedSubclasses_attribute attr, P p);
|
||||
R visitSignature(Signature_attribute attr, P p);
|
||||
R visitSourceDebugExtension(SourceDebugExtension_attribute attr, P p);
|
||||
R visitSourceFile(SourceFile_attribute attr, P p);
|
||||
R visitSourceID(SourceID_attribute attr, P p);
|
||||
R visitStackMap(StackMap_attribute attr, P p);
|
||||
R visitStackMapTable(StackMapTable_attribute attr, P p);
|
||||
R visitSynthetic(Synthetic_attribute attr, P p);
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class AttributeException extends Exception {
|
||||
private static final long serialVersionUID = -4231486387714867770L;
|
||||
AttributeException() { }
|
||||
|
||||
AttributeException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Attributes implements Iterable<Attribute> {
|
||||
|
||||
public final Attribute[] attrs;
|
||||
public final Map<String, Attribute> map;
|
||||
|
||||
Attributes(ClassReader cr) throws IOException {
|
||||
map = new HashMap<>();
|
||||
int attrs_count = cr.readUnsignedShort();
|
||||
attrs = new Attribute[attrs_count];
|
||||
for (int i = 0; i < attrs_count; i++) {
|
||||
Attribute attr = Attribute.read(cr);
|
||||
attrs[i] = attr;
|
||||
try {
|
||||
map.put(attr.getName(cr.getConstantPool()), attr);
|
||||
} catch (ConstantPoolException e) {
|
||||
// don't enter invalid names in map
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes(ConstantPool constant_pool, Attribute[] attrs) {
|
||||
this.attrs = attrs;
|
||||
map = new HashMap<>();
|
||||
for (Attribute attr : attrs) {
|
||||
try {
|
||||
map.put(attr.getName(constant_pool), attr);
|
||||
} catch (ConstantPoolException e) {
|
||||
// don't enter invalid names in map
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes(Map<String, Attribute> attributes) {
|
||||
this.attrs = attributes.values().toArray(new Attribute[attributes.size()]);
|
||||
map = attributes;
|
||||
}
|
||||
|
||||
public Iterator<Attribute> iterator() {
|
||||
return Arrays.asList(attrs).iterator();
|
||||
}
|
||||
|
||||
public Attribute get(int index) {
|
||||
return attrs[index];
|
||||
}
|
||||
|
||||
public Attribute get(String name) {
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
public int getIndex(ConstantPool constant_pool, String name) {
|
||||
for (int i = 0; i < attrs.length; i++) {
|
||||
Attribute attr = attrs[i];
|
||||
try {
|
||||
if (attr != null && attr.getName(constant_pool).equals(name))
|
||||
return i;
|
||||
} catch (ConstantPoolException e) {
|
||||
// ignore invalid entries
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return attrs.length;
|
||||
}
|
||||
|
||||
public int byteLength() {
|
||||
int length = 2;
|
||||
for (Attribute a: attrs)
|
||||
length += a.byteLength();
|
||||
return length;
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS 4.7.21
|
||||
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.21
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class BootstrapMethods_attribute extends Attribute {
|
||||
public final BootstrapMethodSpecifier[] bootstrap_method_specifiers;
|
||||
|
||||
BootstrapMethods_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, AttributeException {
|
||||
super(name_index, length);
|
||||
int bootstrap_method_count = cr.readUnsignedShort();
|
||||
bootstrap_method_specifiers = new BootstrapMethodSpecifier[bootstrap_method_count];
|
||||
for (int i = 0; i < bootstrap_method_specifiers.length; i++)
|
||||
bootstrap_method_specifiers[i] = new BootstrapMethodSpecifier(cr);
|
||||
}
|
||||
|
||||
public BootstrapMethods_attribute(int name_index, BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
|
||||
super(name_index, length(bootstrap_method_specifiers));
|
||||
this.bootstrap_method_specifiers = bootstrap_method_specifiers;
|
||||
}
|
||||
|
||||
public static int length(BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
|
||||
int n = 2;
|
||||
for (BootstrapMethodSpecifier b : bootstrap_method_specifiers)
|
||||
n += b.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitBootstrapMethods(this, p);
|
||||
}
|
||||
|
||||
public static class BootstrapMethodSpecifier {
|
||||
public int bootstrap_method_ref;
|
||||
public int[] bootstrap_arguments;
|
||||
|
||||
public BootstrapMethodSpecifier(int bootstrap_method_ref, int[] bootstrap_arguments) {
|
||||
this.bootstrap_method_ref = bootstrap_method_ref;
|
||||
this.bootstrap_arguments = bootstrap_arguments;
|
||||
}
|
||||
BootstrapMethodSpecifier(ClassReader cr) throws IOException {
|
||||
bootstrap_method_ref = cr.readUnsignedShort();
|
||||
int method_count = cr.readUnsignedShort();
|
||||
bootstrap_arguments = new int[method_count];
|
||||
for (int i = 0; i < bootstrap_arguments.length; i++) {
|
||||
bootstrap_arguments[i] = cr.readUnsignedShort();
|
||||
}
|
||||
}
|
||||
|
||||
int length() {
|
||||
// u2 (method_ref) + u2 (argc) + u2 * argc
|
||||
return 2 + 2 + (bootstrap_arguments.length * 2);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class CharacterRangeTable_attribute extends Attribute {
|
||||
public static final int CRT_STATEMENT = 0x0001;
|
||||
public static final int CRT_BLOCK = 0x0002;
|
||||
public static final int CRT_ASSIGNMENT = 0x0004;
|
||||
public static final int CRT_FLOW_CONTROLLER = 0x0008;
|
||||
public static final int CRT_FLOW_TARGET = 0x0010;
|
||||
public static final int CRT_INVOKE = 0x0020;
|
||||
public static final int CRT_CREATE = 0x0040;
|
||||
public static final int CRT_BRANCH_TRUE = 0x0080;
|
||||
public static final int CRT_BRANCH_FALSE = 0x0100;
|
||||
|
||||
CharacterRangeTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
int character_range_table_length = cr.readUnsignedShort();
|
||||
character_range_table = new Entry[character_range_table_length];
|
||||
for (int i = 0; i < character_range_table_length; i++)
|
||||
character_range_table[i] = new Entry(cr);
|
||||
}
|
||||
|
||||
public CharacterRangeTable_attribute(ConstantPool constant_pool, Entry[] character_range_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.CharacterRangeTable), character_range_table);
|
||||
}
|
||||
|
||||
public CharacterRangeTable_attribute(int name_index, Entry[] character_range_table) {
|
||||
super(name_index, 2 + character_range_table.length * Entry.length());
|
||||
this.character_range_table = character_range_table;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitCharacterRangeTable(this, data);
|
||||
}
|
||||
|
||||
public final Entry[] character_range_table;
|
||||
|
||||
public static class Entry {
|
||||
Entry(ClassReader cr) throws IOException {
|
||||
start_pc = cr.readUnsignedShort();
|
||||
end_pc = cr.readUnsignedShort();
|
||||
character_range_start = cr.readInt();
|
||||
character_range_end = cr.readInt();
|
||||
flags = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public static int length() {
|
||||
return 14;
|
||||
}
|
||||
|
||||
public final int start_pc;
|
||||
public final int end_pc;
|
||||
public final int character_range_start;
|
||||
public final int character_range_end;
|
||||
public final int flags;
|
||||
}
|
||||
}
|
@ -1,189 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static com.sun.tools.classfile.AccessFlags.*;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.2.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ClassFile {
|
||||
public static ClassFile read(File file)
|
||||
throws IOException, ConstantPoolException {
|
||||
return read(file.toPath(), new Attribute.Factory());
|
||||
}
|
||||
|
||||
public static ClassFile read(Path input)
|
||||
throws IOException, ConstantPoolException {
|
||||
return read(input, new Attribute.Factory());
|
||||
}
|
||||
|
||||
public static ClassFile read(Path input, Attribute.Factory attributeFactory)
|
||||
throws IOException, ConstantPoolException {
|
||||
try (InputStream in = Files.newInputStream(input)) {
|
||||
return new ClassFile(in, attributeFactory);
|
||||
}
|
||||
}
|
||||
|
||||
public static ClassFile read(File file, Attribute.Factory attributeFactory)
|
||||
throws IOException, ConstantPoolException {
|
||||
return read(file.toPath(), attributeFactory);
|
||||
}
|
||||
|
||||
public static ClassFile read(InputStream in)
|
||||
throws IOException, ConstantPoolException {
|
||||
return new ClassFile(in, new Attribute.Factory());
|
||||
}
|
||||
|
||||
public static ClassFile read(InputStream in, Attribute.Factory attributeFactory)
|
||||
throws IOException, ConstantPoolException {
|
||||
return new ClassFile(in, attributeFactory);
|
||||
}
|
||||
|
||||
ClassFile(InputStream in, Attribute.Factory attributeFactory) throws IOException, ConstantPoolException {
|
||||
ClassReader cr = new ClassReader(this, in, attributeFactory);
|
||||
magic = cr.readInt();
|
||||
minor_version = cr.readUnsignedShort();
|
||||
major_version = cr.readUnsignedShort();
|
||||
constant_pool = new ConstantPool(cr);
|
||||
access_flags = new AccessFlags(cr);
|
||||
this_class = cr.readUnsignedShort();
|
||||
super_class = cr.readUnsignedShort();
|
||||
|
||||
int interfaces_count = cr.readUnsignedShort();
|
||||
interfaces = new int[interfaces_count];
|
||||
for (int i = 0; i < interfaces_count; i++)
|
||||
interfaces[i] = cr.readUnsignedShort();
|
||||
|
||||
int fields_count = cr.readUnsignedShort();
|
||||
fields = new Field[fields_count];
|
||||
for (int i = 0; i < fields_count; i++)
|
||||
fields[i] = new Field(cr);
|
||||
|
||||
int methods_count = cr.readUnsignedShort();
|
||||
methods = new Method[methods_count];
|
||||
for (int i = 0; i < methods_count; i++)
|
||||
methods[i] = new Method(cr);
|
||||
|
||||
attributes = new Attributes(cr);
|
||||
}
|
||||
|
||||
public ClassFile(int magic, int minor_version, int major_version,
|
||||
ConstantPool constant_pool, AccessFlags access_flags,
|
||||
int this_class, int super_class, int[] interfaces,
|
||||
Field[] fields, Method[] methods, Attributes attributes) {
|
||||
this.magic = magic;
|
||||
this.minor_version = minor_version;
|
||||
this.major_version = major_version;
|
||||
this.constant_pool = constant_pool;
|
||||
this.access_flags = access_flags;
|
||||
this.this_class = this_class;
|
||||
this.super_class = super_class;
|
||||
this.interfaces = interfaces;
|
||||
this.fields = fields;
|
||||
this.methods = methods;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public String getName() throws ConstantPoolException {
|
||||
return constant_pool.getClassInfo(this_class).getName();
|
||||
}
|
||||
|
||||
public String getSuperclassName() throws ConstantPoolException {
|
||||
return constant_pool.getClassInfo(super_class).getName();
|
||||
}
|
||||
|
||||
public String getInterfaceName(int i) throws ConstantPoolException {
|
||||
return constant_pool.getClassInfo(interfaces[i]).getName();
|
||||
}
|
||||
|
||||
public Attribute getAttribute(String name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
public boolean isClass() {
|
||||
return !isInterface();
|
||||
}
|
||||
|
||||
public boolean isInterface() {
|
||||
return access_flags.is(ACC_INTERFACE);
|
||||
}
|
||||
|
||||
public int byteLength() {
|
||||
return 4 + // magic
|
||||
2 + // minor
|
||||
2 + // major
|
||||
constant_pool.byteLength() +
|
||||
2 + // access flags
|
||||
2 + // this_class
|
||||
2 + // super_class
|
||||
byteLength(interfaces) +
|
||||
byteLength(fields) +
|
||||
byteLength(methods) +
|
||||
attributes.byteLength();
|
||||
}
|
||||
|
||||
private int byteLength(int[] indices) {
|
||||
return 2 + 2 * indices.length;
|
||||
}
|
||||
|
||||
private int byteLength(Field[] fields) {
|
||||
int length = 2;
|
||||
for (Field f: fields)
|
||||
length += f.byteLength();
|
||||
return length;
|
||||
}
|
||||
|
||||
private int byteLength(Method[] methods) {
|
||||
int length = 2;
|
||||
for (Method m: methods)
|
||||
length += m.byteLength();
|
||||
return length;
|
||||
}
|
||||
|
||||
public final int magic;
|
||||
public final int minor_version;
|
||||
public final int major_version;
|
||||
public final ConstantPool constant_pool;
|
||||
public final AccessFlags access_flags;
|
||||
public final int this_class;
|
||||
public final int super_class;
|
||||
public final int[] interfaces;
|
||||
public final Field[] fields;
|
||||
public final Method[] methods;
|
||||
public final Attributes attributes;
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ClassReader {
|
||||
ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException {
|
||||
this.classFile = Objects.requireNonNull(classFile);
|
||||
this.attributeFactory = Objects.requireNonNull(attributeFactory);
|
||||
this.in = new DataInputStream(new BufferedInputStream(in));
|
||||
}
|
||||
|
||||
ClassFile getClassFile() {
|
||||
return classFile;
|
||||
}
|
||||
|
||||
ConstantPool getConstantPool() {
|
||||
return classFile.constant_pool;
|
||||
}
|
||||
|
||||
public Attribute readAttribute() throws IOException {
|
||||
int name_index = readUnsignedShort();
|
||||
int length = readInt();
|
||||
if (length < 0) { // we have an overflow as max_value(u4) > max_value(int)
|
||||
String attrName;
|
||||
try {
|
||||
attrName = getConstantPool().getUTF8Value(name_index);
|
||||
} catch (ConstantPool.InvalidIndex | ConstantPool.UnexpectedEntry e) {
|
||||
attrName = "";
|
||||
}
|
||||
throw new FatalError(String.format("attribute %s too big to handle", attrName));
|
||||
}
|
||||
byte[] data = new byte[length];
|
||||
readFully(data);
|
||||
|
||||
DataInputStream prev = in;
|
||||
in = new DataInputStream(new ByteArrayInputStream(data));
|
||||
try {
|
||||
return attributeFactory.createAttribute(this, name_index, data);
|
||||
} finally {
|
||||
in = prev;
|
||||
}
|
||||
}
|
||||
|
||||
public void readFully(byte[] b) throws IOException {
|
||||
in.readFully(b);
|
||||
}
|
||||
|
||||
public int readUnsignedByte() throws IOException {
|
||||
return in.readUnsignedByte();
|
||||
}
|
||||
|
||||
public int readUnsignedShort() throws IOException {
|
||||
return in.readUnsignedShort();
|
||||
}
|
||||
|
||||
public int readInt() throws IOException {
|
||||
return in.readInt();
|
||||
}
|
||||
|
||||
public long readLong() throws IOException {
|
||||
return in.readLong();
|
||||
}
|
||||
|
||||
public float readFloat() throws IOException {
|
||||
return in.readFloat();
|
||||
}
|
||||
|
||||
public double readDouble() throws IOException {
|
||||
return in.readDouble();
|
||||
}
|
||||
|
||||
public String readUTF() throws IOException {
|
||||
return in.readUTF();
|
||||
}
|
||||
|
||||
private DataInputStream in;
|
||||
private ClassFile classFile;
|
||||
private Attribute.Factory attributeFactory;
|
||||
}
|
@ -1,469 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Dynamic_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Double_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Fieldref_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Float_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_InterfaceMethodref_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_InvokeDynamic_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodType_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Package_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
|
||||
import com.sun.tools.classfile.ConstantPool.CPInfo;
|
||||
|
||||
/**
|
||||
* Rewrites a class file using a map of translations.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ClassTranslator
|
||||
implements ConstantPool.Visitor<ConstantPool.CPInfo,Map<Object,Object>> {
|
||||
/**
|
||||
* Create a new ClassFile from {@code cf}, such that for all entries
|
||||
* {@code k -\> v} in {@code translations},
|
||||
* each occurrence of {@code k} in {@code cf} will be replaced by {@code v}.
|
||||
* in
|
||||
* @param cf the class file to be processed
|
||||
* @param translations the set of translations to be applied
|
||||
* @return a copy of {@code} with the values in {@code translations} substituted
|
||||
*/
|
||||
public ClassFile translate(ClassFile cf, Map<Object,Object> translations) {
|
||||
ClassFile cf2 = (ClassFile) translations.get(cf);
|
||||
if (cf2 == null) {
|
||||
ConstantPool constant_pool2 = translate(cf.constant_pool, translations);
|
||||
Field[] fields2 = translate(cf.fields, cf.constant_pool, translations);
|
||||
Method[] methods2 = translateMethods(cf.methods, cf.constant_pool, translations);
|
||||
Attributes attributes2 = translateAttributes(cf.attributes, cf.constant_pool,
|
||||
translations);
|
||||
|
||||
if (constant_pool2 == cf.constant_pool &&
|
||||
fields2 == cf.fields &&
|
||||
methods2 == cf.methods &&
|
||||
attributes2 == cf.attributes)
|
||||
cf2 = cf;
|
||||
else
|
||||
cf2 = new ClassFile(
|
||||
cf.magic,
|
||||
cf.minor_version,
|
||||
cf.major_version,
|
||||
constant_pool2,
|
||||
cf.access_flags,
|
||||
cf.this_class,
|
||||
cf.super_class,
|
||||
cf.interfaces,
|
||||
fields2,
|
||||
methods2,
|
||||
attributes2);
|
||||
translations.put(cf, cf2);
|
||||
}
|
||||
return cf2;
|
||||
}
|
||||
|
||||
ConstantPool translate(ConstantPool cp, Map<Object,Object> translations) {
|
||||
ConstantPool cp2 = (ConstantPool) translations.get(cp);
|
||||
if (cp2 == null) {
|
||||
ConstantPool.CPInfo[] pool2 = new ConstantPool.CPInfo[cp.size()];
|
||||
boolean eq = true;
|
||||
for (int i = 0; i < cp.size(); ) {
|
||||
ConstantPool.CPInfo cpInfo;
|
||||
try {
|
||||
cpInfo = cp.get(i);
|
||||
} catch (ConstantPool.InvalidIndex e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
ConstantPool.CPInfo cpInfo2 = translate(cpInfo, translations);
|
||||
eq &= (cpInfo == cpInfo2);
|
||||
pool2[i] = cpInfo2;
|
||||
if (cpInfo.getTag() != cpInfo2.getTag())
|
||||
throw new IllegalStateException();
|
||||
i += cpInfo.size();
|
||||
}
|
||||
|
||||
if (eq)
|
||||
cp2 = cp;
|
||||
else
|
||||
cp2 = new ConstantPool(pool2);
|
||||
|
||||
translations.put(cp, cp2);
|
||||
}
|
||||
return cp2;
|
||||
}
|
||||
|
||||
ConstantPool.CPInfo translate(ConstantPool.CPInfo cpInfo, Map<Object,Object> translations) {
|
||||
ConstantPool.CPInfo cpInfo2 = (ConstantPool.CPInfo) translations.get(cpInfo);
|
||||
if (cpInfo2 == null) {
|
||||
cpInfo2 = cpInfo.accept(this, translations);
|
||||
translations.put(cpInfo, cpInfo2);
|
||||
}
|
||||
return cpInfo2;
|
||||
}
|
||||
|
||||
Field[] translate(Field[] fields, ConstantPool constant_pool, Map<Object,Object> translations) {
|
||||
Field[] fields2 = (Field[]) translations.get(fields);
|
||||
if (fields2 == null) {
|
||||
fields2 = new Field[fields.length];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
fields2[i] = translate(fields[i], constant_pool, translations);
|
||||
if (equal(fields, fields2))
|
||||
fields2 = fields;
|
||||
translations.put(fields, fields2);
|
||||
}
|
||||
return fields2;
|
||||
}
|
||||
|
||||
Field translate(Field field, ConstantPool constant_pool, Map<Object,Object> translations) {
|
||||
Field field2 = (Field) translations.get(field);
|
||||
if (field2 == null) {
|
||||
Attributes attributes2 = translateAttributes(field.attributes, constant_pool,
|
||||
translations);
|
||||
|
||||
if (attributes2 == field.attributes)
|
||||
field2 = field;
|
||||
else
|
||||
field2 = new Field(
|
||||
field.access_flags,
|
||||
field.name_index,
|
||||
field.descriptor,
|
||||
attributes2);
|
||||
translations.put(field, field2);
|
||||
}
|
||||
return field2;
|
||||
}
|
||||
|
||||
Method[] translateMethods(Method[] methods, ConstantPool constant_pool, Map<Object,Object> translations) {
|
||||
Method[] methods2 = (Method[]) translations.get(methods);
|
||||
if (methods2 == null) {
|
||||
methods2 = new Method[methods.length];
|
||||
for (int i = 0; i < methods.length; i++)
|
||||
methods2[i] = translate(methods[i], constant_pool, translations);
|
||||
if (equal(methods, methods2))
|
||||
methods2 = methods;
|
||||
translations.put(methods, methods2);
|
||||
}
|
||||
return methods2;
|
||||
}
|
||||
|
||||
Method translate(Method method, ConstantPool constant_pool, Map<Object,Object> translations) {
|
||||
Method method2 = (Method) translations.get(method);
|
||||
if (method2 == null) {
|
||||
Attributes attributes2 = translateAttributes(method.attributes, constant_pool,
|
||||
translations);
|
||||
|
||||
if (attributes2 == method.attributes)
|
||||
method2 = method;
|
||||
else
|
||||
method2 = new Method(
|
||||
method.access_flags,
|
||||
method.name_index,
|
||||
method.descriptor,
|
||||
attributes2);
|
||||
translations.put(method, method2);
|
||||
}
|
||||
return method2;
|
||||
}
|
||||
|
||||
Attributes translateAttributes(Attributes attributes,
|
||||
ConstantPool constant_pool, Map<Object,Object> translations) {
|
||||
Attributes attributes2 = (Attributes) translations.get(attributes);
|
||||
if (attributes2 == null) {
|
||||
Attribute[] attrArray2 = new Attribute[attributes.size()];
|
||||
ConstantPool constant_pool2 = translate(constant_pool, translations);
|
||||
boolean attrsEqual = true;
|
||||
for (int i = 0; i < attributes.size(); i++) {
|
||||
Attribute attr = attributes.get(i);
|
||||
Attribute attr2 = translate(attr, translations);
|
||||
if (attr2 != attr)
|
||||
attrsEqual = false;
|
||||
attrArray2[i] = attr2;
|
||||
}
|
||||
if ((constant_pool2 == constant_pool) && attrsEqual)
|
||||
attributes2 = attributes;
|
||||
else
|
||||
attributes2 = new Attributes(constant_pool2, attrArray2);
|
||||
translations.put(attributes, attributes2);
|
||||
}
|
||||
return attributes2;
|
||||
}
|
||||
|
||||
Attribute translate(Attribute attribute, Map<Object,Object> translations) {
|
||||
Attribute attribute2 = (Attribute) translations.get(attribute);
|
||||
if (attribute2 == null) {
|
||||
attribute2 = attribute; // don't support translation within attributes yet
|
||||
// (what about Code attribute)
|
||||
translations.put(attribute, attribute2);
|
||||
}
|
||||
return attribute2;
|
||||
}
|
||||
|
||||
private static <T> boolean equal(T[] a1, T[] a2) {
|
||||
if (a1 == null || a2 == null)
|
||||
return (a1 == a2);
|
||||
if (a1.length != a2.length)
|
||||
return false;
|
||||
for (int i = 0; i < a1.length; i++) {
|
||||
if (a1[i] != a2[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_Class_info(cp2, info.name_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
info2 = info;
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Fieldref_info info2 = (CONSTANT_Fieldref_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_Fieldref_info(cp2, info.class_index, info.name_and_type_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitFloat(CONSTANT_Float_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
info2 = info;
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitInteger(CONSTANT_Integer_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
info2 = info;
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_InterfaceMethodref_info(cp2, info.class_index, info.name_and_type_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_InvokeDynamic_info info2 = (CONSTANT_InvokeDynamic_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp) {
|
||||
info2 = info;
|
||||
} else {
|
||||
info2 = new CONSTANT_InvokeDynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index);
|
||||
}
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public CPInfo visitDynamicConstant(CONSTANT_Dynamic_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Dynamic_info info2 = (CONSTANT_Dynamic_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp) {
|
||||
info2 = info;
|
||||
} else {
|
||||
info2 = new CONSTANT_Dynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index);
|
||||
}
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
info2 = info;
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Methodref_info info2 = (CONSTANT_Methodref_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_Methodref_info(cp2, info.class_index, info.name_and_type_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_MethodHandle_info info2 = (CONSTANT_MethodHandle_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp) {
|
||||
info2 = info;
|
||||
} else {
|
||||
info2 = new CONSTANT_MethodHandle_info(cp2, info.reference_kind, info.reference_index);
|
||||
}
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp) {
|
||||
info2 = info;
|
||||
} else {
|
||||
info2 = new CONSTANT_MethodType_info(cp2, info.descriptor_index);
|
||||
}
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitModule(CONSTANT_Module_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Module_info info2 = (CONSTANT_Module_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_Module_info(cp2, info.name_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitPackage(CONSTANT_Package_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Package_info info2 = (CONSTANT_Package_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_Package_info(cp2, info.name_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
ConstantPool cp2 = translate(info.cp, translations);
|
||||
if (cp2 == info.cp)
|
||||
info2 = info;
|
||||
else
|
||||
info2 = new CONSTANT_String_info(cp2, info.string_index);
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map<Object, Object> translations) {
|
||||
CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info);
|
||||
if (info2 == null) {
|
||||
info2 = info;
|
||||
translations.put(info, info2);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.3.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Code_attribute extends Attribute {
|
||||
public static class InvalidIndex extends AttributeException {
|
||||
private static final long serialVersionUID = -8904527774589382802L;
|
||||
InvalidIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
// i18n
|
||||
return "invalid index " + index + " in Code attribute";
|
||||
}
|
||||
|
||||
public final int index;
|
||||
}
|
||||
|
||||
Code_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, ConstantPoolException {
|
||||
super(name_index, length);
|
||||
max_stack = cr.readUnsignedShort();
|
||||
max_locals = cr.readUnsignedShort();
|
||||
code_length = cr.readInt();
|
||||
code = new byte[code_length];
|
||||
cr.readFully(code);
|
||||
exception_table_length = cr.readUnsignedShort();
|
||||
exception_table = new Exception_data[exception_table_length];
|
||||
for (int i = 0; i < exception_table_length; i++)
|
||||
exception_table[i] = new Exception_data(cr);
|
||||
attributes = new Attributes(cr);
|
||||
}
|
||||
|
||||
public int getByte(int offset) throws InvalidIndex {
|
||||
if (offset < 0 || offset >= code.length)
|
||||
throw new InvalidIndex(offset);
|
||||
return code[offset];
|
||||
}
|
||||
|
||||
public int getUnsignedByte(int offset) throws InvalidIndex {
|
||||
if (offset < 0 || offset >= code.length)
|
||||
throw new InvalidIndex(offset);
|
||||
return code[offset] & 0xff;
|
||||
}
|
||||
|
||||
public int getShort(int offset) throws InvalidIndex {
|
||||
if (offset < 0 || offset + 1 >= code.length)
|
||||
throw new InvalidIndex(offset);
|
||||
return (code[offset] << 8) | (code[offset + 1] & 0xFF);
|
||||
}
|
||||
|
||||
public int getUnsignedShort(int offset) throws InvalidIndex {
|
||||
if (offset < 0 || offset + 1 >= code.length)
|
||||
throw new InvalidIndex(offset);
|
||||
return ((code[offset] << 8) | (code[offset + 1] & 0xFF)) & 0xFFFF;
|
||||
}
|
||||
|
||||
public int getInt(int offset) throws InvalidIndex {
|
||||
if (offset < 0 || offset + 3 >= code.length)
|
||||
throw new InvalidIndex(offset);
|
||||
return (getShort(offset) << 16) | (getShort(offset + 2) & 0xFFFF);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitCode(this, data);
|
||||
}
|
||||
|
||||
public Iterable<Instruction> getInstructions() {
|
||||
return () -> new Iterator<Instruction>() {
|
||||
|
||||
public boolean hasNext() {
|
||||
return (next != null);
|
||||
}
|
||||
|
||||
public Instruction next() {
|
||||
if (next == null)
|
||||
throw new NoSuchElementException();
|
||||
|
||||
current = next;
|
||||
pc += current.length();
|
||||
next = (pc < code.length ? new Instruction(code, pc) : null);
|
||||
return current;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
Instruction current = null;
|
||||
int pc = 0;
|
||||
Instruction next = (pc < code.length ? new Instruction(code, pc) : null);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public final int max_stack;
|
||||
public final int max_locals;
|
||||
public final int code_length;
|
||||
public final byte[] code;
|
||||
public final int exception_table_length;
|
||||
public final Exception_data[] exception_table;
|
||||
public final Attributes attributes;
|
||||
|
||||
public static class Exception_data {
|
||||
Exception_data(ClassReader cr) throws IOException {
|
||||
start_pc = cr.readUnsignedShort();
|
||||
end_pc = cr.readUnsignedShort();
|
||||
handler_pc = cr.readUnsignedShort();
|
||||
catch_type = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public final int start_pc;
|
||||
public final int end_pc;
|
||||
public final int handler_pc;
|
||||
public final int catch_type;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class CompilationID_attribute extends Attribute {
|
||||
|
||||
CompilationID_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
compilationID_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public CompilationID_attribute(ConstantPool constant_pool, int compilationID_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.CompilationID), compilationID_index);
|
||||
}
|
||||
|
||||
public CompilationID_attribute(int name_index, int compilationID_index) {
|
||||
super(name_index, 2);
|
||||
this.compilationID_index = compilationID_index;
|
||||
}
|
||||
|
||||
String getCompilationID(ConstantPool constant_pool)
|
||||
throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(compilationID_index);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitCompilationID(this, data);
|
||||
}
|
||||
|
||||
public final int compilationID_index;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ConstantPoolException extends Exception {
|
||||
private static final long serialVersionUID = -2324397349644754565L;
|
||||
ConstantPoolException(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public final int index;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.2.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ConstantValue_attribute extends Attribute {
|
||||
ConstantValue_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
constantvalue_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ConstantValue_attribute(ConstantPool constant_pool, int constantvalue_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.ConstantValue), constantvalue_index);
|
||||
}
|
||||
|
||||
public ConstantValue_attribute(int name_index, int constantvalue_index) {
|
||||
super(name_index, 2);
|
||||
this.constantvalue_index = constantvalue_index;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitConstantValue(this, data);
|
||||
}
|
||||
|
||||
public final int constantvalue_index;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class DefaultAttribute extends Attribute {
|
||||
DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
|
||||
this(cr, name_index, data, null);
|
||||
}
|
||||
|
||||
DefaultAttribute(ClassReader cr, int name_index, byte[] data, String reason) {
|
||||
super(name_index, data.length);
|
||||
info = data;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
|
||||
this(constant_pool, name_index, info, null);
|
||||
}
|
||||
|
||||
public DefaultAttribute(ConstantPool constant_pool, int name_index,
|
||||
byte[] info, String reason) {
|
||||
super(name_index, info.length);
|
||||
this.info = info;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitDefault(this, p);
|
||||
}
|
||||
|
||||
public final byte[] info;
|
||||
/** Why did we need to generate a DefaultAttribute
|
||||
*/
|
||||
public final String reason;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Deprecated_attribute extends Attribute {
|
||||
Deprecated_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
}
|
||||
|
||||
public Deprecated_attribute(ConstantPool constant_pool)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.Deprecated));
|
||||
}
|
||||
|
||||
public Deprecated_attribute(int name_index) {
|
||||
super(name_index, 0);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitDeprecated(this, data);
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.4.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Descriptor {
|
||||
public static class InvalidDescriptor extends DescriptorException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
InvalidDescriptor(String desc) {
|
||||
this.desc = desc;
|
||||
this.index = -1;
|
||||
}
|
||||
|
||||
InvalidDescriptor(String desc, int index) {
|
||||
this.desc = desc;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
// i18n
|
||||
if (index == -1)
|
||||
return "invalid descriptor \"" + desc + "\"";
|
||||
else
|
||||
return "descriptor is invalid at offset " + index + " in \"" + desc + "\"";
|
||||
}
|
||||
|
||||
public final String desc;
|
||||
public final int index;
|
||||
|
||||
}
|
||||
|
||||
public Descriptor(ClassReader cr) throws IOException {
|
||||
this(cr.readUnsignedShort());
|
||||
}
|
||||
|
||||
public Descriptor(int index) {
|
||||
this.index = index;
|
||||
|
||||
}
|
||||
|
||||
public String getValue(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(index);
|
||||
}
|
||||
|
||||
public int getParameterCount(ConstantPool constant_pool)
|
||||
throws ConstantPoolException, InvalidDescriptor {
|
||||
String desc = getValue(constant_pool);
|
||||
int end = desc.indexOf(")");
|
||||
if (end == -1)
|
||||
throw new InvalidDescriptor(desc);
|
||||
parse(desc, 0, end + 1);
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
public String getParameterTypes(ConstantPool constant_pool)
|
||||
throws ConstantPoolException, InvalidDescriptor {
|
||||
String desc = getValue(constant_pool);
|
||||
int end = desc.indexOf(")");
|
||||
if (end == -1)
|
||||
throw new InvalidDescriptor(desc);
|
||||
return parse(desc, 0, end + 1);
|
||||
}
|
||||
|
||||
public String getReturnType(ConstantPool constant_pool)
|
||||
throws ConstantPoolException, InvalidDescriptor {
|
||||
String desc = getValue(constant_pool);
|
||||
int end = desc.indexOf(")");
|
||||
if (end == -1)
|
||||
throw new InvalidDescriptor(desc);
|
||||
return parse(desc, end + 1, desc.length());
|
||||
}
|
||||
|
||||
public String getFieldType(ConstantPool constant_pool)
|
||||
throws ConstantPoolException, InvalidDescriptor {
|
||||
String desc = getValue(constant_pool);
|
||||
return parse(desc, 0, desc.length());
|
||||
}
|
||||
|
||||
private String parse(String desc, int start, int end)
|
||||
throws InvalidDescriptor {
|
||||
int p = start;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int dims = 0;
|
||||
count = 0;
|
||||
|
||||
while (p < end) {
|
||||
String type;
|
||||
char ch;
|
||||
switch (ch = desc.charAt(p++)) {
|
||||
case '(':
|
||||
sb.append('(');
|
||||
continue;
|
||||
|
||||
case ')':
|
||||
sb.append(')');
|
||||
continue;
|
||||
|
||||
case '[':
|
||||
dims++;
|
||||
continue;
|
||||
|
||||
case 'B':
|
||||
type = "byte";
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
type = "char";
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
type = "double";
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
type = "float";
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
type = "int";
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
type = "long";
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
int sep = desc.indexOf(';', p);
|
||||
if (sep == -1)
|
||||
throw new InvalidDescriptor(desc, p - 1);
|
||||
type = desc.substring(p, sep).replace('/', '.');
|
||||
p = sep + 1;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
type = "short";
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
type = "boolean";
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
type = "void";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidDescriptor(desc, p - 1);
|
||||
}
|
||||
|
||||
if (sb.length() > 1 && sb.charAt(0) == '(')
|
||||
sb.append(", ");
|
||||
sb.append(type);
|
||||
for ( ; dims > 0; dims-- )
|
||||
sb.append("[]");
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public final int index;
|
||||
private int count;
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class DescriptorException extends Exception {
|
||||
private static final long serialVersionUID = 2411890273788901032L;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.7.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class EnclosingMethod_attribute extends Attribute {
|
||||
EnclosingMethod_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
class_index = cr.readUnsignedShort();
|
||||
method_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public EnclosingMethod_attribute(ConstantPool constant_pool, int class_index, int method_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.EnclosingMethod), class_index, method_index);
|
||||
}
|
||||
|
||||
public EnclosingMethod_attribute(int name_index, int class_index, int method_index) {
|
||||
super(name_index, 4);
|
||||
this.class_index = class_index;
|
||||
this.method_index = method_index;
|
||||
}
|
||||
|
||||
public String getClassName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getClassInfo(class_index).getName();
|
||||
}
|
||||
|
||||
public String getMethodName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
if (method_index == 0)
|
||||
return "";
|
||||
return constant_pool.getNameAndTypeInfo(method_index).getName();
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitEnclosingMethod(this, data);
|
||||
}
|
||||
|
||||
public final int class_index;
|
||||
public final int method_index;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.5.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Exceptions_attribute extends Attribute {
|
||||
Exceptions_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
number_of_exceptions = cr.readUnsignedShort();
|
||||
exception_index_table = new int[number_of_exceptions];
|
||||
for (int i = 0; i < number_of_exceptions; i++)
|
||||
exception_index_table[i] = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Exceptions_attribute(ConstantPool constant_pool, int[] exception_index_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.Exceptions), exception_index_table);
|
||||
}
|
||||
|
||||
public Exceptions_attribute(int name_index, int[] exception_index_table) {
|
||||
super(name_index, 2 + 2 * exception_index_table.length);
|
||||
this.number_of_exceptions = exception_index_table.length;
|
||||
this.exception_index_table = exception_index_table;
|
||||
}
|
||||
|
||||
public String getException(int index, ConstantPool constant_pool) throws ConstantPoolException {
|
||||
int exception_index = exception_index_table[index];
|
||||
return constant_pool.getClassInfo(exception_index).getName();
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitExceptions(this, data);
|
||||
}
|
||||
|
||||
public final int number_of_exceptions;
|
||||
public final int[] exception_index_table;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class FatalError extends Error {
|
||||
private static final long serialVersionUID = 8114054446416187030L;
|
||||
|
||||
FatalError(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Field {
|
||||
Field(ClassReader cr) throws IOException {
|
||||
access_flags = new AccessFlags(cr);
|
||||
name_index = cr.readUnsignedShort();
|
||||
descriptor = new Descriptor(cr);
|
||||
attributes = new Attributes(cr);
|
||||
}
|
||||
|
||||
public Field(AccessFlags access_flags,
|
||||
int name_index, Descriptor descriptor,
|
||||
Attributes attributes) {
|
||||
this.access_flags = access_flags;
|
||||
this.name_index = name_index;
|
||||
this.descriptor = descriptor;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public int byteLength() {
|
||||
return 6 + attributes.byteLength();
|
||||
}
|
||||
|
||||
public String getName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(name_index);
|
||||
}
|
||||
|
||||
public final AccessFlags access_flags;
|
||||
public final int name_index;
|
||||
public final Descriptor descriptor;
|
||||
public final Attributes attributes;
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.*;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.6.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class InnerClasses_attribute extends Attribute {
|
||||
InnerClasses_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
number_of_classes = cr.readUnsignedShort();
|
||||
classes = new Info[number_of_classes];
|
||||
for (int i = 0; i < number_of_classes; i++)
|
||||
classes[i] = new Info(cr);
|
||||
}
|
||||
|
||||
public InnerClasses_attribute(ConstantPool constant_pool, Info[] classes)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.InnerClasses), classes);
|
||||
}
|
||||
|
||||
public InnerClasses_attribute(int name_index, Info[] classes) {
|
||||
super(name_index, 2 + Info.length() * classes.length);
|
||||
this.number_of_classes = classes.length;
|
||||
this.classes = classes;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitInnerClasses(this, data);
|
||||
}
|
||||
|
||||
public final int number_of_classes;
|
||||
public final Info[] classes;
|
||||
|
||||
public static class Info {
|
||||
Info(ClassReader cr) throws IOException {
|
||||
inner_class_info_index = cr.readUnsignedShort();
|
||||
outer_class_info_index = cr.readUnsignedShort();
|
||||
inner_name_index = cr.readUnsignedShort();
|
||||
inner_class_access_flags = new AccessFlags(cr.readUnsignedShort());
|
||||
}
|
||||
|
||||
public Info(int inner_class_info_index, int outer_class_info_index, int inner_name_index, AccessFlags inner_class_access_flags) {
|
||||
this.inner_class_info_index = inner_class_info_index;
|
||||
this.outer_class_info_index = outer_class_info_index;
|
||||
this.inner_name_index = inner_name_index;
|
||||
this.inner_class_access_flags = inner_class_access_flags;
|
||||
}
|
||||
|
||||
public CONSTANT_Class_info getInnerClassInfo(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
if (inner_class_info_index == 0)
|
||||
return null;
|
||||
return constant_pool.getClassInfo(inner_class_info_index);
|
||||
}
|
||||
|
||||
public CONSTANT_Class_info getOuterClassInfo(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
if (outer_class_info_index == 0)
|
||||
return null;
|
||||
return constant_pool.getClassInfo(outer_class_info_index);
|
||||
}
|
||||
|
||||
public String getInnerName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
if (inner_name_index == 0)
|
||||
return null;
|
||||
return constant_pool.getUTF8Value(inner_name_index);
|
||||
}
|
||||
|
||||
public static int length() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
public final int inner_class_info_index;
|
||||
public final int outer_class_info_index;
|
||||
public final int inner_name_index;
|
||||
public final AccessFlags inner_class_access_flags;
|
||||
}
|
||||
}
|
@ -1,357 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* See JVMS, chapter 6.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*
|
||||
* @see Code_attribute#getInstructions
|
||||
*/
|
||||
public class Instruction {
|
||||
/** The kind of an instruction, as determined by the position, size and
|
||||
* types of its operands. */
|
||||
public static enum Kind {
|
||||
/** Opcode is not followed by any operands. */
|
||||
NO_OPERANDS(1),
|
||||
/** Opcode is followed by a byte indicating a type. */
|
||||
ATYPE(2),
|
||||
/** Opcode is followed by a 2-byte branch offset. */
|
||||
BRANCH(3),
|
||||
/** Opcode is followed by a 4-byte branch offset. */
|
||||
BRANCH_W(5),
|
||||
/** Opcode is followed by a signed byte value. */
|
||||
BYTE(2),
|
||||
/** Opcode is followed by a 1-byte index into the constant pool. */
|
||||
CPREF(2),
|
||||
/** Opcode is followed by a 2-byte index into the constant pool. */
|
||||
CPREF_W(3),
|
||||
/** Opcode is followed by a 2-byte index into the constant pool,
|
||||
* an unsigned byte value. */
|
||||
CPREF_W_UBYTE(4),
|
||||
/** Opcode is followed by a 2-byte index into the constant pool.,
|
||||
* an unsigned byte value, and a zero byte. */
|
||||
CPREF_W_UBYTE_ZERO(5),
|
||||
/** Opcode is followed by variable number of operands, depending
|
||||
* on the instruction.*/
|
||||
DYNAMIC(-1),
|
||||
/** Opcode is followed by a 1-byte reference to a local variable. */
|
||||
LOCAL(2),
|
||||
/** Opcode is followed by a 1-byte reference to a local variable,
|
||||
* and a signed byte value. */
|
||||
LOCAL_BYTE(3),
|
||||
/** Opcode is followed by a signed short value. */
|
||||
SHORT(3),
|
||||
/** Wide opcode is not followed by any operands. */
|
||||
WIDE_NO_OPERANDS(2),
|
||||
/** Wide opcode is followed by a 2-byte index into the local variables array. */
|
||||
WIDE_LOCAL(4),
|
||||
/** Wide opcode is followed by a 2-byte index into the constant pool. */
|
||||
WIDE_CPREF_W(4),
|
||||
/** Wide opcode is followed by a 2-byte index into the constant pool,
|
||||
* and a signed short value. */
|
||||
WIDE_CPREF_W_SHORT(6),
|
||||
/** Wide opcode is followed by a 2-byte reference to a local variable,
|
||||
* and a signed short value. */
|
||||
WIDE_LOCAL_SHORT(6),
|
||||
/** Opcode was not recognized. */
|
||||
UNKNOWN(1);
|
||||
|
||||
Kind(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
/** The length, in bytes, of this kind of instruction, or -1 is the
|
||||
* length depends on the specific instruction. */
|
||||
public final int length;
|
||||
}
|
||||
|
||||
/** A utility visitor to help decode the operands of an instruction.
|
||||
* @see Instruction#accept */
|
||||
public interface KindVisitor<R,P> {
|
||||
/** See {@link Kind#NO_OPERANDS}, {@link Kind#WIDE_NO_OPERANDS}. */
|
||||
R visitNoOperands(Instruction instr, P p);
|
||||
/** See {@link Kind#ATYPE}. */
|
||||
R visitArrayType(Instruction instr, TypeKind kind, P p);
|
||||
/** See {@link Kind#BRANCH}, {@link Kind#BRANCH_W}. */
|
||||
R visitBranch(Instruction instr, int offset, P p);
|
||||
/** See {@link Kind#CPREF}, {@link Kind#CPREF_W}, {@link Kind#WIDE_CPREF_W}. */
|
||||
R visitConstantPoolRef(Instruction instr, int index, P p);
|
||||
/** See {@link Kind#CPREF_W_UBYTE}, {@link Kind#CPREF_W_UBYTE_ZERO}, {@link Kind#WIDE_CPREF_W_SHORT}. */
|
||||
R visitConstantPoolRefAndValue(Instruction instr, int index, int value, P p);
|
||||
/** See {@link Kind#LOCAL}, {@link Kind#WIDE_LOCAL}. */
|
||||
R visitLocal(Instruction instr, int index, P p);
|
||||
/** See {@link Kind#LOCAL_BYTE}. */
|
||||
R visitLocalAndValue(Instruction instr, int index, int value, P p);
|
||||
/** See {@link Kind#DYNAMIC}. */
|
||||
R visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, P p);
|
||||
/** See {@link Kind#DYNAMIC}. */
|
||||
R visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, P p);
|
||||
/** See {@link Kind#BYTE}, {@link Kind#SHORT}. */
|
||||
R visitValue(Instruction instr, int value, P p);
|
||||
/** Instruction is unrecognized. */
|
||||
R visitUnknown(Instruction instr, P p);
|
||||
|
||||
}
|
||||
|
||||
/** The kind of primitive array type to create.
|
||||
* See JVMS chapter 6, newarray. */
|
||||
public static enum TypeKind {
|
||||
T_BOOLEAN(4, "boolean"),
|
||||
T_CHAR(5, "char"),
|
||||
T_FLOAT(6, "float"),
|
||||
T_DOUBLE(7, "double"),
|
||||
T_BYTE(8, "byte"),
|
||||
T_SHORT(9, "short"),
|
||||
T_INT (10, "int"),
|
||||
T_LONG (11, "long");
|
||||
TypeKind(int value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static TypeKind get(int value) {
|
||||
switch (value) {
|
||||
case 4: return T_BOOLEAN;
|
||||
case 5: return T_CHAR;
|
||||
case 6: return T_FLOAT;
|
||||
case 7: return T_DOUBLE;
|
||||
case 8: return T_BYTE;
|
||||
case 9: return T_SHORT;
|
||||
case 10: return T_INT;
|
||||
case 11: return T_LONG;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final int value;
|
||||
public final String name;
|
||||
}
|
||||
|
||||
/** An instruction is defined by its position in a bytecode array. */
|
||||
public Instruction(byte[] bytes, int pc) {
|
||||
this.bytes = bytes;
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
/** Get the position of the instruction within the bytecode array. */
|
||||
public int getPC() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
/** Get a byte value, relative to the start of this instruction. */
|
||||
public int getByte(int offset) {
|
||||
return bytes[pc + offset];
|
||||
}
|
||||
|
||||
/** Get an unsigned byte value, relative to the start of this instruction. */
|
||||
public int getUnsignedByte(int offset) {
|
||||
return getByte(offset) & 0xff;
|
||||
}
|
||||
|
||||
/** Get a 2-byte value, relative to the start of this instruction. */
|
||||
public int getShort(int offset) {
|
||||
return (getByte(offset) << 8) | getUnsignedByte(offset + 1);
|
||||
}
|
||||
|
||||
/** Get a unsigned 2-byte value, relative to the start of this instruction. */
|
||||
public int getUnsignedShort(int offset) {
|
||||
return getShort(offset) & 0xFFFF;
|
||||
}
|
||||
|
||||
/** Get a 4-byte value, relative to the start of this instruction. */
|
||||
public int getInt(int offset) {
|
||||
return (getShort(offset) << 16) | (getUnsignedShort(offset + 2));
|
||||
}
|
||||
|
||||
/** Get the Opcode for this instruction, or null if the instruction is
|
||||
* unrecognized. */
|
||||
public Opcode getOpcode() {
|
||||
int b = getUnsignedByte(0);
|
||||
switch (b) {
|
||||
case Opcode.NONPRIV:
|
||||
case Opcode.PRIV:
|
||||
case Opcode.WIDE:
|
||||
return Opcode.get(b, getUnsignedByte(1));
|
||||
}
|
||||
return Opcode.get(b);
|
||||
}
|
||||
|
||||
/** Get the mnemonic for this instruction, or a default string if the
|
||||
* instruction is unrecognized. */
|
||||
public String getMnemonic() {
|
||||
Opcode opcode = getOpcode();
|
||||
if (opcode == null)
|
||||
return "bytecode " + getUnsignedByte(0);
|
||||
else
|
||||
return opcode.toString().toLowerCase(Locale.US);
|
||||
}
|
||||
|
||||
/** Get the length, in bytes, of this instruction, including the opcode
|
||||
* and all its operands. */
|
||||
public int length() {
|
||||
Opcode opcode = getOpcode();
|
||||
if (opcode == null)
|
||||
return 1;
|
||||
|
||||
switch (opcode) {
|
||||
case TABLESWITCH: {
|
||||
int pad = align(pc + 1) - pc;
|
||||
int low = getInt(pad + 4);
|
||||
int high = getInt(pad + 8);
|
||||
return pad + 12 + 4 * (high - low + 1);
|
||||
}
|
||||
case LOOKUPSWITCH: {
|
||||
int pad = align(pc + 1) - pc;
|
||||
int npairs = getInt(pad + 4);
|
||||
return pad + 8 + 8 * npairs;
|
||||
|
||||
}
|
||||
default:
|
||||
return opcode.kind.length;
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the {@link Kind} of this instruction. */
|
||||
public Kind getKind() {
|
||||
Opcode opcode = getOpcode();
|
||||
return (opcode != null ? opcode.kind : Kind.UNKNOWN);
|
||||
}
|
||||
|
||||
/** Invoke a method on the visitor according to the kind of this
|
||||
* instruction, passing in the decoded operands for the instruction. */
|
||||
public <R,P> R accept(KindVisitor<R,P> visitor, P p) {
|
||||
switch (getKind()) {
|
||||
case NO_OPERANDS:
|
||||
return visitor.visitNoOperands(this, p);
|
||||
|
||||
case ATYPE:
|
||||
return visitor.visitArrayType(
|
||||
this, TypeKind.get(getUnsignedByte(1)), p);
|
||||
|
||||
case BRANCH:
|
||||
return visitor.visitBranch(this, getShort(1), p);
|
||||
|
||||
case BRANCH_W:
|
||||
return visitor.visitBranch(this, getInt(1), p);
|
||||
|
||||
case BYTE:
|
||||
return visitor.visitValue(this, getByte(1), p);
|
||||
|
||||
case CPREF:
|
||||
return visitor.visitConstantPoolRef(this, getUnsignedByte(1), p);
|
||||
|
||||
case CPREF_W:
|
||||
return visitor.visitConstantPoolRef(this, getUnsignedShort(1), p);
|
||||
|
||||
case CPREF_W_UBYTE:
|
||||
case CPREF_W_UBYTE_ZERO:
|
||||
return visitor.visitConstantPoolRefAndValue(
|
||||
this, getUnsignedShort(1), getUnsignedByte(3), p);
|
||||
|
||||
case DYNAMIC: {
|
||||
switch (getOpcode()) {
|
||||
case TABLESWITCH: {
|
||||
int pad = align(pc + 1) - pc;
|
||||
int default_ = getInt(pad);
|
||||
int low = getInt(pad + 4);
|
||||
int high = getInt(pad + 8);
|
||||
if (low > high)
|
||||
throw new IllegalStateException();
|
||||
int[] values = new int[high - low + 1];
|
||||
for (int i = 0; i < values.length; i++)
|
||||
values[i] = getInt(pad + 12 + 4 * i);
|
||||
return visitor.visitTableSwitch(
|
||||
this, default_, low, high, values, p);
|
||||
}
|
||||
case LOOKUPSWITCH: {
|
||||
int pad = align(pc + 1) - pc;
|
||||
int default_ = getInt(pad);
|
||||
int npairs = getInt(pad + 4);
|
||||
if (npairs < 0)
|
||||
throw new IllegalStateException();
|
||||
int[] matches = new int[npairs];
|
||||
int[] offsets = new int[npairs];
|
||||
for (int i = 0; i < npairs; i++) {
|
||||
matches[i] = getInt(pad + 8 + i * 8);
|
||||
offsets[i] = getInt(pad + 12 + i * 8);
|
||||
}
|
||||
return visitor.visitLookupSwitch(
|
||||
this, default_, npairs, matches, offsets, p);
|
||||
}
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
case LOCAL:
|
||||
return visitor.visitLocal(this, getUnsignedByte(1), p);
|
||||
|
||||
case LOCAL_BYTE:
|
||||
return visitor.visitLocalAndValue(
|
||||
this, getUnsignedByte(1), getByte(2), p);
|
||||
|
||||
case SHORT:
|
||||
return visitor.visitValue(this, getShort(1), p);
|
||||
|
||||
case WIDE_NO_OPERANDS:
|
||||
return visitor.visitNoOperands(this, p);
|
||||
|
||||
case WIDE_LOCAL:
|
||||
return visitor.visitLocal(this, getUnsignedShort(2), p);
|
||||
|
||||
case WIDE_CPREF_W:
|
||||
return visitor.visitConstantPoolRef(this, getUnsignedShort(2), p);
|
||||
|
||||
case WIDE_CPREF_W_SHORT:
|
||||
return visitor.visitConstantPoolRefAndValue(
|
||||
this, getUnsignedShort(2), getUnsignedByte(4), p);
|
||||
|
||||
case WIDE_LOCAL_SHORT:
|
||||
return visitor.visitLocalAndValue(
|
||||
this, getUnsignedShort(2), getShort(4), p);
|
||||
|
||||
case UNKNOWN:
|
||||
return visitor.visitUnknown(this, p);
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
private static int align(int n) {
|
||||
return (n + 3) & ~3;
|
||||
}
|
||||
|
||||
private byte[] bytes;
|
||||
private int pc;
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.12.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class LineNumberTable_attribute extends Attribute {
|
||||
LineNumberTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
line_number_table_length = cr.readUnsignedShort();
|
||||
line_number_table = new Entry[line_number_table_length];
|
||||
for (int i = 0; i < line_number_table_length; i++)
|
||||
line_number_table[i] = new Entry(cr);
|
||||
}
|
||||
|
||||
public LineNumberTable_attribute(ConstantPool constant_pool, Entry[] line_number_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.LineNumberTable), line_number_table);
|
||||
}
|
||||
|
||||
public LineNumberTable_attribute(int name_index, Entry[] line_number_table) {
|
||||
super(name_index, 2 + line_number_table.length * Entry.length());
|
||||
this.line_number_table_length = line_number_table.length;
|
||||
this.line_number_table = line_number_table;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitLineNumberTable(this, data);
|
||||
}
|
||||
|
||||
public final int line_number_table_length;
|
||||
public final Entry[] line_number_table;
|
||||
|
||||
public static class Entry {
|
||||
Entry(ClassReader cr) throws IOException {
|
||||
start_pc = cr.readUnsignedShort();
|
||||
line_number = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public static int length() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
public final int start_pc;
|
||||
public final int line_number;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.13.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class LocalVariableTable_attribute extends Attribute {
|
||||
LocalVariableTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
local_variable_table_length = cr.readUnsignedShort();
|
||||
local_variable_table = new Entry[local_variable_table_length];
|
||||
for (int i = 0; i < local_variable_table_length; i++)
|
||||
local_variable_table[i] = new Entry(cr);
|
||||
}
|
||||
|
||||
public LocalVariableTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.LocalVariableTable), local_variable_table);
|
||||
}
|
||||
|
||||
public LocalVariableTable_attribute(int name_index, Entry[] local_variable_table) {
|
||||
super(name_index, 2 + local_variable_table.length * Entry.length());
|
||||
this.local_variable_table_length = local_variable_table.length;
|
||||
this.local_variable_table = local_variable_table;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitLocalVariableTable(this, data);
|
||||
}
|
||||
|
||||
public final int local_variable_table_length;
|
||||
public final Entry[] local_variable_table;
|
||||
|
||||
public static class Entry {
|
||||
Entry(ClassReader cr) throws IOException {
|
||||
start_pc = cr.readUnsignedShort();
|
||||
length = cr.readUnsignedShort();
|
||||
name_index = cr.readUnsignedShort();
|
||||
descriptor_index = cr.readUnsignedShort();
|
||||
index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public static int length() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
public final int start_pc;
|
||||
public final int length;
|
||||
public final int name_index;
|
||||
public final int descriptor_index;
|
||||
public final int index;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.14.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class LocalVariableTypeTable_attribute extends Attribute {
|
||||
LocalVariableTypeTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
local_variable_table_length = cr.readUnsignedShort();
|
||||
local_variable_table = new Entry[local_variable_table_length];
|
||||
for (int i = 0; i < local_variable_table_length; i++)
|
||||
local_variable_table[i] = new Entry(cr);
|
||||
}
|
||||
|
||||
public LocalVariableTypeTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.LocalVariableTypeTable), local_variable_table);
|
||||
}
|
||||
|
||||
public LocalVariableTypeTable_attribute(int name_index, Entry[] local_variable_table) {
|
||||
super(name_index, 2 + local_variable_table.length * Entry.length());
|
||||
this.local_variable_table_length = local_variable_table.length;
|
||||
this.local_variable_table = local_variable_table;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitLocalVariableTypeTable(this, data);
|
||||
}
|
||||
|
||||
public final int local_variable_table_length;
|
||||
public final Entry[] local_variable_table;
|
||||
|
||||
public static class Entry {
|
||||
Entry(ClassReader cr) throws IOException {
|
||||
start_pc = cr.readUnsignedShort();
|
||||
length = cr.readUnsignedShort();
|
||||
name_index = cr.readUnsignedShort();
|
||||
signature_index = cr.readUnsignedShort();
|
||||
index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public static int length() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
public final int start_pc;
|
||||
public final int length;
|
||||
public final int name_index;
|
||||
public final int signature_index;
|
||||
public final int index;
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Method {
|
||||
Method(ClassReader cr) throws IOException {
|
||||
access_flags = new AccessFlags(cr);
|
||||
name_index = cr.readUnsignedShort();
|
||||
descriptor = new Descriptor(cr);
|
||||
attributes = new Attributes(cr);
|
||||
}
|
||||
|
||||
public Method(AccessFlags access_flags,
|
||||
int name_index, Descriptor descriptor,
|
||||
Attributes attributes) {
|
||||
this.access_flags = access_flags;
|
||||
this.name_index = name_index;
|
||||
this.descriptor = descriptor;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public int byteLength() {
|
||||
return 6 + attributes.byteLength();
|
||||
}
|
||||
|
||||
public String getName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(name_index);
|
||||
}
|
||||
|
||||
public final AccessFlags access_flags;
|
||||
public final int name_index;
|
||||
public final Descriptor descriptor;
|
||||
public final Attributes attributes;
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.13.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class MethodParameters_attribute extends Attribute {
|
||||
|
||||
public final int method_parameter_table_length;
|
||||
public final Entry[] method_parameter_table;
|
||||
|
||||
MethodParameters_attribute(ClassReader cr,
|
||||
int name_index,
|
||||
int length)
|
||||
throws IOException {
|
||||
super(name_index, length);
|
||||
|
||||
method_parameter_table_length = cr.readUnsignedByte();
|
||||
method_parameter_table = new Entry[method_parameter_table_length];
|
||||
for (int i = 0; i < method_parameter_table_length; i++)
|
||||
method_parameter_table[i] = new Entry(cr);
|
||||
}
|
||||
|
||||
public MethodParameters_attribute(ConstantPool constant_pool,
|
||||
Entry[] method_parameter_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.MethodParameters),
|
||||
method_parameter_table);
|
||||
}
|
||||
|
||||
public MethodParameters_attribute(int name_index,
|
||||
Entry[] method_parameter_table) {
|
||||
super(name_index, 1 + method_parameter_table.length * Entry.length());
|
||||
this.method_parameter_table_length = method_parameter_table.length;
|
||||
this.method_parameter_table = method_parameter_table;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitMethodParameters(this, data);
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
Entry(ClassReader cr) throws IOException {
|
||||
name_index = cr.readUnsignedShort();
|
||||
flags = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Entry(int name_index, int flags) {
|
||||
this.name_index = name_index;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public static int length() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
public final int name_index;
|
||||
public final int flags;
|
||||
}
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ModuleHashes_attribute extends Attribute {
|
||||
ModuleHashes_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
algorithm_index = cr.readUnsignedShort();
|
||||
hashes_table_length = cr.readUnsignedShort();
|
||||
hashes_table = new Entry[hashes_table_length];
|
||||
for (int i = 0; i < hashes_table_length; i++)
|
||||
hashes_table[i] = new Entry(cr);
|
||||
}
|
||||
|
||||
public ModuleHashes_attribute(ConstantPool constant_pool, int algorithm_index, Entry[] hashes_table)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.ModuleHashes), algorithm_index, hashes_table);
|
||||
}
|
||||
|
||||
public ModuleHashes_attribute(int name_index, int algorithm_index, Entry[] hashes_table) {
|
||||
super(name_index, 2 + 2 + length(hashes_table));
|
||||
this.algorithm_index = algorithm_index;
|
||||
this.hashes_table_length = hashes_table.length;
|
||||
this.hashes_table = hashes_table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitModuleHashes(this, data);
|
||||
}
|
||||
|
||||
private static int length(Entry[] hashes_table) {
|
||||
int len = 0;
|
||||
for (Entry e: hashes_table) {
|
||||
len += e.length();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
public final int algorithm_index;
|
||||
public final int hashes_table_length;
|
||||
public final Entry[] hashes_table;
|
||||
|
||||
public static class Entry {
|
||||
Entry(ClassReader cr) throws IOException {
|
||||
module_name_index = cr.readUnsignedShort();
|
||||
int hash_length = cr.readUnsignedShort();
|
||||
hash = new byte[hash_length];
|
||||
for (int i=0; i<hash_length; i++) {
|
||||
hash[i] = (byte) cr.readUnsignedByte();
|
||||
}
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return 4 + hash.length;
|
||||
}
|
||||
|
||||
public final int module_name_index;
|
||||
public final byte[] hash;
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ModuleMainClass_attribute extends Attribute {
|
||||
ModuleMainClass_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
main_class_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ModuleMainClass_attribute(ConstantPool constant_pool, int mainClass_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.ModuleMainClass), mainClass_index);
|
||||
}
|
||||
|
||||
public ModuleMainClass_attribute(int name_index, int mainClass_index) {
|
||||
super(name_index, 2);
|
||||
this.main_class_index = mainClass_index;
|
||||
}
|
||||
|
||||
public String getMainClassName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getClassInfo(main_class_index).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitModuleMainClass(this, data);
|
||||
}
|
||||
|
||||
public final int main_class_index;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Package_info;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ModulePackages_attribute extends Attribute {
|
||||
ModulePackages_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException {
|
||||
super(name_index, length);
|
||||
packages_count = cr.readUnsignedShort();
|
||||
packages_index = new int[packages_count];
|
||||
for (int i = 0; i < packages_count; i++)
|
||||
packages_index[i] = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ModulePackages_attribute(ConstantPool constant_pool,
|
||||
int[] packages_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.ModulePackages),
|
||||
packages_index);
|
||||
}
|
||||
|
||||
public ModulePackages_attribute(int name_index,
|
||||
int[] packages_index) {
|
||||
super(name_index, 2 + packages_index.length * 2);
|
||||
this.packages_count = packages_index.length;
|
||||
this.packages_index = packages_index;
|
||||
}
|
||||
|
||||
public String getPackage(int index, ConstantPool constant_pool) throws ConstantPoolException {
|
||||
int package_index = packages_index[index];
|
||||
CONSTANT_Package_info info = constant_pool.getPackageInfo(package_index);
|
||||
return info.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitModulePackages(this, data);
|
||||
}
|
||||
|
||||
public final int packages_count;
|
||||
public final int[] packages_index;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ModuleResolution_attribute extends Attribute {
|
||||
public static final int DO_NOT_RESOLVE_BY_DEFAULT = 0x0001;
|
||||
public static final int WARN_DEPRECATED = 0x0002;
|
||||
public static final int WARN_DEPRECATED_FOR_REMOVAL = 0x0004;
|
||||
public static final int WARN_INCUBATING = 0x0008;
|
||||
|
||||
ModuleResolution_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException {
|
||||
super(name_index, length);
|
||||
resolution_flags = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ModuleResolution_attribute(ConstantPool constant_pool,
|
||||
int resolution_flags)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.ModuleResolution),
|
||||
resolution_flags);
|
||||
}
|
||||
|
||||
public ModuleResolution_attribute(int name_index,
|
||||
int resolution_flags) {
|
||||
super(name_index, 2);
|
||||
this.resolution_flags = resolution_flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitModuleResolution(this, data);
|
||||
}
|
||||
|
||||
public final int resolution_flags;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class ModuleTarget_attribute extends Attribute {
|
||||
ModuleTarget_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
target_platform_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ModuleTarget_attribute(int name_index, int target_platform_index) {
|
||||
super(name_index, 2);
|
||||
this.target_platform_index = target_platform_index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitModuleTarget(this, data);
|
||||
}
|
||||
|
||||
public final int target_platform_index;
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info;
|
||||
|
||||
/**
|
||||
* See Jigsaw.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Module_attribute extends Attribute {
|
||||
public static final int ACC_TRANSITIVE = 0x20;
|
||||
public static final int ACC_STATIC_PHASE = 0x40;
|
||||
public static final int ACC_OPEN = 0x20;
|
||||
public static final int ACC_SYNTHETIC = 0x1000;
|
||||
public static final int ACC_MANDATED = 0x8000;
|
||||
|
||||
Module_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
|
||||
module_name = cr.readUnsignedShort();
|
||||
module_flags = cr.readUnsignedShort();
|
||||
|
||||
module_version_index = cr.readUnsignedShort();
|
||||
|
||||
requires_count = cr.readUnsignedShort();
|
||||
requires = new RequiresEntry[requires_count];
|
||||
for (int i = 0; i < requires_count; i++)
|
||||
requires[i] = new RequiresEntry(cr);
|
||||
|
||||
exports_count = cr.readUnsignedShort();
|
||||
exports = new ExportsEntry[exports_count];
|
||||
for (int i = 0; i < exports_count; i++)
|
||||
exports[i] = new ExportsEntry(cr);
|
||||
|
||||
opens_count = cr.readUnsignedShort();
|
||||
opens = new OpensEntry[opens_count];
|
||||
for (int i = 0; i < opens_count; i++)
|
||||
opens[i] = new OpensEntry(cr);
|
||||
|
||||
uses_count = cr.readUnsignedShort();
|
||||
uses_index = new int[uses_count];
|
||||
for (int i = 0; i < uses_count; i++)
|
||||
uses_index[i] = cr.readUnsignedShort();
|
||||
|
||||
provides_count = cr.readUnsignedShort();
|
||||
provides = new ProvidesEntry[provides_count];
|
||||
for (int i = 0; i < provides_count; i++)
|
||||
provides[i] = new ProvidesEntry(cr);
|
||||
}
|
||||
|
||||
public Module_attribute(int name_index,
|
||||
int module_name,
|
||||
int module_flags,
|
||||
int module_version_index,
|
||||
RequiresEntry[] requires,
|
||||
ExportsEntry[] exports,
|
||||
OpensEntry[] opens,
|
||||
int[] uses,
|
||||
ProvidesEntry[] provides) {
|
||||
super(name_index, 2);
|
||||
this.module_name = module_name;
|
||||
this.module_flags = module_flags;
|
||||
this.module_version_index = module_version_index;
|
||||
requires_count = requires.length;
|
||||
this.requires = requires;
|
||||
exports_count = exports.length;
|
||||
this.exports = exports;
|
||||
opens_count = opens.length;
|
||||
this.opens = opens;
|
||||
uses_count = uses.length;
|
||||
this.uses_index = uses;
|
||||
provides_count = provides.length;
|
||||
this.provides = provides;
|
||||
}
|
||||
|
||||
public String getUses(int index, ConstantPool constant_pool) throws ConstantPoolException {
|
||||
int i = uses_index[index];
|
||||
return constant_pool.getClassInfo(i).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitModule(this, data);
|
||||
}
|
||||
|
||||
public final int module_name;
|
||||
public final int module_flags;
|
||||
public final int module_version_index;
|
||||
public final int requires_count;
|
||||
public final RequiresEntry[] requires;
|
||||
public final int exports_count;
|
||||
public final ExportsEntry[] exports;
|
||||
public final int opens_count;
|
||||
public final OpensEntry[] opens;
|
||||
public final int uses_count;
|
||||
public final int[] uses_index;
|
||||
public final int provides_count;
|
||||
public final ProvidesEntry[] provides;
|
||||
|
||||
public static class RequiresEntry {
|
||||
RequiresEntry(ClassReader cr) throws IOException {
|
||||
requires_index = cr.readUnsignedShort();
|
||||
requires_flags = cr.readUnsignedShort();
|
||||
requires_version_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public RequiresEntry(int index, int flags, int version_index) {
|
||||
this.requires_index = index;
|
||||
this.requires_flags = flags;
|
||||
this.requires_version_index = version_index;
|
||||
}
|
||||
|
||||
public String getRequires(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
CONSTANT_Module_info info = constant_pool.getModuleInfo(requires_index);
|
||||
return info.getName();
|
||||
}
|
||||
|
||||
public static final int length = 4;
|
||||
|
||||
public final int requires_index;
|
||||
public final int requires_flags;
|
||||
public final int requires_version_index;
|
||||
}
|
||||
|
||||
public static class ExportsEntry {
|
||||
ExportsEntry(ClassReader cr) throws IOException {
|
||||
exports_index = cr.readUnsignedShort();
|
||||
exports_flags = cr.readUnsignedShort();
|
||||
exports_to_count = cr.readUnsignedShort();
|
||||
exports_to_index = new int[exports_to_count];
|
||||
for (int i = 0; i < exports_to_count; i++)
|
||||
exports_to_index[i] = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ExportsEntry(int index, int flags, int[] to) {
|
||||
this.exports_index = index;
|
||||
this.exports_flags = flags;
|
||||
this.exports_to_count = to.length;
|
||||
this.exports_to_index = to;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return 4 + 2 * exports_to_index.length;
|
||||
}
|
||||
|
||||
public final int exports_index;
|
||||
public final int exports_flags;
|
||||
public final int exports_to_count;
|
||||
public final int[] exports_to_index;
|
||||
}
|
||||
|
||||
public static class OpensEntry {
|
||||
OpensEntry(ClassReader cr) throws IOException {
|
||||
opens_index = cr.readUnsignedShort();
|
||||
opens_flags = cr.readUnsignedShort();
|
||||
opens_to_count = cr.readUnsignedShort();
|
||||
opens_to_index = new int[opens_to_count];
|
||||
for (int i = 0; i < opens_to_count; i++)
|
||||
opens_to_index[i] = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public OpensEntry(int index, int flags, int[] to) {
|
||||
this.opens_index = index;
|
||||
this.opens_flags = flags;
|
||||
this.opens_to_count = to.length;
|
||||
this.opens_to_index = to;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return 4 + 2 * opens_to_index.length;
|
||||
}
|
||||
|
||||
public final int opens_index;
|
||||
public final int opens_flags;
|
||||
public final int opens_to_count;
|
||||
public final int[] opens_to_index;
|
||||
}
|
||||
|
||||
public static class ProvidesEntry {
|
||||
ProvidesEntry(ClassReader cr) throws IOException {
|
||||
provides_index = cr.readUnsignedShort();
|
||||
with_count = cr.readUnsignedShort();
|
||||
with_index = new int[with_count];
|
||||
for (int i = 0; i < with_count; i++)
|
||||
with_index[i] = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public ProvidesEntry(int provides, int[] with) {
|
||||
this.provides_index = provides;
|
||||
this.with_count = with.length;
|
||||
this.with_index = with;
|
||||
}
|
||||
|
||||
public static final int length = 4;
|
||||
|
||||
public final int provides_index;
|
||||
public final int with_count;
|
||||
public final int[] with_index;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class NestHost_attribute extends Attribute {
|
||||
NestHost_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
top_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public NestHost_attribute(ConstantPool constant_pool, int signature_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.Signature), signature_index);
|
||||
}
|
||||
|
||||
public NestHost_attribute(int name_index, int top_index) {
|
||||
super(name_index, 2);
|
||||
this.top_index = top_index;
|
||||
}
|
||||
|
||||
public CONSTANT_Class_info getNestTop(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getClassInfo(top_index);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitNestHost(this, data);
|
||||
}
|
||||
|
||||
public final int top_index;
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class NestMembers_attribute extends Attribute {
|
||||
NestMembers_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
int len = cr.readUnsignedShort();
|
||||
members_indexes = new int[len];
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
members_indexes[i] = cr.readUnsignedShort();
|
||||
}
|
||||
}
|
||||
|
||||
public NestMembers_attribute(int name_index, int[] members_indexes) {
|
||||
super(name_index, 2);
|
||||
this.members_indexes = members_indexes;
|
||||
}
|
||||
|
||||
public CONSTANT_Class_info[] getChildren(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return IntStream.of(members_indexes)
|
||||
.mapToObj(i -> {
|
||||
try {
|
||||
return constant_pool.getClassInfo(i);
|
||||
} catch (ConstantPoolException ex) {
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
}).toArray(CONSTANT_Class_info[]::new);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitNestMembers(this, data);
|
||||
}
|
||||
|
||||
public final int[] members_indexes;
|
||||
}
|
@ -1,472 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import static com.sun.tools.classfile.Instruction.Kind.*;
|
||||
import static com.sun.tools.classfile.Opcode.Set.*;
|
||||
|
||||
/**
|
||||
* See JVMS, chapter 6.
|
||||
*
|
||||
* <p>In addition to providing all the standard opcodes defined in JVMS,
|
||||
* this class also provides legacy support for the PicoJava extensions.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public enum Opcode {
|
||||
NOP(0x0),
|
||||
ACONST_NULL(0x1),
|
||||
ICONST_M1(0x2),
|
||||
ICONST_0(0x3),
|
||||
ICONST_1(0x4),
|
||||
ICONST_2(0x5),
|
||||
ICONST_3(0x6),
|
||||
ICONST_4(0x7),
|
||||
ICONST_5(0x8),
|
||||
LCONST_0(0x9),
|
||||
LCONST_1(0xa),
|
||||
FCONST_0(0xb),
|
||||
FCONST_1(0xc),
|
||||
FCONST_2(0xd),
|
||||
DCONST_0(0xe),
|
||||
DCONST_1(0xf),
|
||||
BIPUSH(0x10, BYTE),
|
||||
SIPUSH(0x11, SHORT),
|
||||
LDC(0x12, CPREF),
|
||||
LDC_W(0x13, CPREF_W),
|
||||
LDC2_W(0x14, CPREF_W),
|
||||
ILOAD(0x15, LOCAL),
|
||||
LLOAD(0x16, LOCAL),
|
||||
FLOAD(0x17, LOCAL),
|
||||
DLOAD(0x18, LOCAL),
|
||||
ALOAD(0x19, LOCAL),
|
||||
ILOAD_0(0x1a),
|
||||
ILOAD_1(0x1b),
|
||||
ILOAD_2(0x1c),
|
||||
ILOAD_3(0x1d),
|
||||
LLOAD_0(0x1e),
|
||||
LLOAD_1(0x1f),
|
||||
LLOAD_2(0x20),
|
||||
LLOAD_3(0x21),
|
||||
FLOAD_0(0x22),
|
||||
FLOAD_1(0x23),
|
||||
FLOAD_2(0x24),
|
||||
FLOAD_3(0x25),
|
||||
DLOAD_0(0x26),
|
||||
DLOAD_1(0x27),
|
||||
DLOAD_2(0x28),
|
||||
DLOAD_3(0x29),
|
||||
ALOAD_0(0x2a),
|
||||
ALOAD_1(0x2b),
|
||||
ALOAD_2(0x2c),
|
||||
ALOAD_3(0x2d),
|
||||
IALOAD(0x2e),
|
||||
LALOAD(0x2f),
|
||||
FALOAD(0x30),
|
||||
DALOAD(0x31),
|
||||
AALOAD(0x32),
|
||||
BALOAD(0x33),
|
||||
CALOAD(0x34),
|
||||
SALOAD(0x35),
|
||||
ISTORE(0x36, LOCAL),
|
||||
LSTORE(0x37, LOCAL),
|
||||
FSTORE(0x38, LOCAL),
|
||||
DSTORE(0x39, LOCAL),
|
||||
ASTORE(0x3a, LOCAL),
|
||||
ISTORE_0(0x3b),
|
||||
ISTORE_1(0x3c),
|
||||
ISTORE_2(0x3d),
|
||||
ISTORE_3(0x3e),
|
||||
LSTORE_0(0x3f),
|
||||
LSTORE_1(0x40),
|
||||
LSTORE_2(0x41),
|
||||
LSTORE_3(0x42),
|
||||
FSTORE_0(0x43),
|
||||
FSTORE_1(0x44),
|
||||
FSTORE_2(0x45),
|
||||
FSTORE_3(0x46),
|
||||
DSTORE_0(0x47),
|
||||
DSTORE_1(0x48),
|
||||
DSTORE_2(0x49),
|
||||
DSTORE_3(0x4a),
|
||||
ASTORE_0(0x4b),
|
||||
ASTORE_1(0x4c),
|
||||
ASTORE_2(0x4d),
|
||||
ASTORE_3(0x4e),
|
||||
IASTORE(0x4f),
|
||||
LASTORE(0x50),
|
||||
FASTORE(0x51),
|
||||
DASTORE(0x52),
|
||||
AASTORE(0x53),
|
||||
BASTORE(0x54),
|
||||
CASTORE(0x55),
|
||||
SASTORE(0x56),
|
||||
POP(0x57),
|
||||
POP2(0x58),
|
||||
DUP(0x59),
|
||||
DUP_X1(0x5a),
|
||||
DUP_X2(0x5b),
|
||||
DUP2(0x5c),
|
||||
DUP2_X1(0x5d),
|
||||
DUP2_X2(0x5e),
|
||||
SWAP(0x5f),
|
||||
IADD(0x60),
|
||||
LADD(0x61),
|
||||
FADD(0x62),
|
||||
DADD(0x63),
|
||||
ISUB(0x64),
|
||||
LSUB(0x65),
|
||||
FSUB(0x66),
|
||||
DSUB(0x67),
|
||||
IMUL(0x68),
|
||||
LMUL(0x69),
|
||||
FMUL(0x6a),
|
||||
DMUL(0x6b),
|
||||
IDIV(0x6c),
|
||||
LDIV(0x6d),
|
||||
FDIV(0x6e),
|
||||
DDIV(0x6f),
|
||||
IREM(0x70),
|
||||
LREM(0x71),
|
||||
FREM(0x72),
|
||||
DREM(0x73),
|
||||
INEG(0x74),
|
||||
LNEG(0x75),
|
||||
FNEG(0x76),
|
||||
DNEG(0x77),
|
||||
ISHL(0x78),
|
||||
LSHL(0x79),
|
||||
ISHR(0x7a),
|
||||
LSHR(0x7b),
|
||||
IUSHR(0x7c),
|
||||
LUSHR(0x7d),
|
||||
IAND(0x7e),
|
||||
LAND(0x7f),
|
||||
IOR(0x80),
|
||||
LOR(0x81),
|
||||
IXOR(0x82),
|
||||
LXOR(0x83),
|
||||
IINC(0x84, LOCAL_BYTE),
|
||||
I2L(0x85),
|
||||
I2F(0x86),
|
||||
I2D(0x87),
|
||||
L2I(0x88),
|
||||
L2F(0x89),
|
||||
L2D(0x8a),
|
||||
F2I(0x8b),
|
||||
F2L(0x8c),
|
||||
F2D(0x8d),
|
||||
D2I(0x8e),
|
||||
D2L(0x8f),
|
||||
D2F(0x90),
|
||||
I2B(0x91),
|
||||
I2C(0x92),
|
||||
I2S(0x93),
|
||||
LCMP(0x94),
|
||||
FCMPL(0x95),
|
||||
FCMPG(0x96),
|
||||
DCMPL(0x97),
|
||||
DCMPG(0x98),
|
||||
IFEQ(0x99, BRANCH),
|
||||
IFNE(0x9a, BRANCH),
|
||||
IFLT(0x9b, BRANCH),
|
||||
IFGE(0x9c, BRANCH),
|
||||
IFGT(0x9d, BRANCH),
|
||||
IFLE(0x9e, BRANCH),
|
||||
IF_ICMPEQ(0x9f, BRANCH),
|
||||
IF_ICMPNE(0xa0, BRANCH),
|
||||
IF_ICMPLT(0xa1, BRANCH),
|
||||
IF_ICMPGE(0xa2, BRANCH),
|
||||
IF_ICMPGT(0xa3, BRANCH),
|
||||
IF_ICMPLE(0xa4, BRANCH),
|
||||
IF_ACMPEQ(0xa5, BRANCH),
|
||||
IF_ACMPNE(0xa6, BRANCH),
|
||||
GOTO(0xa7, BRANCH),
|
||||
JSR(0xa8, BRANCH),
|
||||
RET(0xa9, LOCAL),
|
||||
TABLESWITCH(0xaa, DYNAMIC),
|
||||
LOOKUPSWITCH(0xab, DYNAMIC),
|
||||
IRETURN(0xac),
|
||||
LRETURN(0xad),
|
||||
FRETURN(0xae),
|
||||
DRETURN(0xaf),
|
||||
ARETURN(0xb0),
|
||||
RETURN(0xb1),
|
||||
GETSTATIC(0xb2, CPREF_W),
|
||||
PUTSTATIC(0xb3, CPREF_W),
|
||||
GETFIELD(0xb4, CPREF_W),
|
||||
PUTFIELD(0xb5, CPREF_W),
|
||||
INVOKEVIRTUAL(0xb6, CPREF_W),
|
||||
INVOKESPECIAL(0xb7, CPREF_W),
|
||||
INVOKESTATIC(0xb8, CPREF_W),
|
||||
INVOKEINTERFACE(0xb9, CPREF_W_UBYTE_ZERO),
|
||||
INVOKEDYNAMIC(0xba, CPREF_W_UBYTE_ZERO),
|
||||
NEW(0xbb, CPREF_W),
|
||||
NEWARRAY(0xbc, ATYPE),
|
||||
ANEWARRAY(0xbd, CPREF_W),
|
||||
ARRAYLENGTH(0xbe),
|
||||
ATHROW(0xbf),
|
||||
CHECKCAST(0xc0, CPREF_W),
|
||||
INSTANCEOF(0xc1, CPREF_W),
|
||||
MONITORENTER(0xc2),
|
||||
MONITOREXIT(0xc3),
|
||||
// wide 0xc4
|
||||
MULTIANEWARRAY(0xc5, CPREF_W_UBYTE),
|
||||
IFNULL(0xc6, BRANCH),
|
||||
IFNONNULL(0xc7, BRANCH),
|
||||
GOTO_W(0xc8, BRANCH_W),
|
||||
JSR_W(0xc9, BRANCH_W),
|
||||
// impdep 0xfe: PicoJava nonpriv
|
||||
// impdep 0xff: Picojava priv
|
||||
|
||||
// wide opcodes
|
||||
ILOAD_W(0xc415, WIDE_LOCAL),
|
||||
LLOAD_W(0xc416, WIDE_LOCAL),
|
||||
FLOAD_W(0xc417, WIDE_LOCAL),
|
||||
DLOAD_W(0xc418, WIDE_LOCAL),
|
||||
ALOAD_W(0xc419, WIDE_LOCAL),
|
||||
ISTORE_W(0xc436, WIDE_LOCAL),
|
||||
LSTORE_W(0xc437, WIDE_LOCAL),
|
||||
FSTORE_W(0xc438, WIDE_LOCAL),
|
||||
DSTORE_W(0xc439, WIDE_LOCAL),
|
||||
ASTORE_W(0xc43a, WIDE_LOCAL),
|
||||
IINC_W(0xc484, WIDE_LOCAL_SHORT),
|
||||
RET_W(0xc4a9, WIDE_LOCAL),
|
||||
|
||||
// PicoJava nonpriv instructions
|
||||
LOAD_UBYTE(PICOJAVA, 0xfe00),
|
||||
LOAD_BYTE(PICOJAVA, 0xfe01),
|
||||
LOAD_CHAR(PICOJAVA, 0xfe02),
|
||||
LOAD_SHORT(PICOJAVA, 0xfe03),
|
||||
LOAD_WORD(PICOJAVA, 0xfe04),
|
||||
RET_FROM_SUB(PICOJAVA, 0xfe05),
|
||||
LOAD_CHAR_OE(PICOJAVA, 0xfe0a),
|
||||
LOAD_SHORT_OE(PICOJAVA, 0xfe0b),
|
||||
LOAD_WORD_OE(PICOJAVA, 0xfe0c),
|
||||
NCLOAD_UBYTE(PICOJAVA, 0xfe10),
|
||||
NCLOAD_BYTE(PICOJAVA, 0xfe11),
|
||||
NCLOAD_CHAR(PICOJAVA, 0xfe12),
|
||||
NCLOAD_SHORT(PICOJAVA, 0xfe13),
|
||||
NCLOAD_WORD(PICOJAVA, 0xfe14),
|
||||
NCLOAD_CHAR_OE(PICOJAVA, 0xfe1a),
|
||||
NCLOAD_SHORT_OE(PICOJAVA, 0xfe1b),
|
||||
NCLOAD_WORD_OE(PICOJAVA, 0xfe1c),
|
||||
CACHE_FLUSH(PICOJAVA, 0xfe1e),
|
||||
STORE_BYTE(PICOJAVA, 0xfe20),
|
||||
STORE_SHORT(PICOJAVA, 0xfe22),
|
||||
STORE_WORD(PICOJAVA, 0xfe24),
|
||||
STORE_SHORT_OE(PICOJAVA, 0xfe2a),
|
||||
STORE_WORD_OE(PICOJAVA, 0xfe2c),
|
||||
NCSTORE_BYTE(PICOJAVA, 0xfe30),
|
||||
NCSTORE_SHORT(PICOJAVA, 0xfe32),
|
||||
NCSTORE_WORD(PICOJAVA, 0xfe34),
|
||||
NCSTORE_SHORT_OE(PICOJAVA, 0xfe3a),
|
||||
NCSTORE_WORD_OE(PICOJAVA, 0xfe3c),
|
||||
ZERO_LINE(PICOJAVA, 0xfe3e),
|
||||
ENTER_SYNC_METHOD(PICOJAVA, 0xfe3f),
|
||||
|
||||
// PicoJava priv instructions
|
||||
PRIV_LOAD_UBYTE(PICOJAVA, 0xff00),
|
||||
PRIV_LOAD_BYTE(PICOJAVA, 0xff01),
|
||||
PRIV_LOAD_CHAR(PICOJAVA, 0xff02),
|
||||
PRIV_LOAD_SHORT(PICOJAVA, 0xff03),
|
||||
PRIV_LOAD_WORD(PICOJAVA, 0xff04),
|
||||
PRIV_RET_FROM_TRAP(PICOJAVA, 0xff05),
|
||||
PRIV_READ_DCACHE_TAG(PICOJAVA, 0xff06),
|
||||
PRIV_READ_DCACHE_DATA(PICOJAVA, 0xff07),
|
||||
PRIV_LOAD_CHAR_OE(PICOJAVA, 0xff0a),
|
||||
PRIV_LOAD_SHORT_OE(PICOJAVA, 0xff0b),
|
||||
PRIV_LOAD_WORD_OE(PICOJAVA, 0xff0c),
|
||||
PRIV_READ_ICACHE_TAG(PICOJAVA, 0xff0e),
|
||||
PRIV_READ_ICACHE_DATA(PICOJAVA, 0xff0f),
|
||||
PRIV_NCLOAD_UBYTE(PICOJAVA, 0xff10),
|
||||
PRIV_NCLOAD_BYTE(PICOJAVA, 0xff11),
|
||||
PRIV_NCLOAD_CHAR(PICOJAVA, 0xff12),
|
||||
PRIV_NCLOAD_SHORT(PICOJAVA, 0xff13),
|
||||
PRIV_NCLOAD_WORD(PICOJAVA, 0xff14),
|
||||
PRIV_POWERDOWN(PICOJAVA, 0xff16),
|
||||
PRIV_READ_SCACHE_DATA(PICOJAVA, 0xff17),
|
||||
PRIV_NCLOAD_CHAR_OE(PICOJAVA, 0xff1a),
|
||||
PRIV_NCLOAD_SHORT_OE(PICOJAVA, 0xff1b),
|
||||
PRIV_NCLOAD_WORD_OE(PICOJAVA, 0xff1c),
|
||||
PRIV_CACHE_FLUSH(PICOJAVA, 0xff1e),
|
||||
PRIV_CACHE_INDEX_FLUSH(PICOJAVA, 0xff1f),
|
||||
PRIV_STORE_BYTE(PICOJAVA, 0xff20),
|
||||
PRIV_STORE_SHORT(PICOJAVA, 0xff22),
|
||||
PRIV_STORE_WORD(PICOJAVA, 0xff24),
|
||||
PRIV_WRITE_DCACHE_TAG(PICOJAVA, 0xff26),
|
||||
PRIV_WRITE_DCACHE_DATA(PICOJAVA, 0xff27),
|
||||
PRIV_STORE_SHORT_OE(PICOJAVA, 0xff2a),
|
||||
PRIV_STORE_WORD_OE(PICOJAVA, 0xff2c),
|
||||
PRIV_WRITE_ICACHE_TAG(PICOJAVA, 0xff2e),
|
||||
PRIV_WRITE_ICACHE_DATA(PICOJAVA, 0xff2f),
|
||||
PRIV_NCSTORE_BYTE(PICOJAVA, 0xff30),
|
||||
PRIV_NCSTORE_SHORT(PICOJAVA, 0xff32),
|
||||
PRIV_NCSTORE_WORD(PICOJAVA, 0xff34),
|
||||
PRIV_RESET(PICOJAVA, 0xff36),
|
||||
PRIV_WRITE_SCACHE_DATA(PICOJAVA, 0xff37),
|
||||
PRIV_NCSTORE_SHORT_OE(PICOJAVA, 0xff3a),
|
||||
PRIV_NCSTORE_WORD_OE(PICOJAVA, 0xff3c),
|
||||
PRIV_ZERO_LINE(PICOJAVA, 0xff3e),
|
||||
PRIV_READ_REG_0(PICOJAVA, 0xff40),
|
||||
PRIV_READ_REG_1(PICOJAVA, 0xff41),
|
||||
PRIV_READ_REG_2(PICOJAVA, 0xff42),
|
||||
PRIV_READ_REG_3(PICOJAVA, 0xff43),
|
||||
PRIV_READ_REG_4(PICOJAVA, 0xff44),
|
||||
PRIV_READ_REG_5(PICOJAVA, 0xff45),
|
||||
PRIV_READ_REG_6(PICOJAVA, 0xff46),
|
||||
PRIV_READ_REG_7(PICOJAVA, 0xff47),
|
||||
PRIV_READ_REG_8(PICOJAVA, 0xff48),
|
||||
PRIV_READ_REG_9(PICOJAVA, 0xff49),
|
||||
PRIV_READ_REG_10(PICOJAVA, 0xff4a),
|
||||
PRIV_READ_REG_11(PICOJAVA, 0xff4b),
|
||||
PRIV_READ_REG_12(PICOJAVA, 0xff4c),
|
||||
PRIV_READ_REG_13(PICOJAVA, 0xff4d),
|
||||
PRIV_READ_REG_14(PICOJAVA, 0xff4e),
|
||||
PRIV_READ_REG_15(PICOJAVA, 0xff4f),
|
||||
PRIV_READ_REG_16(PICOJAVA, 0xff50),
|
||||
PRIV_READ_REG_17(PICOJAVA, 0xff51),
|
||||
PRIV_READ_REG_18(PICOJAVA, 0xff52),
|
||||
PRIV_READ_REG_19(PICOJAVA, 0xff53),
|
||||
PRIV_READ_REG_20(PICOJAVA, 0xff54),
|
||||
PRIV_READ_REG_21(PICOJAVA, 0xff55),
|
||||
PRIV_READ_REG_22(PICOJAVA, 0xff56),
|
||||
PRIV_READ_REG_23(PICOJAVA, 0xff57),
|
||||
PRIV_READ_REG_24(PICOJAVA, 0xff58),
|
||||
PRIV_READ_REG_25(PICOJAVA, 0xff59),
|
||||
PRIV_READ_REG_26(PICOJAVA, 0xff5a),
|
||||
PRIV_READ_REG_27(PICOJAVA, 0xff5b),
|
||||
PRIV_READ_REG_28(PICOJAVA, 0xff5c),
|
||||
PRIV_READ_REG_29(PICOJAVA, 0xff5d),
|
||||
PRIV_READ_REG_30(PICOJAVA, 0xff5e),
|
||||
PRIV_READ_REG_31(PICOJAVA, 0xff5f),
|
||||
PRIV_WRITE_REG_0(PICOJAVA, 0xff60),
|
||||
PRIV_WRITE_REG_1(PICOJAVA, 0xff61),
|
||||
PRIV_WRITE_REG_2(PICOJAVA, 0xff62),
|
||||
PRIV_WRITE_REG_3(PICOJAVA, 0xff63),
|
||||
PRIV_WRITE_REG_4(PICOJAVA, 0xff64),
|
||||
PRIV_WRITE_REG_5(PICOJAVA, 0xff65),
|
||||
PRIV_WRITE_REG_6(PICOJAVA, 0xff66),
|
||||
PRIV_WRITE_REG_7(PICOJAVA, 0xff67),
|
||||
PRIV_WRITE_REG_8(PICOJAVA, 0xff68),
|
||||
PRIV_WRITE_REG_9(PICOJAVA, 0xff69),
|
||||
PRIV_WRITE_REG_10(PICOJAVA, 0xff6a),
|
||||
PRIV_WRITE_REG_11(PICOJAVA, 0xff6b),
|
||||
PRIV_WRITE_REG_12(PICOJAVA, 0xff6c),
|
||||
PRIV_WRITE_REG_13(PICOJAVA, 0xff6d),
|
||||
PRIV_WRITE_REG_14(PICOJAVA, 0xff6e),
|
||||
PRIV_WRITE_REG_15(PICOJAVA, 0xff6f),
|
||||
PRIV_WRITE_REG_16(PICOJAVA, 0xff70),
|
||||
PRIV_WRITE_REG_17(PICOJAVA, 0xff71),
|
||||
PRIV_WRITE_REG_18(PICOJAVA, 0xff72),
|
||||
PRIV_WRITE_REG_19(PICOJAVA, 0xff73),
|
||||
PRIV_WRITE_REG_20(PICOJAVA, 0xff74),
|
||||
PRIV_WRITE_REG_21(PICOJAVA, 0xff75),
|
||||
PRIV_WRITE_REG_22(PICOJAVA, 0xff76),
|
||||
PRIV_WRITE_REG_23(PICOJAVA, 0xff77),
|
||||
PRIV_WRITE_REG_24(PICOJAVA, 0xff78),
|
||||
PRIV_WRITE_REG_25(PICOJAVA, 0xff79),
|
||||
PRIV_WRITE_REG_26(PICOJAVA, 0xff7a),
|
||||
PRIV_WRITE_REG_27(PICOJAVA, 0xff7b),
|
||||
PRIV_WRITE_REG_28(PICOJAVA, 0xff7c),
|
||||
PRIV_WRITE_REG_29(PICOJAVA, 0xff7d),
|
||||
PRIV_WRITE_REG_30(PICOJAVA, 0xff7e),
|
||||
PRIV_WRITE_REG_31(PICOJAVA, 0xff7f);
|
||||
|
||||
Opcode(int opcode) {
|
||||
this(STANDARD, opcode, NO_OPERANDS);
|
||||
}
|
||||
|
||||
Opcode(int opcode, Instruction.Kind kind) {
|
||||
this(STANDARD, opcode, kind);
|
||||
}
|
||||
|
||||
Opcode(Set set, int opcode) {
|
||||
this(set, opcode, (set == STANDARD ? NO_OPERANDS : WIDE_NO_OPERANDS));
|
||||
}
|
||||
|
||||
Opcode(Set set, int opcode, Instruction.Kind kind) {
|
||||
this.set = set;
|
||||
this.opcode = opcode;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public final Set set;
|
||||
public final int opcode;
|
||||
public final Instruction.Kind kind;
|
||||
|
||||
/** Get the Opcode for a simple standard 1-byte opcode. */
|
||||
public static Opcode get(int opcode) {
|
||||
return stdOpcodes[opcode];
|
||||
}
|
||||
|
||||
/** Get the Opcode for 1- or 2-byte opcode. */
|
||||
public static Opcode get(int opcodePrefix, int opcode) {
|
||||
Opcode[] block = getOpcodeBlock(opcodePrefix);
|
||||
return (block == null ? null : block[opcode]);
|
||||
}
|
||||
|
||||
private static Opcode[] getOpcodeBlock(int opcodePrefix) {
|
||||
switch (opcodePrefix) {
|
||||
case 0:
|
||||
return stdOpcodes;
|
||||
case WIDE:
|
||||
return wideOpcodes;
|
||||
case NONPRIV:
|
||||
return nonPrivOpcodes;
|
||||
case PRIV:
|
||||
return privOpcodes;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final Opcode[] stdOpcodes = new Opcode[256];
|
||||
private static final Opcode[] wideOpcodes = new Opcode[256];
|
||||
private static final Opcode[] nonPrivOpcodes = new Opcode[256];
|
||||
private static final Opcode[] privOpcodes = new Opcode[256];
|
||||
static {
|
||||
for (Opcode o: values())
|
||||
getOpcodeBlock(o.opcode >> 8)[o.opcode & 0xff] = o;
|
||||
}
|
||||
|
||||
/** The byte prefix for the wide instructions. */
|
||||
public static final int WIDE = 0xc4;
|
||||
/** The byte prefix for the PicoJava nonpriv instructions. */
|
||||
public static final int NONPRIV = 0xfe;
|
||||
/** The byte prefix for the PicoJava priv instructions. */
|
||||
public static final int PRIV = 0xff;
|
||||
|
||||
public enum Set {
|
||||
/** Standard opcodes. */
|
||||
STANDARD,
|
||||
/** Legacy support for PicoJava opcodes. */
|
||||
PICOJAVA }
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
|
||||
|
||||
public class PermittedSubclasses_attribute extends Attribute {
|
||||
|
||||
public int[] subtypes;
|
||||
|
||||
PermittedSubclasses_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
int number_of_classes = cr.readUnsignedShort();
|
||||
subtypes = new int[number_of_classes];
|
||||
for (int i = 0; i < number_of_classes; i++)
|
||||
subtypes[i] = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public PermittedSubclasses_attribute(int name_index, int[] subtypes) {
|
||||
super(name_index, 2);
|
||||
this.subtypes = subtypes;
|
||||
}
|
||||
|
||||
public CONSTANT_Class_info[] getSubtypes(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return IntStream.of(subtypes)
|
||||
.mapToObj(i -> {
|
||||
try {
|
||||
return constant_pool.getClassInfo(i);
|
||||
} catch (ConstantPoolException ex) {
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
}).toArray(CONSTANT_Class_info[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitPermittedSubclasses(this, data);
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.sun.tools.classfile.Attribute.Visitor;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Record_attribute extends Attribute {
|
||||
Record_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
component_count = cr.readUnsignedShort();
|
||||
component_info_arr = new ComponentInfo[component_count];
|
||||
for (int i = 0; i < component_count; i++) {
|
||||
component_info_arr[i] = new ComponentInfo(cr);
|
||||
}
|
||||
}
|
||||
|
||||
public Record_attribute(int name_index, ComponentInfo[] component_info_arr) {
|
||||
super(name_index, 2);
|
||||
this.component_count = component_info_arr.length;
|
||||
this.component_info_arr = component_info_arr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitRecord(this, data);
|
||||
}
|
||||
|
||||
public final int component_count;
|
||||
public final ComponentInfo[] component_info_arr;
|
||||
|
||||
public static class ComponentInfo {
|
||||
ComponentInfo(ClassReader cr) throws IOException {
|
||||
name_index = cr.readUnsignedShort();
|
||||
descriptor = new Descriptor(cr);
|
||||
attributes = new Attributes(cr);
|
||||
}
|
||||
|
||||
public ComponentInfo(int name_index, Descriptor descriptor, Attributes attributes) {
|
||||
this.name_index = name_index;
|
||||
this.descriptor = descriptor;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public String getName(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(name_index);
|
||||
}
|
||||
|
||||
public final int name_index;
|
||||
public final Descriptor descriptor;
|
||||
public final Attributes attributes;
|
||||
}
|
||||
}
|
@ -1,253 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import com.sun.tools.classfile.Instruction.TypeKind;
|
||||
import static com.sun.tools.classfile.ConstantPool.*;
|
||||
|
||||
/**
|
||||
* A utility class to find where in a ClassFile references
|
||||
* a {@link CONSTANT_Methodref_info method},
|
||||
* a {@link CONSTANT_InterfaceMethodref_info interface method},
|
||||
* or a {@link CONSTANT_Fieldref_info field}.
|
||||
*/
|
||||
public final class ReferenceFinder {
|
||||
/**
|
||||
* Filter for ReferenceFinder of what constant pool entries for reference lookup.
|
||||
*/
|
||||
public interface Filter {
|
||||
/**
|
||||
* Decides if the given CPRefInfo entry should be accepted or filtered.
|
||||
*
|
||||
* @param cpool ConstantPool of the ClassFile being parsed
|
||||
* @param cpref constant pool entry representing a reference to
|
||||
* a fields method, and interface method.
|
||||
* @return {@code true} if accepted; otherwise {@code false}
|
||||
*/
|
||||
boolean accept(ConstantPool cpool, CPRefInfo cpref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitor of individual method of a ClassFile that references the
|
||||
* accepted field, method, or interface method references.
|
||||
*/
|
||||
public interface Visitor {
|
||||
/**
|
||||
* Invoked for a method containing one or more accepted CPRefInfo entries
|
||||
*
|
||||
* @param cf ClassFile
|
||||
* @param method Method that does the references the accepted references
|
||||
* @param refs Accepted constant pool method/field reference
|
||||
*/
|
||||
void visit(ClassFile cf, Method method, List<CPRefInfo> refConstantPool);
|
||||
}
|
||||
|
||||
private final Filter filter;
|
||||
private final Visitor visitor;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ReferenceFinder(Filter filter, Visitor visitor) {
|
||||
this.filter = Objects.requireNonNull(filter);
|
||||
this.visitor = Objects.requireNonNull(visitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a given ClassFile and invoke the visitor if there is any reference
|
||||
* to the constant pool entries referencing field, method, or
|
||||
* interface method that are accepted. This method will return
|
||||
* {@code true} if there is one or more accepted constant pool entries
|
||||
* to lookup; otherwise, it will return {@code false}.
|
||||
*
|
||||
* @param cf ClassFile
|
||||
* @return {@code true} if the given class file is processed to lookup
|
||||
* references
|
||||
* @throws ConstantPoolException if an error of the constant pool
|
||||
*/
|
||||
public boolean parse(ClassFile cf) throws ConstantPoolException {
|
||||
List<Integer> cprefs = new ArrayList<>();
|
||||
int index = 1;
|
||||
for (ConstantPool.CPInfo cpInfo : cf.constant_pool.entries()) {
|
||||
if (cpInfo.accept(cpVisitor, cf.constant_pool)) {
|
||||
cprefs.add(index);
|
||||
}
|
||||
index += cpInfo.size();
|
||||
}
|
||||
|
||||
if (cprefs.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Method m : cf.methods) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
Code_attribute c_attr = (Code_attribute) m.attributes.get(Attribute.Code);
|
||||
if (c_attr != null) {
|
||||
for (Instruction instr : c_attr.getInstructions()) {
|
||||
int idx = instr.accept(codeVisitor, cprefs);
|
||||
if (idx > 0) {
|
||||
ids.add(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ids.size() > 0) {
|
||||
List<CPRefInfo> refInfos = new ArrayList<>(ids.size());
|
||||
for (int id : ids) {
|
||||
refInfos.add(CPRefInfo.class.cast(cf.constant_pool.get(id)));
|
||||
}
|
||||
visitor.visit(cf, m, refInfos);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private ConstantPool.Visitor<Boolean,ConstantPool> cpVisitor =
|
||||
new ConstantPool.Visitor<Boolean,ConstantPool>()
|
||||
{
|
||||
public Boolean visitClass(CONSTANT_Class_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitFieldref(CONSTANT_Fieldref_info info, ConstantPool cpool) {
|
||||
return filter.accept(cpool, info);
|
||||
}
|
||||
|
||||
public Boolean visitDouble(CONSTANT_Double_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitFloat(CONSTANT_Float_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitInteger(CONSTANT_Integer_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ConstantPool cpool) {
|
||||
return filter.accept(cpool, info);
|
||||
}
|
||||
|
||||
public Boolean visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitDynamicConstant(CONSTANT_Dynamic_info info, ConstantPool constantPool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitLong(CONSTANT_Long_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitMethodHandle(CONSTANT_MethodHandle_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitMethodref(CONSTANT_Methodref_info info, ConstantPool cpool) {
|
||||
return filter.accept(cpool, info);
|
||||
}
|
||||
|
||||
public Boolean visitMethodType(CONSTANT_MethodType_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitModule(CONSTANT_Module_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitNameAndType(CONSTANT_NameAndType_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitPackage(CONSTANT_Package_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitString(CONSTANT_String_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean visitUtf8(CONSTANT_Utf8_info info, ConstantPool cpool) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private Instruction.KindVisitor<Integer, List<Integer>> codeVisitor =
|
||||
new Instruction.KindVisitor<Integer, List<Integer>>()
|
||||
{
|
||||
public Integer visitNoOperands(Instruction instr, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitArrayType(Instruction instr, TypeKind kind, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitBranch(Instruction instr, int offset, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitConstantPoolRef(Instruction instr, int index, List<Integer> p) {
|
||||
return p.contains(index) ? index : 0;
|
||||
}
|
||||
|
||||
public Integer visitConstantPoolRefAndValue(Instruction instr, int index, int value, List<Integer> p) {
|
||||
return p.contains(index) ? index : 0;
|
||||
}
|
||||
|
||||
public Integer visitLocal(Instruction instr, int index, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitLocalAndValue(Instruction instr, int index, int value, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitValue(Instruction instr, int value, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer visitUnknown(Instruction instr, List<Integer> p) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.16 and 4.8.17.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public abstract class RuntimeAnnotations_attribute extends Attribute {
|
||||
protected RuntimeAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(name_index, length);
|
||||
int num_annotations = cr.readUnsignedShort();
|
||||
annotations = new Annotation[num_annotations];
|
||||
for (int i = 0; i < annotations.length; i++)
|
||||
annotations[i] = new Annotation(cr);
|
||||
}
|
||||
|
||||
protected RuntimeAnnotations_attribute(int name_index, Annotation[] annotations) {
|
||||
super(name_index, length(annotations));
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
private static int length(Annotation[] annos) {
|
||||
int n = 2;
|
||||
for (Annotation anno: annos)
|
||||
n += anno.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public final Annotation[] annotations;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.17.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class RuntimeInvisibleAnnotations_attribute extends RuntimeAnnotations_attribute {
|
||||
RuntimeInvisibleAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, AttributeException {
|
||||
super(cr, name_index, length);
|
||||
}
|
||||
|
||||
public RuntimeInvisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations)
|
||||
throws ConstantPoolException {
|
||||
this(cp.getUTF8Index(Attribute.RuntimeInvisibleAnnotations), annotations);
|
||||
}
|
||||
|
||||
public RuntimeInvisibleAnnotations_attribute(int name_index, Annotation[] annotations) {
|
||||
super(name_index, annotations);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitRuntimeInvisibleAnnotations(this, p);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.18.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class RuntimeInvisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute {
|
||||
RuntimeInvisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(cr, name_index, length);
|
||||
}
|
||||
|
||||
public RuntimeInvisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations)
|
||||
throws ConstantPoolException {
|
||||
this(cp.getUTF8Index(Attribute.RuntimeInvisibleParameterAnnotations), parameter_annotations);
|
||||
}
|
||||
|
||||
public RuntimeInvisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
|
||||
super(name_index, parameter_annotations);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitRuntimeInvisibleParameterAnnotations(this, p);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JSR 308 specification, Section 3.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class RuntimeInvisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute {
|
||||
RuntimeInvisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(cr, name_index, length);
|
||||
}
|
||||
|
||||
public RuntimeInvisibleTypeAnnotations_attribute(ConstantPool cp, TypeAnnotation[] annotations)
|
||||
throws ConstantPoolException {
|
||||
this(cp.getUTF8Index(Attribute.RuntimeInvisibleTypeAnnotations), annotations);
|
||||
}
|
||||
|
||||
public RuntimeInvisibleTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) {
|
||||
super(name_index, annotations);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitRuntimeInvisibleTypeAnnotations(this, p);
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.18 and 4.8.19.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public abstract class RuntimeParameterAnnotations_attribute extends Attribute {
|
||||
RuntimeParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(name_index, length);
|
||||
int num_parameters = cr.readUnsignedByte();
|
||||
parameter_annotations = new Annotation[num_parameters][];
|
||||
for (int p = 0; p < parameter_annotations.length; p++) {
|
||||
int num_annotations = cr.readUnsignedShort();
|
||||
Annotation[] annotations = new Annotation[num_annotations];
|
||||
for (int i = 0; i < num_annotations; i++)
|
||||
annotations[i] = new Annotation(cr);
|
||||
parameter_annotations[p] = annotations;
|
||||
}
|
||||
}
|
||||
|
||||
protected RuntimeParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
|
||||
super(name_index, length(parameter_annotations));
|
||||
this.parameter_annotations = parameter_annotations;
|
||||
}
|
||||
|
||||
private static int length(Annotation[][] anno_arrays) {
|
||||
int n = 1;
|
||||
for (Annotation[] anno_array: anno_arrays) {
|
||||
n += 2;
|
||||
for (Annotation anno: anno_array)
|
||||
n += anno.length();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public final Annotation[][] parameter_annotations;
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JSR 308 specification, Section 3.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public abstract class RuntimeTypeAnnotations_attribute extends Attribute {
|
||||
protected RuntimeTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(name_index, length);
|
||||
int num_annotations = cr.readUnsignedShort();
|
||||
annotations = new TypeAnnotation[num_annotations];
|
||||
for (int i = 0; i < annotations.length; i++)
|
||||
annotations[i] = new TypeAnnotation(cr);
|
||||
}
|
||||
|
||||
protected RuntimeTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) {
|
||||
super(name_index, length(annotations));
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
private static int length(TypeAnnotation[] annos) {
|
||||
int n = 2;
|
||||
for (TypeAnnotation anno: annos)
|
||||
n += anno.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public final TypeAnnotation[] annotations;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.16.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class RuntimeVisibleAnnotations_attribute extends RuntimeAnnotations_attribute {
|
||||
RuntimeVisibleAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(cr, name_index, length);
|
||||
}
|
||||
|
||||
public RuntimeVisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations)
|
||||
throws ConstantPoolException {
|
||||
this(cp.getUTF8Index(Attribute.RuntimeVisibleAnnotations), annotations);
|
||||
}
|
||||
|
||||
public RuntimeVisibleAnnotations_attribute(int name_index, Annotation[] annotations) {
|
||||
super(name_index, annotations);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitRuntimeVisibleAnnotations(this, p);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.18.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class RuntimeVisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute {
|
||||
RuntimeVisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(cr, name_index, length);
|
||||
}
|
||||
|
||||
public RuntimeVisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations)
|
||||
throws ConstantPoolException {
|
||||
this(cp.getUTF8Index(Attribute.RuntimeVisibleParameterAnnotations), parameter_annotations);
|
||||
}
|
||||
|
||||
public RuntimeVisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
|
||||
super(name_index, parameter_annotations);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitRuntimeVisibleParameterAnnotations(this, p);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JSR 308 specification, Section 3.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class RuntimeVisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute {
|
||||
RuntimeVisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, Annotation.InvalidAnnotation {
|
||||
super(cr, name_index, length);
|
||||
}
|
||||
|
||||
public RuntimeVisibleTypeAnnotations_attribute(ConstantPool cp, TypeAnnotation[] annotations)
|
||||
throws ConstantPoolException {
|
||||
this(cp.getUTF8Index(Attribute.RuntimeVisibleTypeAnnotations), annotations);
|
||||
}
|
||||
|
||||
public RuntimeVisibleTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) {
|
||||
super(name_index, annotations);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitRuntimeVisibleTypeAnnotations(this, p);
|
||||
}
|
||||
}
|
@ -1,272 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sun.tools.classfile.Type.*;
|
||||
|
||||
/**
|
||||
* See JVMS 4.4.4.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Signature extends Descriptor {
|
||||
|
||||
public Signature(int index) {
|
||||
super(index);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
if (type == null)
|
||||
type = parse(getValue(constant_pool));
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParameterCount(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
MethodType m = (MethodType) getType(constant_pool);
|
||||
return m.paramTypes.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameterTypes(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
MethodType m = (MethodType) getType(constant_pool);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
String sep = "";
|
||||
for (Type paramType: m.paramTypes) {
|
||||
sb.append(sep);
|
||||
sb.append(paramType);
|
||||
sep = ", ";
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReturnType(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
MethodType m = (MethodType) getType(constant_pool);
|
||||
return m.returnType.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldType(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return getType(constant_pool).toString();
|
||||
}
|
||||
|
||||
private Type parse(String sig) {
|
||||
this.sig = sig;
|
||||
sigp = 0;
|
||||
|
||||
List<TypeParamType> typeParamTypes = null;
|
||||
if (sig.charAt(sigp) == '<')
|
||||
typeParamTypes = parseTypeParamTypes();
|
||||
|
||||
if (sig.charAt(sigp) == '(') {
|
||||
List<Type> paramTypes = parseTypeSignatures(')');
|
||||
Type returnType = parseTypeSignature();
|
||||
List<Type> throwsTypes = null;
|
||||
while (sigp < sig.length() && sig.charAt(sigp) == '^') {
|
||||
sigp++;
|
||||
if (throwsTypes == null)
|
||||
throwsTypes = new ArrayList<>();
|
||||
throwsTypes.add(parseTypeSignature());
|
||||
}
|
||||
return new MethodType(typeParamTypes, paramTypes, returnType, throwsTypes);
|
||||
} else {
|
||||
Type t = parseTypeSignature();
|
||||
if (typeParamTypes == null && sigp == sig.length())
|
||||
return t;
|
||||
Type superclass = t;
|
||||
List<Type> superinterfaces = null;
|
||||
while (sigp < sig.length()) {
|
||||
if (superinterfaces == null)
|
||||
superinterfaces = new ArrayList<>();
|
||||
superinterfaces.add(parseTypeSignature());
|
||||
}
|
||||
return new ClassSigType(typeParamTypes, superclass, superinterfaces);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Type parseTypeSignature() {
|
||||
switch (sig.charAt(sigp)) {
|
||||
case 'B':
|
||||
sigp++;
|
||||
return new SimpleType("byte");
|
||||
|
||||
case 'C':
|
||||
sigp++;
|
||||
return new SimpleType("char");
|
||||
|
||||
case 'D':
|
||||
sigp++;
|
||||
return new SimpleType("double");
|
||||
|
||||
case 'F':
|
||||
sigp++;
|
||||
return new SimpleType("float");
|
||||
|
||||
case 'I':
|
||||
sigp++;
|
||||
return new SimpleType("int");
|
||||
|
||||
case 'J':
|
||||
sigp++;
|
||||
return new SimpleType("long");
|
||||
|
||||
case 'L':
|
||||
return parseClassTypeSignature();
|
||||
|
||||
case 'S':
|
||||
sigp++;
|
||||
return new SimpleType("short");
|
||||
|
||||
case 'T':
|
||||
return parseTypeVariableSignature();
|
||||
|
||||
case 'V':
|
||||
sigp++;
|
||||
return new SimpleType("void");
|
||||
|
||||
case 'Z':
|
||||
sigp++;
|
||||
return new SimpleType("boolean");
|
||||
|
||||
case '[':
|
||||
sigp++;
|
||||
return new ArrayType(parseTypeSignature());
|
||||
|
||||
case '*':
|
||||
sigp++;
|
||||
return new WildcardType();
|
||||
|
||||
case '+':
|
||||
sigp++;
|
||||
return new WildcardType(WildcardType.Kind.EXTENDS, parseTypeSignature());
|
||||
|
||||
case '-':
|
||||
sigp++;
|
||||
return new WildcardType(WildcardType.Kind.SUPER, parseTypeSignature());
|
||||
|
||||
default:
|
||||
throw new IllegalStateException(debugInfo());
|
||||
}
|
||||
}
|
||||
|
||||
private List<Type> parseTypeSignatures(char term) {
|
||||
sigp++;
|
||||
List<Type> types = new ArrayList<>();
|
||||
while (sig.charAt(sigp) != term)
|
||||
types.add(parseTypeSignature());
|
||||
sigp++;
|
||||
return types;
|
||||
}
|
||||
|
||||
private Type parseClassTypeSignature() {
|
||||
assert sig.charAt(sigp) == 'L';
|
||||
sigp++;
|
||||
return parseClassTypeSignatureRest();
|
||||
}
|
||||
|
||||
private Type parseClassTypeSignatureRest() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Type> argTypes = null;
|
||||
ClassType t = null;
|
||||
char sigch ;
|
||||
|
||||
do {
|
||||
switch (sigch = sig.charAt(sigp)) {
|
||||
case '<':
|
||||
argTypes = parseTypeSignatures('>');
|
||||
break;
|
||||
|
||||
case '.':
|
||||
case ';':
|
||||
sigp++;
|
||||
t = new ClassType(t, sb.toString(), argTypes);
|
||||
sb.setLength(0);
|
||||
argTypes = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
sigp++;
|
||||
sb.append(sigch);
|
||||
break;
|
||||
}
|
||||
} while (sigch != ';');
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private List<TypeParamType> parseTypeParamTypes() {
|
||||
assert sig.charAt(sigp) == '<';
|
||||
sigp++;
|
||||
List<TypeParamType> types = new ArrayList<>();
|
||||
while (sig.charAt(sigp) != '>')
|
||||
types.add(parseTypeParamType());
|
||||
sigp++;
|
||||
return types;
|
||||
}
|
||||
|
||||
private TypeParamType parseTypeParamType() {
|
||||
int sep = sig.indexOf(":", sigp);
|
||||
String name = sig.substring(sigp, sep);
|
||||
Type classBound = null;
|
||||
List<Type> interfaceBounds = null;
|
||||
sigp = sep + 1;
|
||||
if (sig.charAt(sigp) != ':')
|
||||
classBound = parseTypeSignature();
|
||||
while (sig.charAt(sigp) == ':') {
|
||||
sigp++;
|
||||
if (interfaceBounds == null)
|
||||
interfaceBounds = new ArrayList<>();
|
||||
interfaceBounds.add(parseTypeSignature());
|
||||
}
|
||||
return new TypeParamType(name, classBound, interfaceBounds);
|
||||
}
|
||||
|
||||
private Type parseTypeVariableSignature() {
|
||||
sigp++;
|
||||
int sep = sig.indexOf(';', sigp);
|
||||
Type t = new SimpleType(sig.substring(sigp, sep));
|
||||
sigp = sep + 1;
|
||||
return t;
|
||||
}
|
||||
|
||||
private String debugInfo() {
|
||||
return sig.substring(0, sigp) + "!" + sig.charAt(sigp) + "!" + sig.substring(sigp+1);
|
||||
}
|
||||
|
||||
private String sig;
|
||||
private int sigp;
|
||||
|
||||
private Type type;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.9.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Signature_attribute extends Attribute {
|
||||
Signature_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
signature_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Signature_attribute(ConstantPool constant_pool, int signature_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.Signature), signature_index);
|
||||
}
|
||||
|
||||
public Signature_attribute(int name_index, int signature_index) {
|
||||
super(name_index, 2);
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public String getSignature(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(signature_index);
|
||||
}
|
||||
|
||||
public Signature getParsedSignature() {
|
||||
return new Signature(signature_index);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitSignature(this, data);
|
||||
}
|
||||
|
||||
public final int signature_index;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.15.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class SourceDebugExtension_attribute extends Attribute {
|
||||
|
||||
SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
debug_extension = new byte[attribute_length];
|
||||
cr.readFully(debug_extension);
|
||||
}
|
||||
|
||||
public SourceDebugExtension_attribute(ConstantPool constant_pool, byte[] debug_extension)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.SourceDebugExtension), debug_extension);
|
||||
}
|
||||
|
||||
public SourceDebugExtension_attribute(int name_index, byte[] debug_extension) {
|
||||
super(name_index, debug_extension.length);
|
||||
this.debug_extension = debug_extension;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return new String(debug_extension, UTF_8);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitSourceDebugExtension(this, data);
|
||||
}
|
||||
|
||||
public final byte[] debug_extension;
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.10.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class SourceFile_attribute extends Attribute {
|
||||
SourceFile_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
sourcefile_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public SourceFile_attribute(ConstantPool constant_pool, int sourcefile_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.SourceFile), sourcefile_index);
|
||||
}
|
||||
|
||||
public SourceFile_attribute(int name_index, int sourcefile_index) {
|
||||
super(name_index, 2);
|
||||
this.sourcefile_index = sourcefile_index;
|
||||
}
|
||||
|
||||
public String getSourceFile(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(sourcefile_index);
|
||||
}
|
||||
|
||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||
return visitor.visitSourceFile(this, p);
|
||||
}
|
||||
|
||||
public final int sourcefile_index;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class SourceID_attribute extends Attribute {
|
||||
|
||||
SourceID_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
sourceID_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
public SourceID_attribute(ConstantPool constant_pool, int sourceID_index)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.SourceID), sourceID_index);
|
||||
}
|
||||
|
||||
public SourceID_attribute(int name_index, int sourceID_index) {
|
||||
super(name_index, 2);
|
||||
this.sourceID_index = sourceID_index;
|
||||
}
|
||||
|
||||
String getSourceID(ConstantPool constant_pool) throws ConstantPoolException {
|
||||
return constant_pool.getUTF8Value(sourceID_index);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitSourceID(this, data);
|
||||
}
|
||||
|
||||
public final int sourceID_index;
|
||||
}
|
@ -1,380 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.4.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class StackMapTable_attribute extends Attribute {
|
||||
static class InvalidStackMap extends AttributeException {
|
||||
private static final long serialVersionUID = -5659038410855089780L;
|
||||
InvalidStackMap(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
StackMapTable_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, InvalidStackMap {
|
||||
super(name_index, length);
|
||||
number_of_entries = cr.readUnsignedShort();
|
||||
entries = new stack_map_frame[number_of_entries];
|
||||
for (int i = 0; i < number_of_entries; i++)
|
||||
entries[i] = stack_map_frame.read(cr);
|
||||
}
|
||||
|
||||
public StackMapTable_attribute(ConstantPool constant_pool, stack_map_frame[] entries)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.StackMapTable), entries);
|
||||
}
|
||||
|
||||
public StackMapTable_attribute(int name_index, stack_map_frame[] entries) {
|
||||
super(name_index, length(entries));
|
||||
this.number_of_entries = entries.length;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitStackMapTable(this, data);
|
||||
}
|
||||
|
||||
static int length(stack_map_frame[] entries) {
|
||||
int n = 2;
|
||||
for (stack_map_frame entry: entries)
|
||||
n += entry.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public final int number_of_entries;
|
||||
public final stack_map_frame entries[];
|
||||
|
||||
public abstract static class stack_map_frame {
|
||||
static stack_map_frame read(ClassReader cr)
|
||||
throws IOException, InvalidStackMap {
|
||||
int frame_type = cr.readUnsignedByte();
|
||||
if (frame_type <= 63)
|
||||
return new same_frame(frame_type);
|
||||
else if (frame_type <= 127)
|
||||
return new same_locals_1_stack_item_frame(frame_type, cr);
|
||||
else if (frame_type <= 246)
|
||||
throw new Error("unknown frame_type " + frame_type);
|
||||
else if (frame_type == 247)
|
||||
return new same_locals_1_stack_item_frame_extended(frame_type, cr);
|
||||
else if (frame_type <= 250)
|
||||
return new chop_frame(frame_type, cr);
|
||||
else if (frame_type == 251)
|
||||
return new same_frame_extended(frame_type, cr);
|
||||
else if (frame_type <= 254)
|
||||
return new append_frame(frame_type, cr);
|
||||
else
|
||||
return new full_frame(frame_type, cr);
|
||||
}
|
||||
|
||||
protected stack_map_frame(int frame_type) {
|
||||
this.frame_type = frame_type;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public abstract int getOffsetDelta();
|
||||
|
||||
public abstract <R,D> R accept(Visitor<R,D> visitor, D data);
|
||||
|
||||
public final int frame_type;
|
||||
|
||||
public static interface Visitor<R,P> {
|
||||
R visit_same_frame(same_frame frame, P p);
|
||||
R visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, P p);
|
||||
R visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, P p);
|
||||
R visit_chop_frame(chop_frame frame, P p);
|
||||
R visit_same_frame_extended(same_frame_extended frame, P p);
|
||||
R visit_append_frame(append_frame frame, P p);
|
||||
R visit_full_frame(full_frame frame, P p);
|
||||
}
|
||||
}
|
||||
|
||||
public static class same_frame extends stack_map_frame {
|
||||
same_frame(int frame_type) {
|
||||
super(frame_type);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_same_frame(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return frame_type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class same_locals_1_stack_item_frame extends stack_map_frame {
|
||||
same_locals_1_stack_item_frame(int frame_type, ClassReader cr)
|
||||
throws IOException, InvalidStackMap {
|
||||
super(frame_type);
|
||||
stack = new verification_type_info[1];
|
||||
stack[0] = verification_type_info.read(cr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return super.length() + stack[0].length();
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_same_locals_1_stack_item_frame(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return frame_type - 64;
|
||||
}
|
||||
|
||||
public final verification_type_info[] stack;
|
||||
}
|
||||
|
||||
public static class same_locals_1_stack_item_frame_extended extends stack_map_frame {
|
||||
same_locals_1_stack_item_frame_extended(int frame_type, ClassReader cr)
|
||||
throws IOException, InvalidStackMap {
|
||||
super(frame_type);
|
||||
offset_delta = cr.readUnsignedShort();
|
||||
stack = new verification_type_info[1];
|
||||
stack[0] = verification_type_info.read(cr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return super.length() + 2 + stack[0].length();
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_same_locals_1_stack_item_frame_extended(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return offset_delta;
|
||||
}
|
||||
|
||||
public final int offset_delta;
|
||||
public final verification_type_info[] stack;
|
||||
}
|
||||
|
||||
public static class chop_frame extends stack_map_frame {
|
||||
chop_frame(int frame_type, ClassReader cr) throws IOException {
|
||||
super(frame_type);
|
||||
offset_delta = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return super.length() + 2;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_chop_frame(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return offset_delta;
|
||||
}
|
||||
|
||||
public final int offset_delta;
|
||||
}
|
||||
|
||||
public static class same_frame_extended extends stack_map_frame {
|
||||
same_frame_extended(int frame_type, ClassReader cr) throws IOException {
|
||||
super(frame_type);
|
||||
offset_delta = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return super.length() + 2;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_same_frame_extended(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return offset_delta;
|
||||
}
|
||||
|
||||
public final int offset_delta;
|
||||
}
|
||||
|
||||
public static class append_frame extends stack_map_frame {
|
||||
append_frame(int frame_type, ClassReader cr)
|
||||
throws IOException, InvalidStackMap {
|
||||
super(frame_type);
|
||||
offset_delta = cr.readUnsignedShort();
|
||||
locals = new verification_type_info[frame_type - 251];
|
||||
for (int i = 0; i < locals.length; i++)
|
||||
locals[i] = verification_type_info.read(cr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
int n = super.length() + 2;
|
||||
for (verification_type_info local: locals)
|
||||
n += local.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_append_frame(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return offset_delta;
|
||||
}
|
||||
|
||||
public final int offset_delta;
|
||||
public final verification_type_info[] locals;
|
||||
}
|
||||
|
||||
public static class full_frame extends stack_map_frame {
|
||||
full_frame(int frame_type, ClassReader cr)
|
||||
throws IOException, InvalidStackMap {
|
||||
super(frame_type);
|
||||
offset_delta = cr.readUnsignedShort();
|
||||
number_of_locals = cr.readUnsignedShort();
|
||||
locals = new verification_type_info[number_of_locals];
|
||||
for (int i = 0; i < locals.length; i++)
|
||||
locals[i] = verification_type_info.read(cr);
|
||||
number_of_stack_items = cr.readUnsignedShort();
|
||||
stack = new verification_type_info[number_of_stack_items];
|
||||
for (int i = 0; i < stack.length; i++)
|
||||
stack[i] = verification_type_info.read(cr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
int n = super.length() + 2;
|
||||
for (verification_type_info local: locals)
|
||||
n += local.length();
|
||||
n += 2;
|
||||
for (verification_type_info item: stack)
|
||||
n += item.length();
|
||||
return n;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visit_full_frame(this, data);
|
||||
}
|
||||
|
||||
public int getOffsetDelta() {
|
||||
return offset_delta;
|
||||
}
|
||||
|
||||
public final int offset_delta;
|
||||
public final int number_of_locals;
|
||||
public final verification_type_info[] locals;
|
||||
public final int number_of_stack_items;
|
||||
public final verification_type_info[] stack;
|
||||
}
|
||||
|
||||
public static class verification_type_info {
|
||||
public static final int ITEM_Top = 0;
|
||||
public static final int ITEM_Integer = 1;
|
||||
public static final int ITEM_Float = 2;
|
||||
public static final int ITEM_Long = 4;
|
||||
public static final int ITEM_Double = 3;
|
||||
public static final int ITEM_Null = 5;
|
||||
public static final int ITEM_UninitializedThis = 6;
|
||||
public static final int ITEM_Object = 7;
|
||||
public static final int ITEM_Uninitialized = 8;
|
||||
|
||||
static verification_type_info read(ClassReader cr)
|
||||
throws IOException, InvalidStackMap {
|
||||
int tag = cr.readUnsignedByte();
|
||||
switch (tag) {
|
||||
case ITEM_Top:
|
||||
case ITEM_Integer:
|
||||
case ITEM_Float:
|
||||
case ITEM_Long:
|
||||
case ITEM_Double:
|
||||
case ITEM_Null:
|
||||
case ITEM_UninitializedThis:
|
||||
return new verification_type_info(tag);
|
||||
|
||||
case ITEM_Object:
|
||||
return new Object_variable_info(cr);
|
||||
|
||||
case ITEM_Uninitialized:
|
||||
return new Uninitialized_variable_info(cr);
|
||||
|
||||
default:
|
||||
throw new InvalidStackMap("unrecognized verification_type_info tag");
|
||||
}
|
||||
}
|
||||
|
||||
protected verification_type_info(int tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public final int tag;
|
||||
}
|
||||
|
||||
public static class Object_variable_info extends verification_type_info {
|
||||
Object_variable_info(ClassReader cr) throws IOException {
|
||||
super(ITEM_Object);
|
||||
cpool_index = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return super.length() + 2;
|
||||
}
|
||||
|
||||
public final int cpool_index;
|
||||
}
|
||||
|
||||
public static class Uninitialized_variable_info extends verification_type_info {
|
||||
Uninitialized_variable_info(ClassReader cr) throws IOException {
|
||||
super(ITEM_Uninitialized);
|
||||
offset = cr.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return super.length() + 2;
|
||||
}
|
||||
|
||||
public final int offset;
|
||||
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class StackMap_attribute extends Attribute {
|
||||
StackMap_attribute(ClassReader cr, int name_index, int length)
|
||||
throws IOException, StackMapTable_attribute.InvalidStackMap {
|
||||
super(name_index, length);
|
||||
number_of_entries = cr.readUnsignedShort();
|
||||
entries = new stack_map_frame[number_of_entries];
|
||||
for (int i = 0; i < number_of_entries; i++)
|
||||
entries[i] = new stack_map_frame(cr);
|
||||
}
|
||||
|
||||
public StackMap_attribute(ConstantPool constant_pool, stack_map_frame[] entries)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.StackMap), entries);
|
||||
}
|
||||
|
||||
public StackMap_attribute(int name_index, stack_map_frame[] entries) {
|
||||
super(name_index, StackMapTable_attribute.length(entries));
|
||||
this.number_of_entries = entries.length;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitStackMap(this, data);
|
||||
}
|
||||
|
||||
public final int number_of_entries;
|
||||
public final stack_map_frame entries[];
|
||||
|
||||
public static class stack_map_frame extends StackMapTable_attribute.full_frame {
|
||||
stack_map_frame(ClassReader cr)
|
||||
throws IOException, StackMapTable_attribute.InvalidStackMap {
|
||||
super(255, cr);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* See JVMS, section 4.8.8.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class Synthetic_attribute extends Attribute {
|
||||
Synthetic_attribute(ClassReader cr, int name_index, int length) throws IOException {
|
||||
super(name_index, length);
|
||||
}
|
||||
|
||||
public Synthetic_attribute(ConstantPool constant_pool)
|
||||
throws ConstantPoolException {
|
||||
this(constant_pool.getUTF8Index(Attribute.Synthetic));
|
||||
}
|
||||
|
||||
public Synthetic_attribute(int name_index) {
|
||||
super(name_index, 0);
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitSynthetic(this, data);
|
||||
}
|
||||
}
|
@ -1,378 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* Family of classes used to represent the parsed form of a {@link Descriptor}
|
||||
* or {@link Signature}.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public abstract class Type {
|
||||
protected Type() { }
|
||||
|
||||
public boolean isObject() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract <R,D> R accept(Visitor<R,D> visitor, D data);
|
||||
|
||||
protected static void append(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
|
||||
sb.append(prefix);
|
||||
String sep = "";
|
||||
for (Type t: types) {
|
||||
sb.append(sep);
|
||||
sb.append(t);
|
||||
sep = ", ";
|
||||
}
|
||||
sb.append(suffix);
|
||||
}
|
||||
|
||||
protected static void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
|
||||
if (types != null && types.size() > 0)
|
||||
append(sb, prefix, types, suffix);
|
||||
}
|
||||
|
||||
public interface Visitor<R,P> {
|
||||
R visitSimpleType(SimpleType type, P p);
|
||||
R visitArrayType(ArrayType type, P p);
|
||||
R visitMethodType(MethodType type, P p);
|
||||
R visitClassSigType(ClassSigType type, P p);
|
||||
R visitClassType(ClassType type, P p);
|
||||
R visitTypeParamType(TypeParamType type, P p);
|
||||
R visitWildcardType(WildcardType type, P p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a type signature with a simple name. The name may be that of a
|
||||
* primitive type, such "{@code int}, {@code float}, etc
|
||||
* or that of a type argument, such as {@code T}, {@code K}, {@code V}, etc.
|
||||
*
|
||||
* See:
|
||||
* JVMS 4.3.2
|
||||
* BaseType:
|
||||
* {@code B}, {@code C}, {@code D}, {@code F}, {@code I},
|
||||
* {@code J}, {@code S}, {@code Z};
|
||||
* VoidDescriptor:
|
||||
* {@code V};
|
||||
* JVMS 4.3.4
|
||||
* TypeVariableSignature:
|
||||
* {@code T} Identifier {@code ;}
|
||||
*/
|
||||
public static class SimpleType extends Type {
|
||||
public SimpleType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitSimpleType(this, data);
|
||||
}
|
||||
|
||||
public boolean isPrimitiveType() {
|
||||
return primitiveTypes.contains(name);
|
||||
}
|
||||
// where
|
||||
private static final Set<String> primitiveTypes = new HashSet<>(Arrays.asList(
|
||||
"boolean", "byte", "char", "double", "float", "int", "long", "short", "void"));
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public final String name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an array type signature.
|
||||
*
|
||||
* See:
|
||||
* JVMS 4.3.4
|
||||
* ArrayTypeSignature:
|
||||
* {@code [} TypeSignature {@code ]}
|
||||
*/
|
||||
public static class ArrayType extends Type {
|
||||
public ArrayType(Type elemType) {
|
||||
this.elemType = elemType;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitArrayType(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return elemType + "[]";
|
||||
}
|
||||
|
||||
public final Type elemType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a method type signature.
|
||||
*
|
||||
* See;
|
||||
* JVMS 4.3.4
|
||||
* MethodTypeSignature:
|
||||
* FormalTypeParameters_opt {@code (} TypeSignature* {@code)} ReturnType
|
||||
* ThrowsSignature*
|
||||
*/
|
||||
public static class MethodType extends Type {
|
||||
public MethodType(List<? extends Type> paramTypes, Type resultType) {
|
||||
this(null, paramTypes, resultType, null);
|
||||
}
|
||||
|
||||
public MethodType(List<? extends TypeParamType> typeParamTypes,
|
||||
List<? extends Type> paramTypes,
|
||||
Type returnType,
|
||||
List<? extends Type> throwsTypes) {
|
||||
this.typeParamTypes = typeParamTypes;
|
||||
this.paramTypes = paramTypes;
|
||||
this.returnType = returnType;
|
||||
this.throwsTypes = throwsTypes;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitMethodType(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendIfNotEmpty(sb, "<", typeParamTypes, "> ");
|
||||
sb.append(returnType);
|
||||
append(sb, " (", paramTypes, ")");
|
||||
appendIfNotEmpty(sb, " throws ", throwsTypes, "");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public final List<? extends TypeParamType> typeParamTypes;
|
||||
public final List<? extends Type> paramTypes;
|
||||
public final Type returnType;
|
||||
public final List<? extends Type> throwsTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a class signature. These describe the signature of
|
||||
* a class that has type arguments.
|
||||
*
|
||||
* See:
|
||||
* JVMS 4.3.4
|
||||
* ClassSignature:
|
||||
* FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature*
|
||||
*/
|
||||
public static class ClassSigType extends Type {
|
||||
public ClassSigType(List<TypeParamType> typeParamTypes, Type superclassType,
|
||||
List<Type> superinterfaceTypes) {
|
||||
this.typeParamTypes = typeParamTypes;
|
||||
this.superclassType = superclassType;
|
||||
this.superinterfaceTypes = superinterfaceTypes;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassSigType(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendIfNotEmpty(sb, "<", typeParamTypes, ">");
|
||||
if (superclassType != null) {
|
||||
sb.append(" extends ");
|
||||
sb.append(superclassType);
|
||||
}
|
||||
appendIfNotEmpty(sb, " implements ", superinterfaceTypes, "");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public final List<TypeParamType> typeParamTypes;
|
||||
public final Type superclassType;
|
||||
public final List<Type> superinterfaceTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a class type signature. This is used to represent a
|
||||
* reference to a class, such as in a field, parameter, return type, etc.
|
||||
*
|
||||
* See:
|
||||
* JVMS 4.3.4
|
||||
* ClassTypeSignature:
|
||||
* {@code L} PackageSpecifier_opt SimpleClassTypeSignature
|
||||
* ClassTypeSignatureSuffix* {@code ;}
|
||||
* PackageSpecifier:
|
||||
* Identifier {@code /} PackageSpecifier*
|
||||
* SimpleClassTypeSignature:
|
||||
* Identifier TypeArguments_opt }
|
||||
* ClassTypeSignatureSuffix:
|
||||
* {@code .} SimpleClassTypeSignature
|
||||
*/
|
||||
public static class ClassType extends Type {
|
||||
public ClassType(ClassType outerType, String name, List<Type> typeArgs) {
|
||||
this.outerType = outerType;
|
||||
this.name = name;
|
||||
this.typeArgs = typeArgs;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassType(this, data);
|
||||
}
|
||||
|
||||
public String getBinaryName() {
|
||||
if (outerType == null)
|
||||
return name;
|
||||
else
|
||||
return (outerType.getBinaryName() + "$" + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (outerType != null) {
|
||||
sb.append(outerType);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(name);
|
||||
appendIfNotEmpty(sb, "<", typeArgs, ">");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObject() {
|
||||
return (outerType == null)
|
||||
&& name.equals("java/lang/Object")
|
||||
&& (typeArgs == null || typeArgs.isEmpty());
|
||||
}
|
||||
|
||||
public final ClassType outerType;
|
||||
public final String name;
|
||||
public final List<Type> typeArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a FormalTypeParameter. These are used to declare the type
|
||||
* parameters for generic classes and methods.
|
||||
*
|
||||
* See:
|
||||
* JVMS 4.3.4
|
||||
* FormalTypeParameters:
|
||||
* {@code <} FormalTypeParameter+ {@code >}
|
||||
* FormalTypeParameter:
|
||||
* Identifier ClassBound InterfaceBound*
|
||||
* ClassBound:
|
||||
* {@code :} FieldTypeSignature_opt
|
||||
* InterfaceBound:
|
||||
* {@code :} FieldTypeSignature
|
||||
*/
|
||||
public static class TypeParamType extends Type {
|
||||
public TypeParamType(String name, Type classBound, List<Type> interfaceBounds) {
|
||||
this.name = name;
|
||||
this.classBound = classBound;
|
||||
this.interfaceBounds = interfaceBounds;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitTypeParamType(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name);
|
||||
String sep = " extends ";
|
||||
if (classBound != null) {
|
||||
sb.append(sep);
|
||||
sb.append(classBound);
|
||||
sep = " & ";
|
||||
}
|
||||
if (interfaceBounds != null) {
|
||||
for (Type bound: interfaceBounds) {
|
||||
sb.append(sep);
|
||||
sb.append(bound);
|
||||
sep = " & ";
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public final String name;
|
||||
public final Type classBound;
|
||||
public final List<Type> interfaceBounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a wildcard type argument. A type argument that is not a
|
||||
* wildcard type argument will be represented by a ClassType, ArrayType, etc.
|
||||
*
|
||||
* See:
|
||||
* JVMS 4.3.4
|
||||
* TypeArgument:
|
||||
* WildcardIndicator_opt FieldTypeSignature
|
||||
* {@code *}
|
||||
* WildcardIndicator:
|
||||
* {@code +}
|
||||
* {@code -}
|
||||
*/
|
||||
public static class WildcardType extends Type {
|
||||
public enum Kind { UNBOUNDED, EXTENDS, SUPER }
|
||||
|
||||
public WildcardType() {
|
||||
this(Kind.UNBOUNDED, null);
|
||||
}
|
||||
public WildcardType(Kind kind, Type boundType) {
|
||||
this.kind = kind;
|
||||
this.boundType = boundType;
|
||||
}
|
||||
|
||||
public <R, D> R accept(Visitor<R, D> visitor, D data) {
|
||||
return visitor.visitWildcardType(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (kind) {
|
||||
case UNBOUNDED:
|
||||
return "?";
|
||||
case EXTENDS:
|
||||
return "? extends " + boundType;
|
||||
case SUPER:
|
||||
return "? super " + boundType;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public final Kind kind;
|
||||
public final Type boundType;
|
||||
}
|
||||
}
|
@ -1,654 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.classfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.tools.classfile.TypeAnnotation.Position.TypePathEntry;
|
||||
|
||||
/**
|
||||
* See JSR 308 specification, Section 3.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own risk.
|
||||
* This code and its internal interfaces are subject to change or
|
||||
* deletion without notice.</b>
|
||||
*/
|
||||
public class TypeAnnotation {
|
||||
TypeAnnotation(ClassReader cr) throws IOException, Annotation.InvalidAnnotation {
|
||||
constant_pool = cr.getConstantPool();
|
||||
position = read_position(cr);
|
||||
annotation = new Annotation(cr);
|
||||
}
|
||||
|
||||
public TypeAnnotation(ConstantPool constant_pool,
|
||||
Annotation annotation, Position position) {
|
||||
this.constant_pool = constant_pool;
|
||||
this.position = position;
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
int n = annotation.length();
|
||||
n += position_length(position);
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return "@" + constant_pool.getUTF8Value(annotation.type_index).substring(1) +
|
||||
" pos: " + position.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public final ConstantPool constant_pool;
|
||||
public final Position position;
|
||||
public final Annotation annotation;
|
||||
|
||||
private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation {
|
||||
// Copied from ClassReader
|
||||
int tag = cr.readUnsignedByte(); // TargetType tag is a byte
|
||||
if (!TargetType.isValidTargetTypeValue(tag))
|
||||
throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag));
|
||||
|
||||
TargetType type = TargetType.fromTargetTypeValue(tag);
|
||||
|
||||
Position position = new Position();
|
||||
position.type = type;
|
||||
|
||||
switch (type) {
|
||||
// instanceof
|
||||
case INSTANCEOF:
|
||||
// new expression
|
||||
case NEW:
|
||||
// constructor/method reference receiver
|
||||
case CONSTRUCTOR_REFERENCE:
|
||||
case METHOD_REFERENCE:
|
||||
position.offset = cr.readUnsignedShort();
|
||||
break;
|
||||
// local variable
|
||||
case LOCAL_VARIABLE:
|
||||
// resource variable
|
||||
case RESOURCE_VARIABLE:
|
||||
int table_length = cr.readUnsignedShort();
|
||||
position.lvarOffset = new int[table_length];
|
||||
position.lvarLength = new int[table_length];
|
||||
position.lvarIndex = new int[table_length];
|
||||
for (int i = 0; i < table_length; ++i) {
|
||||
position.lvarOffset[i] = cr.readUnsignedShort();
|
||||
position.lvarLength[i] = cr.readUnsignedShort();
|
||||
position.lvarIndex[i] = cr.readUnsignedShort();
|
||||
}
|
||||
break;
|
||||
// exception parameter
|
||||
case EXCEPTION_PARAMETER:
|
||||
position.exception_index = cr.readUnsignedShort();
|
||||
break;
|
||||
// method receiver
|
||||
case METHOD_RECEIVER:
|
||||
// Do nothing
|
||||
break;
|
||||
// type parameter
|
||||
case CLASS_TYPE_PARAMETER:
|
||||
case METHOD_TYPE_PARAMETER:
|
||||
position.parameter_index = cr.readUnsignedByte();
|
||||
break;
|
||||
// type parameter bound
|
||||
case CLASS_TYPE_PARAMETER_BOUND:
|
||||
case METHOD_TYPE_PARAMETER_BOUND:
|
||||
position.parameter_index = cr.readUnsignedByte();
|
||||
position.bound_index = cr.readUnsignedByte();
|
||||
break;
|
||||
// class extends or implements clause
|
||||
case CLASS_EXTENDS:
|
||||
position.type_index = cr.readUnsignedShort();
|
||||
break;
|
||||
// throws
|
||||
case THROWS:
|
||||
position.type_index = cr.readUnsignedShort();
|
||||
break;
|
||||
// method parameter
|
||||
case METHOD_FORMAL_PARAMETER:
|
||||
position.parameter_index = cr.readUnsignedByte();
|
||||
break;
|
||||
// type cast
|
||||
case CAST:
|
||||
// method/constructor/reference type argument
|
||||
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
|
||||
case METHOD_INVOCATION_TYPE_ARGUMENT:
|
||||
case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
|
||||
case METHOD_REFERENCE_TYPE_ARGUMENT:
|
||||
position.offset = cr.readUnsignedShort();
|
||||
position.type_index = cr.readUnsignedByte();
|
||||
break;
|
||||
// We don't need to worry about these
|
||||
case METHOD_RETURN:
|
||||
case FIELD:
|
||||
break;
|
||||
case UNKNOWN:
|
||||
throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!");
|
||||
default:
|
||||
throw new AssertionError("TypeAnnotation: Unknown target type: " + type);
|
||||
}
|
||||
|
||||
{ // Write type path
|
||||
int len = cr.readUnsignedByte();
|
||||
List<Integer> loc = new ArrayList<>(len);
|
||||
for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i)
|
||||
loc.add(cr.readUnsignedByte());
|
||||
position.location = Position.getTypePathFromBinary(loc);
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private static int position_length(Position pos) {
|
||||
int n = 0;
|
||||
n += 1; // TargetType tag is a byte
|
||||
switch (pos.type) {
|
||||
// instanceof
|
||||
case INSTANCEOF:
|
||||
// new expression
|
||||
case NEW:
|
||||
// constructor/method reference receiver
|
||||
case CONSTRUCTOR_REFERENCE:
|
||||
case METHOD_REFERENCE:
|
||||
n += 2; // offset
|
||||
break;
|
||||
// local variable
|
||||
case LOCAL_VARIABLE:
|
||||
// resource variable
|
||||
case RESOURCE_VARIABLE:
|
||||
n += 2; // table_length;
|
||||
int table_length = pos.lvarOffset.length;
|
||||
n += 2 * table_length; // offset
|
||||
n += 2 * table_length; // length
|
||||
n += 2 * table_length; // index
|
||||
break;
|
||||
// exception parameter
|
||||
case EXCEPTION_PARAMETER:
|
||||
n += 2; // exception_index
|
||||
break;
|
||||
// method receiver
|
||||
case METHOD_RECEIVER:
|
||||
// Do nothing
|
||||
break;
|
||||
// type parameter
|
||||
case CLASS_TYPE_PARAMETER:
|
||||
case METHOD_TYPE_PARAMETER:
|
||||
n += 1; // parameter_index
|
||||
break;
|
||||
// type parameter bound
|
||||
case CLASS_TYPE_PARAMETER_BOUND:
|
||||
case METHOD_TYPE_PARAMETER_BOUND:
|
||||
n += 1; // parameter_index
|
||||
n += 1; // bound_index
|
||||
break;
|
||||
// class extends or implements clause
|
||||
case CLASS_EXTENDS:
|
||||
n += 2; // type_index
|
||||
break;
|
||||
// throws
|
||||
case THROWS:
|
||||
n += 2; // type_index
|
||||
break;
|
||||
// method parameter
|
||||
case METHOD_FORMAL_PARAMETER:
|
||||
n += 1; // parameter_index
|
||||
break;
|
||||
// type cast
|
||||
case CAST:
|
||||
// method/constructor/reference type argument
|
||||
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
|
||||
case METHOD_INVOCATION_TYPE_ARGUMENT:
|
||||
case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
|
||||
case METHOD_REFERENCE_TYPE_ARGUMENT:
|
||||
n += 2; // offset
|
||||
n += 1; // type index
|
||||
break;
|
||||
// We don't need to worry about these
|
||||
case METHOD_RETURN:
|
||||
case FIELD:
|
||||
break;
|
||||
case UNKNOWN:
|
||||
throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!");
|
||||
default:
|
||||
throw new AssertionError("TypeAnnotation: Unknown target type: " + pos.type);
|
||||
}
|
||||
|
||||
{
|
||||
n += 1; // length
|
||||
n += TypePathEntry.bytesPerEntry * pos.location.size(); // bytes for actual array
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// Code duplicated from com.sun.tools.javac.code.TypeAnnotationPosition
|
||||
public static class Position {
|
||||
public enum TypePathEntryKind {
|
||||
ARRAY(0),
|
||||
INNER_TYPE(1),
|
||||
WILDCARD(2),
|
||||
TYPE_ARGUMENT(3);
|
||||
|
||||
public final int tag;
|
||||
|
||||
private TypePathEntryKind(int tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TypePathEntry {
|
||||
/** The fixed number of bytes per TypePathEntry. */
|
||||
public static final int bytesPerEntry = 2;
|
||||
|
||||
public final TypePathEntryKind tag;
|
||||
public final int arg;
|
||||
|
||||
public static final TypePathEntry ARRAY = new TypePathEntry(TypePathEntryKind.ARRAY);
|
||||
public static final TypePathEntry INNER_TYPE = new TypePathEntry(TypePathEntryKind.INNER_TYPE);
|
||||
public static final TypePathEntry WILDCARD = new TypePathEntry(TypePathEntryKind.WILDCARD);
|
||||
|
||||
private TypePathEntry(TypePathEntryKind tag) {
|
||||
if (!(tag == TypePathEntryKind.ARRAY ||
|
||||
tag == TypePathEntryKind.INNER_TYPE ||
|
||||
tag == TypePathEntryKind.WILDCARD)) {
|
||||
throw new AssertionError("Invalid TypePathEntryKind: " + tag);
|
||||
}
|
||||
this.tag = tag;
|
||||
this.arg = 0;
|
||||
}
|
||||
|
||||
public TypePathEntry(TypePathEntryKind tag, int arg) {
|
||||
if (tag != TypePathEntryKind.TYPE_ARGUMENT) {
|
||||
throw new AssertionError("Invalid TypePathEntryKind: " + tag);
|
||||
}
|
||||
this.tag = tag;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public static TypePathEntry fromBinary(int tag, int arg) {
|
||||
if (arg != 0 && tag != TypePathEntryKind.TYPE_ARGUMENT.tag) {
|
||||
throw new AssertionError("Invalid TypePathEntry tag/arg: " + tag + "/" + arg);
|
||||
}
|
||||
switch (tag) {
|
||||
case 0:
|
||||
return ARRAY;
|
||||
case 1:
|
||||
return INNER_TYPE;
|
||||
case 2:
|
||||
return WILDCARD;
|
||||
case 3:
|
||||
return new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg);
|
||||
default:
|
||||
throw new AssertionError("Invalid TypePathEntryKind tag: " + tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return tag.toString() +
|
||||
(tag == TypePathEntryKind.TYPE_ARGUMENT ? ("(" + arg + ")") : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (! (other instanceof TypePathEntry)) {
|
||||
return false;
|
||||
}
|
||||
TypePathEntry tpe = (TypePathEntry) other;
|
||||
return this.tag == tpe.tag && this.arg == tpe.arg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.tag.hashCode() * 17 + this.arg;
|
||||
}
|
||||
}
|
||||
|
||||
public TargetType type = TargetType.UNKNOWN;
|
||||
|
||||
// For generic/array types.
|
||||
// TODO: or should we use null? No one will use this object.
|
||||
public List<TypePathEntry> location = new ArrayList<>(0);
|
||||
|
||||
// Tree position.
|
||||
public int pos = -1;
|
||||
|
||||
// For typecasts, type tests, new (and locals, as start_pc).
|
||||
public boolean isValidOffset = false;
|
||||
public int offset = -1;
|
||||
|
||||
// For locals. arrays same length
|
||||
public int[] lvarOffset = null;
|
||||
public int[] lvarLength = null;
|
||||
public int[] lvarIndex = null;
|
||||
|
||||
// For type parameter bound
|
||||
public int bound_index = Integer.MIN_VALUE;
|
||||
|
||||
// For type parameter and method parameter
|
||||
public int parameter_index = Integer.MIN_VALUE;
|
||||
|
||||
// For class extends, implements, and throws clauses
|
||||
public int type_index = Integer.MIN_VALUE;
|
||||
|
||||
// For exception parameters, index into exception table
|
||||
public int exception_index = Integer.MIN_VALUE;
|
||||
|
||||
public Position() {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('[');
|
||||
sb.append(type);
|
||||
|
||||
switch (type) {
|
||||
// instanceof
|
||||
case INSTANCEOF:
|
||||
// new expression
|
||||
case NEW:
|
||||
// constructor/method reference receiver
|
||||
case CONSTRUCTOR_REFERENCE:
|
||||
case METHOD_REFERENCE:
|
||||
sb.append(", offset = ");
|
||||
sb.append(offset);
|
||||
break;
|
||||
// local variable
|
||||
case LOCAL_VARIABLE:
|
||||
// resource variable
|
||||
case RESOURCE_VARIABLE:
|
||||
if (lvarOffset == null) {
|
||||
sb.append(", lvarOffset is null!");
|
||||
break;
|
||||
}
|
||||
sb.append(", {");
|
||||
for (int i = 0; i < lvarOffset.length; ++i) {
|
||||
if (i != 0) sb.append("; ");
|
||||
sb.append("start_pc = ");
|
||||
sb.append(lvarOffset[i]);
|
||||
sb.append(", length = ");
|
||||
sb.append(lvarLength[i]);
|
||||
sb.append(", index = ");
|
||||
sb.append(lvarIndex[i]);
|
||||
}
|
||||
sb.append("}");
|
||||
break;
|
||||
// method receiver
|
||||
case METHOD_RECEIVER:
|
||||
// Do nothing
|
||||
break;
|
||||
// type parameter
|
||||
case CLASS_TYPE_PARAMETER:
|
||||
case METHOD_TYPE_PARAMETER:
|
||||
sb.append(", param_index = ");
|
||||
sb.append(parameter_index);
|
||||
break;
|
||||
// type parameter bound
|
||||
case CLASS_TYPE_PARAMETER_BOUND:
|
||||
case METHOD_TYPE_PARAMETER_BOUND:
|
||||
sb.append(", param_index = ");
|
||||
sb.append(parameter_index);
|
||||
sb.append(", bound_index = ");
|
||||
sb.append(bound_index);
|
||||
break;
|
||||
// class extends or implements clause
|
||||
case CLASS_EXTENDS:
|
||||
sb.append(", type_index = ");
|
||||
sb.append(type_index);
|
||||
break;
|
||||
// throws
|
||||
case THROWS:
|
||||
sb.append(", type_index = ");
|
||||
sb.append(type_index);
|
||||
break;
|
||||
// exception parameter
|
||||
case EXCEPTION_PARAMETER:
|
||||
sb.append(", exception_index = ");
|
||||
sb.append(exception_index);
|
||||
break;
|
||||
// method parameter
|
||||
case METHOD_FORMAL_PARAMETER:
|
||||
sb.append(", param_index = ");
|
||||
sb.append(parameter_index);
|
||||
break;
|
||||
// type cast
|
||||
case CAST:
|
||||
// method/constructor/reference type argument
|
||||
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
|
||||
case METHOD_INVOCATION_TYPE_ARGUMENT:
|
||||
case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
|
||||
case METHOD_REFERENCE_TYPE_ARGUMENT:
|
||||
sb.append(", offset = ");
|
||||
sb.append(offset);
|
||||
sb.append(", type_index = ");
|
||||
sb.append(type_index);
|
||||
break;
|
||||
// We don't need to worry about these
|
||||
case METHOD_RETURN:
|
||||
case FIELD:
|
||||
break;
|
||||
case UNKNOWN:
|
||||
sb.append(", position UNKNOWN!");
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unknown target type: " + type);
|
||||
}
|
||||
|
||||
// Append location data for generics/arrays.
|
||||
if (!location.isEmpty()) {
|
||||
sb.append(", location = (");
|
||||
sb.append(location);
|
||||
sb.append(")");
|
||||
}
|
||||
|
||||
sb.append(", pos = ");
|
||||
sb.append(pos);
|
||||
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the target tree of the annotation has been optimized
|
||||
* away from classfile or not.
|
||||
* @return true if the target has not been optimized away
|
||||
*/
|
||||
public boolean emitToClassfile() {
|
||||
return !type.isLocal() || isValidOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the binary representation for a type path and set
|
||||
* the {@code location} field.
|
||||
*
|
||||
* @param list The bytecode representation of the type path.
|
||||
*/
|
||||
public static List<TypePathEntry> getTypePathFromBinary(List<Integer> list) {
|
||||
List<TypePathEntry> loc = new ArrayList<>(list.size() / TypePathEntry.bytesPerEntry);
|
||||
int idx = 0;
|
||||
while (idx < list.size()) {
|
||||
if (idx + 1 == list.size()) {
|
||||
throw new AssertionError("Could not decode type path: " + list);
|
||||
}
|
||||
loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1)));
|
||||
idx += 2;
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
public static List<Integer> getBinaryFromTypePath(List<TypePathEntry> locs) {
|
||||
List<Integer> loc = new ArrayList<>(locs.size() * TypePathEntry.bytesPerEntry);
|
||||
for (TypePathEntry tpe : locs) {
|
||||
loc.add(tpe.tag.tag);
|
||||
loc.add(tpe.arg);
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
|
||||
// Code duplicated from com.sun.tools.javac.code.TargetType
|
||||
// The IsLocal flag could be removed here.
|
||||
public enum TargetType {
|
||||
/** For annotations on a class type parameter declaration. */
|
||||
CLASS_TYPE_PARAMETER(0x00),
|
||||
|
||||
/** For annotations on a method type parameter declaration. */
|
||||
METHOD_TYPE_PARAMETER(0x01),
|
||||
|
||||
/** For annotations on the type of an "extends" or "implements" clause. */
|
||||
CLASS_EXTENDS(0x10),
|
||||
|
||||
/** For annotations on a bound of a type parameter of a class. */
|
||||
CLASS_TYPE_PARAMETER_BOUND(0x11),
|
||||
|
||||
/** For annotations on a bound of a type parameter of a method. */
|
||||
METHOD_TYPE_PARAMETER_BOUND(0x12),
|
||||
|
||||
/** For annotations on a field. */
|
||||
FIELD(0x13),
|
||||
|
||||
/** For annotations on a method return type. */
|
||||
METHOD_RETURN(0x14),
|
||||
|
||||
/** For annotations on the method receiver. */
|
||||
METHOD_RECEIVER(0x15),
|
||||
|
||||
/** For annotations on a method parameter. */
|
||||
METHOD_FORMAL_PARAMETER(0x16),
|
||||
|
||||
/** For annotations on a throws clause in a method declaration. */
|
||||
THROWS(0x17),
|
||||
|
||||
/** For annotations on a local variable. */
|
||||
LOCAL_VARIABLE(0x40, true),
|
||||
|
||||
/** For annotations on a resource variable. */
|
||||
RESOURCE_VARIABLE(0x41, true),
|
||||
|
||||
/** For annotations on an exception parameter. */
|
||||
EXCEPTION_PARAMETER(0x42, true),
|
||||
|
||||
/** For annotations on a type test. */
|
||||
INSTANCEOF(0x43, true),
|
||||
|
||||
/** For annotations on an object creation expression. */
|
||||
NEW(0x44, true),
|
||||
|
||||
/** For annotations on a constructor reference receiver. */
|
||||
CONSTRUCTOR_REFERENCE(0x45, true),
|
||||
|
||||
/** For annotations on a method reference receiver. */
|
||||
METHOD_REFERENCE(0x46, true),
|
||||
|
||||
/** For annotations on a typecast. */
|
||||
CAST(0x47, true),
|
||||
|
||||
/** For annotations on a type argument of an object creation expression. */
|
||||
CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true),
|
||||
|
||||
/** For annotations on a type argument of a method call. */
|
||||
METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true),
|
||||
|
||||
/** For annotations on a type argument of a constructor reference. */
|
||||
CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true),
|
||||
|
||||
/** For annotations on a type argument of a method reference. */
|
||||
METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true),
|
||||
|
||||
/** For annotations with an unknown target. */
|
||||
UNKNOWN(0xFF);
|
||||
|
||||
private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B;
|
||||
|
||||
private final int targetTypeValue;
|
||||
private final boolean isLocal;
|
||||
|
||||
private TargetType(int targetTypeValue) {
|
||||
this(targetTypeValue, false);
|
||||
}
|
||||
|
||||
private TargetType(int targetTypeValue, boolean isLocal) {
|
||||
if (targetTypeValue < 0
|
||||
|| targetTypeValue > 255)
|
||||
throw new AssertionError("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue));
|
||||
this.targetTypeValue = targetTypeValue;
|
||||
this.isLocal = isLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this TargetType represents an annotation whose
|
||||
* target is exclusively a tree in a method body
|
||||
*
|
||||
* Note: wildcard bound targets could target a local tree and a class
|
||||
* member declaration signature tree
|
||||
*/
|
||||
public boolean isLocal() {
|
||||
return isLocal;
|
||||
}
|
||||
|
||||
public int targetTypeValue() {
|
||||
return this.targetTypeValue;
|
||||
}
|
||||
|
||||
private static final TargetType[] targets;
|
||||
|
||||
static {
|
||||
targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
|
||||
TargetType[] alltargets = values();
|
||||
for (TargetType target : alltargets) {
|
||||
if (target.targetTypeValue != UNKNOWN.targetTypeValue)
|
||||
targets[target.targetTypeValue] = target;
|
||||
}
|
||||
for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) {
|
||||
if (targets[i] == null)
|
||||
targets[i] = UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidTargetTypeValue(int tag) {
|
||||
if (tag == UNKNOWN.targetTypeValue)
|
||||
return true;
|
||||
return (tag >= 0 && tag < targets.length);
|
||||
}
|
||||
|
||||
public static TargetType fromTargetTypeValue(int tag) {
|
||||
if (tag == UNKNOWN.targetTypeValue)
|
||||
return UNKNOWN;
|
||||
|
||||
if (tag < 0 || tag >= targets.length)
|
||||
throw new AssertionError("Unknown TargetType: " + tag);
|
||||
return targets[tag];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
A minimalist library to read and write class files into objects closely
|
||||
based on the corresponding definitions in
|
||||
<cite>The Java Virtual Machine Specification</cite> (JVMS).
|
||||
|
||||
<p><b>This is NOT part of any supported API.
|
||||
If you write code that depends on this, you do so at your own risk.
|
||||
This code and its internal interfaces are subject to change or
|
||||
deletion without notice.</b>
|
||||
*/
|
||||
package com.sun.tools.classfile;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -70,8 +70,6 @@ module jdk.jdeps {
|
||||
|
||||
uses com.sun.tools.javac.platform.PlatformProvider;
|
||||
|
||||
exports com.sun.tools.classfile to jdk.jlink;
|
||||
|
||||
provides java.util.spi.ToolProvider with
|
||||
com.sun.tools.javap.Main.JavapToolProvider,
|
||||
com.sun.tools.jdeps.Main.JDepsToolProvider,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,7 +32,6 @@
|
||||
* jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.file
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
* jdk.jdeps/com.sun.tools.classfile
|
||||
* @build toolbox.ToolBox toolbox.JavacTask
|
||||
* @run main WildcardBoundsNotReadFromClassFileTest
|
||||
*/
|
||||
@ -42,7 +41,6 @@ import java.nio.file.Paths;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.util.Assert;
|
||||
import com.sun.tools.classfile.ClassFile;
|
||||
|
||||
import toolbox.TestRunner;
|
||||
import toolbox.ToolBox;
|
||||
|
Loading…
x
Reference in New Issue
Block a user