提交 19955628 编写于 作者: J jjg

4075303: Use javap to enquire aboput a specific inner class

4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini
上级 236f5bc2
......@@ -66,7 +66,7 @@ javac.no.jdk.warnings = -XDignore.symbol.file=true
# set the following to -version to verify the versions of javac being used
javac.version.opt =
# in time, there should be no exceptions to -Xlint:all
javac.lint.opts = -Xlint:all,-unchecked,-deprecation,-fallthrough,-cast,-serial -Werror
javac.lint.opts = -Xlint:all,-deprecation,-fallthrough,-serial -Werror
# options for the <javadoc> task for javac
javadoc.jls3.url=http://java.sun.com/docs/books/jls/
......@@ -120,6 +120,8 @@ javah.tests = \
tools/javah/
javap.includes = \
com/sun/tools/classfile/ \
com/sun/tools/javap/ \
sun/tools/javap/
javap.tests = \
......
......@@ -136,7 +136,7 @@
<arg value="-html:${findbugs.home}/src/xsl/fancy.xsl"/>
<arg value="${dist.findbugs.dir}/findbugs.xml"/>
<redirector output="${dist.findbugs.dir}/findbugs.html"/>
</exec>
</exec>
</target>
<target name="coverage" depends="-def-cobertura,build-all-classes,instrument-classes,jtreg,coverage-report"/>
......@@ -301,14 +301,15 @@
jarmainclass="sun.tools.javap.Main"/>
</target>
<target name="build-classes-javap" depends="build-bootstrap-javac">
<target name="build-classes-javap" depends="build-classes-javac">
<build-classes name="javap" includes="${javap.includes}"/>
</target>
<target name="build-javap" depends="build-bootstrap-javac">
<target name="build-javap" depends="build-javac">
<build-tool name="javap"
includes="${javap.includes}"
jarmainclass="sun.tools.javap.Main"/>
jarmainclass="sun.tools.javap.Main"
jarclasspath="javac.jar"/>
</target>
<!-- (no javadoc for javap) -->
......@@ -480,7 +481,7 @@
destdir="@{gensrc.dir}"
includes="@{includes}"/>
<copy todir="@{gensrc.dir}">
<fileset dir="${src.classes.dir}" includes="${javac.includes}"/>
<fileset dir="${src.classes.dir}" includes="@{includes}"/>
<globmapper from="*.properties-template" to="*.properties"/>
<filterset begintoken="$(" endtoken=")">
<filter token="JDK_VERSION" value="${jdk.version}"/>
......
......@@ -157,5 +157,5 @@
</action>
<action name="javadoc">
<target>javadoc-nb</target>
<target>-javadoc-nb</target>
</action>
......@@ -157,5 +157,5 @@
</action>
<action name="javadoc">
<target>javadoc-nb</target>
<target>-javadoc-nb</target>
</action>
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 JVMS3, sections 4.2, 4.6, 4.7.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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_MODULE = 0x8000; // class, inner, field, method
private static enum Type { 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;
}
private static final int[] classModifiers = {
ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT, ACC_MODULE
};
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, Type.Class);
}
public Set<String> getClassFlags() {
return getFlags(classFlags, Type.Class);
}
private static final int[] innerClassModifiers = {
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
ACC_ABSTRACT, ACC_MODULE
};
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, ACC_MODULE
};
public Set<String> getInnerClassModifiers() {
int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
return getModifiers(f, innerClassModifiers, Type.InnerClass);
}
public Set<String> getInnerClassFlags() {
return getFlags(innerClassFlags, Type.InnerClass);
}
private static final int[] fieldModifiers = {
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
ACC_VOLATILE, ACC_TRANSIENT, ACC_MODULE
};
private static final int[] fieldFlags = {
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM, ACC_MODULE
};
public Set<String> getFieldModifiers() {
return getModifiers(fieldModifiers, Type.Field);
}
public Set<String> getFieldFlags() {
return getFlags(fieldFlags, Type.Field);
}
private static final int[] methodModifiers = {
ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT, ACC_MODULE
};
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, ACC_MODULE
};
public Set<String> getMethodModifiers() {
return getModifiers(methodModifiers, Type.Method);
}
public Set<String> getMethodFlags() {
return getFlags(methodFlags, Type.Method);
}
private Set<String> getModifiers(int[] modifierFlags, Type t) {
return getModifiers(flags, modifierFlags, t);
}
private static Set<String> getModifiers(int flags, int[] modifierFlags, Type t) {
Set<String> s = new LinkedHashSet<String>();
for (int m: modifierFlags) {
if ((flags & m) != 0)
s.add(flagToModifier(m, t));
}
return s;
}
private Set<String> getFlags(int[] expectedFlags, Type t) {
Set<String> s = new LinkedHashSet<String>();
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, Type 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 == Type.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_MODULE:
return "module";
default:
return null;
}
}
private static String flagToName(int flag, Type 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 == Type.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED");
case 0x40:
return (t == Type.Field ? "ACC_VOLATILE" : "ACC_BRIDGE");
case 0x80:
return (t == Type.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 ACC_MODULE:
return "ACC_MODULE";
default:
return null;
}
}
final int flags;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.16.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
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 JVMS3, section 4.8.16.1.
*/
public static abstract 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();
}
@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();
}
@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();
}
@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);
}
@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);
}
@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 int length() {
return 2 + value.length();
}
public final int element_name_index;
public final element_value value;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.15.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 API supported by Sun Microsystems. 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 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 RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations";
public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations";
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";
// JSR 277/294
public static final String Module = "Module";
public static final String ModuleExportTable = "ModuleExportTable";
public static final String ModuleMemberTable = "ModuleMemberTable";
public static class Factory {
public Factory() {
// defer init of standardAttributeClasses until after options set up
}
public void setCompat(boolean compat) {
this.compat = compat;
}
public void setJSR277(boolean jsr277) {
this.jsr277 = jsr277;
}
public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
throws IOException {
if (standardAttributes == null)
init();
ConstantPool cp = cr.getConstantPool();
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(new Object[] { cr, name_index, data.length });
} catch (Throwable t) {
// fall through and use DefaultAttribute
// t.printStackTrace();
}
}
} catch (ConstantPoolException e) {
// fall through and use DefaultAttribute
}
return new DefaultAttribute(cr, name_index, data);
}
protected void init() {
standardAttributes = new HashMap<String,Class<? extends Attribute>>();
standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class);
standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
standardAttributes.put(Code, Code_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);
if (jsr277) {
standardAttributes.put(Module, Module_attribute.class);
standardAttributes.put(ModuleExportTable, ModuleExportTable_attribute.class);
standardAttributes.put(ModuleMemberTable, ModuleMemberTable_attribute.class);
}
if (!compat) { // old javap does not recognize recent attributes
standardAttributes.put(CompilationID, CompilationID_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(Signature, Signature_attribute.class);
standardAttributes.put(SourceID, SourceID_attribute.class);
}
standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class);
standardAttributes.put(SourceFile, SourceFile_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;
private boolean compat; // don't support recent attrs in compatibility mode
private boolean jsr277; // support new jsr277 attrs
}
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 final int attribute_name_index;
public final int attribute_length;
public interface Visitor<R,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 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 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);
R visitModule(Module_attribute attr, P p);
R visitModuleExportTable(ModuleExportTable_attribute attr, P p);
R visitModuleMemberTable(ModuleMemberTable_attribute attr, P p);
}
}
/*
* Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
/*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
AttributeException() { }
AttributeException(String msg) {
super(msg);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 API supported by Sun Microsystems. 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> {
Attributes(ClassReader cr) throws IOException {
map = new HashMap<String,Attribute>();
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<String,Attribute>();
for (int i = 0; i < attrs.length; i++) {
Attribute attr = attrs[i];
try {
map.put(attr.getName(constant_pool), attr);
} catch (ConstantPoolException e) {
// don't enter invalid names in map
}
}
}
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 size() {
return attrs.length;
}
public final Attribute[] attrs;
public final Map<String, Attribute> map;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 API supported by Sun Microsystems. 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, 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;
};
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import static com.sun.tools.classfile.AccessFlags.*;
/**
* See JVMS3, section 4.2.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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, new Attribute.Factory());
}
public static ClassFile read(File file, Attribute.Factory attributeFactory)
throws IOException, ConstantPoolException {
FileInputStream in = new FileInputStream(file);
try {
return new ClassFile(in, attributeFactory);
} finally {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
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 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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;
/**
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
// null checks
classFile.getClass();
attributeFactory.getClass();
this.classFile = classFile;
this.in = new DataInputStream(new BufferedInputStream(in));
this.attributeFactory = attributeFactory;
}
ClassFile getClassFile() {
return classFile;
}
ConstantPool getConstantPool() {
return classFile.constant_pool;
}
public Attribute readAttribute() throws IOException {
int name_index = readUnsignedShort();
int length = readInt();
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;
}
/*
* Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 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_Long_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_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;
import java.util.Map;
/**
* Rewrites a class file using a map of translations.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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&nbsp;-\&gt;&nbsp;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(); i++) {
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();
switch (cpInfo.getTag()) {
case ConstantPool.CONSTANT_Double:
case ConstantPool.CONSTANT_Long:
i += 1;
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.3.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 class InvalidIndex extends AttributeException {
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_langth = cr.readUnsignedShort();
exception_table = new Exception_data[exception_table_langth];
for (int i = 0; i < exception_table_langth; 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 final int max_stack;
public final int max_locals;
public final int code_length;
public final byte[] code;
public final int exception_table_langth;
public final Exception_data[] exception_table;
public final Attributes attributes;
public 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;
}
}
/*
* Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.5.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 ConstantPool {
public class InvalidIndex extends ConstantPoolException {
InvalidIndex(int index) {
super(index);
}
@Override
public String getMessage() {
// i18n
return "invalid index #" + index;
}
}
public class UnexpectedEntry extends ConstantPoolException {
UnexpectedEntry(int index, int expected_tag, int found_tag) {
super(index);
this.expected_tag = expected_tag;
this.found_tag = found_tag;
}
@Override
public String getMessage() {
// i18n?
return "unexpected entry at #" + index + " -- expected tag " + expected_tag + ", found " + found_tag;
}
public final int expected_tag;
public final int found_tag;
}
public class InvalidEntry extends ConstantPoolException {
InvalidEntry(int index, int tag) {
super(index);
this.tag = tag;
}
@Override
public String getMessage() {
// i18n?
return "unexpected tag at #" + index + ": " + tag;
}
public final int tag;
}
public class EntryNotFound extends ConstantPoolException {
EntryNotFound(Object value) {
super(-1);
this.value = value;
}
@Override
public String getMessage() {
// i18n?
return "value not found: " + value;
}
public final Object value;
}
public static final int CONSTANT_Utf8 = 1;
public static final int CONSTANT_Integer = 3;
public static final int CONSTANT_Float = 4;
public static final int CONSTANT_Long = 5;
public static final int CONSTANT_Double = 6;
public static final int CONSTANT_Class = 7;
public static final int CONSTANT_String = 8;
public static final int CONSTANT_Fieldref = 9;
public static final int CONSTANT_Methodref = 10;
public static final int CONSTANT_InterfaceMethodref = 11;
public static final int CONSTANT_NameAndType = 12;
ConstantPool(ClassReader cr) throws IOException, InvalidEntry {
int count = cr.readUnsignedShort();
pool = new CPInfo[count];
for (int i = 1; i < count; i++) {
int tag = cr.readUnsignedByte();
switch (tag) {
case CONSTANT_Class:
pool[i] = new CONSTANT_Class_info(this, cr);
break;
case CONSTANT_Double:
pool[i] = new CONSTANT_Double_info(cr);
i++;
break;
case CONSTANT_Fieldref:
pool[i] = new CONSTANT_Fieldref_info(this, cr);
break;
case CONSTANT_Float:
pool[i] = new CONSTANT_Float_info(cr);
break;
case CONSTANT_Integer:
pool[i] = new CONSTANT_Integer_info(cr);
break;
case CONSTANT_InterfaceMethodref:
pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr);
break;
case CONSTANT_Long:
pool[i] = new CONSTANT_Long_info(cr);
i++;
break;
case CONSTANT_Methodref:
pool[i] = new CONSTANT_Methodref_info(this, cr);
break;
case CONSTANT_NameAndType:
pool[i] = new CONSTANT_NameAndType_info(this, cr);
break;
case CONSTANT_String:
pool[i] = new CONSTANT_String_info(cr);
break;
case CONSTANT_Utf8:
pool[i] = new CONSTANT_Utf8_info(cr);
break;
default:
throw new InvalidEntry(i, tag);
}
}
}
public ConstantPool(CPInfo[] pool) {
this.pool = pool;
}
public int size() {
return pool.length;
}
public CPInfo get(int index) throws InvalidIndex {
if (index <= 0 || index >= pool.length)
throw new InvalidIndex(index);
CPInfo info = pool[index];
if (info == null) {
// this occurs for indices referencing the "second half" of an
// 8 byte constant, such as CONSTANT_Double or CONSTANT_Long
throw new InvalidIndex(index);
}
return pool[index];
}
private CPInfo get(int index, int expected_type) throws InvalidIndex, UnexpectedEntry {
CPInfo info = get(index);
if (info.getTag() != expected_type)
throw new UnexpectedEntry(index, expected_type, info.getTag());
return info;
}
public CONSTANT_Utf8_info getUTF8Info(int index) throws InvalidIndex, UnexpectedEntry {
return ((CONSTANT_Utf8_info) get(index, CONSTANT_Utf8));
}
public CONSTANT_Class_info getClassInfo(int index) throws InvalidIndex, UnexpectedEntry {
return ((CONSTANT_Class_info) get(index, CONSTANT_Class));
}
public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry {
return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType));
}
public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry {
return getUTF8Info(index).value;
}
public int getUTF8Index(String value) throws EntryNotFound {
for (int i = 1; i < pool.length; i++) {
CPInfo info = pool[i];
if (info instanceof CONSTANT_Utf8_info &&
((CONSTANT_Utf8_info) info).value.equals(value))
return i;
}
throw new EntryNotFound(value);
}
private CPInfo[] pool;
public interface Visitor<R,P> {
R visitClass(CONSTANT_Class_info info, P p);
R visitDouble(CONSTANT_Double_info info, P p);
R visitFieldref(CONSTANT_Fieldref_info info, P p);
R visitFloat(CONSTANT_Float_info info, P p);
R visitInteger(CONSTANT_Integer_info info, P p);
R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p);
R visitLong(CONSTANT_Long_info info, P p);
R visitNameAndType(CONSTANT_NameAndType_info info, P p);
R visitMethodref(CONSTANT_Methodref_info info, P p);
R visitString(CONSTANT_String_info info, P p);
R visitUtf8(CONSTANT_Utf8_info info, P p);
}
public static abstract class CPInfo {
CPInfo() {
this.cp = null;
}
CPInfo(ConstantPool cp) {
this.cp = cp;
}
public abstract int getTag();
public abstract <R,D> R accept(Visitor<R,D> visitor, D data);
protected final ConstantPool cp;
}
public static abstract class CPRefInfo extends CPInfo {
protected CPRefInfo(ConstantPool cp, ClassReader cr, int tag) throws IOException {
super(cp);
this.tag = tag;
class_index = cr.readUnsignedShort();
name_and_type_index = cr.readUnsignedShort();
}
protected CPRefInfo(ConstantPool cp, int tag, int class_index, int name_and_type_index) {
super(cp);
this.tag = tag;
this.class_index = class_index;
this.name_and_type_index = name_and_type_index;
}
public int getTag() {
return tag;
}
public CONSTANT_Class_info getClassInfo() throws ConstantPoolException {
return cp.getClassInfo(class_index);
}
public String getClassName() throws ConstantPoolException {
return cp.getClassInfo(class_index).getName();
}
public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException {
return cp.getNameAndTypeInfo(name_and_type_index);
}
public final int tag;
public final int class_index;
public final int name_and_type_index;
}
public static class CONSTANT_Class_info extends CPInfo {
CONSTANT_Class_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
name_index = cr.readUnsignedShort();
}
public CONSTANT_Class_info(ConstantPool cp, int name_index) {
super(cp);
this.name_index = name_index;
}
public int getTag() {
return CONSTANT_Class;
}
public String getName() throws ConstantPoolException {
return cp.getUTF8Value(name_index);
}
@Override
public String toString() {
return "CONSTANT_Class_info[name_index: " + name_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitClass(this, data);
}
public final int name_index;
}
public static class CONSTANT_Double_info extends CPInfo {
CONSTANT_Double_info(ClassReader cr) throws IOException {
value = cr.readDouble();
}
public CONSTANT_Double_info(double value) {
this.value = value;
}
public int getTag() {
return CONSTANT_Double;
}
@Override
public String toString() {
return "CONSTANT_Double_info[value: " + value + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitDouble(this, data);
}
public final double value;
}
public static class CONSTANT_Fieldref_info extends CPRefInfo {
CONSTANT_Fieldref_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp, cr, CONSTANT_Fieldref);
}
public CONSTANT_Fieldref_info(ConstantPool cp, int class_index, int name_and_type_index) {
super(cp, CONSTANT_Fieldref, class_index, name_and_type_index);
}
@Override
public String toString() {
return "CONSTANT_Fieldref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitFieldref(this, data);
}
}
public static class CONSTANT_Float_info extends CPInfo {
CONSTANT_Float_info(ClassReader cr) throws IOException {
value = cr.readFloat();
}
public CONSTANT_Float_info(float value) {
this.value = value;
}
public int getTag() {
return CONSTANT_Float;
}
@Override
public String toString() {
return "CONSTANT_Float_info[value: " + value + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitFloat(this, data);
}
public final float value;
}
public static class CONSTANT_Integer_info extends CPInfo {
CONSTANT_Integer_info(ClassReader cr) throws IOException {
value = cr.readInt();
}
public CONSTANT_Integer_info(int value) {
this.value = value;
}
public int getTag() {
return CONSTANT_Integer;
}
@Override
public String toString() {
return "CONSTANT_Integer_info[value: " + value + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitInteger(this, data);
}
public final int value;
}
public static class CONSTANT_InterfaceMethodref_info extends CPRefInfo {
CONSTANT_InterfaceMethodref_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp, cr, CONSTANT_InterfaceMethodref);
}
public CONSTANT_InterfaceMethodref_info(ConstantPool cp, int class_index, int name_and_type_index) {
super(cp, CONSTANT_InterfaceMethodref, class_index, name_and_type_index);
}
@Override
public String toString() {
return "CONSTANT_InterfaceMethodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitInterfaceMethodref(this, data);
}
}
public static class CONSTANT_Long_info extends CPInfo {
CONSTANT_Long_info(ClassReader cr) throws IOException {
value = cr.readLong();
}
public CONSTANT_Long_info(long value) {
this.value = value;
}
public int getTag() {
return CONSTANT_Long;
}
@Override
public String toString() {
return "CONSTANT_Long_info[value: " + value + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitLong(this, data);
}
public final long value;
}
public static class CONSTANT_Methodref_info extends CPRefInfo {
CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp, cr, CONSTANT_Methodref);
}
public CONSTANT_Methodref_info(ConstantPool cp, int class_index, int name_and_type_index) {
super(cp, CONSTANT_Methodref, class_index, name_and_type_index);
}
@Override
public String toString() {
return "CONSTANT_Methodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitMethodref(this, data);
}
}
public static class CONSTANT_NameAndType_info extends CPInfo {
CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
name_index = cr.readUnsignedShort();
type_index = cr.readUnsignedShort();
}
public CONSTANT_NameAndType_info(ConstantPool cp, int name_index, int type_index) {
super(cp);
this.name_index = name_index;
this.type_index = type_index;
}
public int getTag() {
return CONSTANT_NameAndType;
}
public String getName() throws ConstantPoolException {
return cp.getUTF8Value(name_index);
}
public String getType() throws ConstantPoolException {
return cp.getUTF8Value(type_index);
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitNameAndType(this, data);
}
public final int name_index;
public final int type_index;
}
public static class CONSTANT_String_info extends CPInfo {
CONSTANT_String_info(ClassReader cr) throws IOException {
string_index = cr.readUnsignedShort();
}
public CONSTANT_String_info(ConstantPool cp, int string_index) {
super(cp);
this.string_index = string_index;
}
public int getTag() {
return CONSTANT_String;
}
public String getString() throws ConstantPoolException {
return cp.getUTF8Value(string_index);
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitString(this, data);
}
public final int string_index;
}
public static class CONSTANT_Utf8_info extends CPInfo {
CONSTANT_Utf8_info(ClassReader cr) throws IOException {
value = cr.readUTF();
}
public CONSTANT_Utf8_info(String value) {
this.value = value;
}
public int getTag() {
return CONSTANT_Utf8;
}
@Override
public String toString() {
return "CONSTANT_Utf8_info[value: " + value + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitUtf8(this, data);
}
public final String value;
}
}
/*
* Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
/*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
ConstantPoolException(int index) {
this.index = index;
}
public final int index;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.2.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
/*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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) {
super(name_index, data.length);
info = data;
}
public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
super(name_index, info.length);
this.info = info;
}
public <R, P> R accept(Visitor<R, P> visitor, P p) {
return visitor.visitDefault(this, p);
}
public final byte[] info;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.15.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.4.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 class InvalidDescriptor extends DescriptorException {
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;
StringBuffer sb = new StringBuffer();
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;
}
/*
* Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
/*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.7.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.5.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 API supported by Sun Microsystems. 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 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 JVMS3, section 4.8.6.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 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;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.12.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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, 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;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.13.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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, 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;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.14.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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, 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;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 API supported by Sun Microsystems. 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 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JSR 277.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 ModuleExportTable_attribute extends Attribute {
ModuleExportTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
super(name_index, length);
int export_type_length = cr.readUnsignedShort();
export_type_table = new int[export_type_length];
for (int i = 0; i < export_type_table.length; i++)
export_type_table[i] = cr.readUnsignedShort();
}
public ModuleExportTable_attribute(ConstantPool cp, int[] export_type_table)
throws ConstantPoolException {
this(cp.getUTF8Index(Attribute.ModuleExportTable), export_type_table);
}
public ModuleExportTable_attribute(int name_index, int[] export_type_table) {
super(name_index, 2 * export_type_table.length);
this.export_type_table = export_type_table;
}
public int getExportTypeCount() {
return export_type_table.length;
}
public String getExportTypeName(int index, ConstantPool constant_pool) throws ConstantPoolException {
return constant_pool.getUTF8Value(export_type_table[index]);
}
public <R, P> R accept(Visitor<R, P> visitor, P p) {
return visitor.visitModuleExportTable(this, p);
}
public final int[] export_type_table;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JSR 277.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 ModuleMemberTable_attribute extends Attribute {
ModuleMemberTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
super(name_index, length);
int package_member_length = cr.readUnsignedShort();
package_member_table = new int[package_member_length];
for (int i = 0; i < package_member_table.length; i++)
package_member_table[i] = cr.readUnsignedShort();
}
public ModuleMemberTable_attribute(ConstantPool cp, int[] package_member_table)
throws ConstantPoolException {
this(cp.getUTF8Index(Attribute.ModuleMemberTable), package_member_table);
}
public ModuleMemberTable_attribute(int name_index, int[] package_member_table) {
super(name_index, 2 * package_member_table.length);
this.package_member_table = package_member_table;
}
public int getPackageMemberCount() {
return package_member_table.length;
}
public String getPackageMemberName(int index, ConstantPool constant_pool) throws ConstantPoolException {
return constant_pool.getUTF8Value(package_member_table[index]);
}
public <R, P> R accept(Visitor<R, P> visitor, P p) {
return visitor.visitModuleMemberTable(this, p);
}
public final int[] package_member_table;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JSR 277.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
Module_attribute(ClassReader cr, int name_index, int length) throws IOException {
super(name_index, length);
module_name = cr.readUnsignedShort();
}
public Module_attribute(ConstantPool constant_pool, int module_name)
throws ConstantPoolException {
this(constant_pool.getUTF8Index(Attribute.Module), module_name);
}
public Module_attribute(int name_index, int module_name) {
super(name_index, 2);
this.module_name = module_name;
}
public String getModuleName(ConstantPool constant_pool) throws ConstantPoolException {
return constant_pool.getUTF8Value(module_name);
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitModule(this, data);
}
public final int module_name;
}
此差异已折叠。
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.16 and 4.8.17.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.17.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.18.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.18 and 4.8.19.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.16.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JVMS3, section 4.8.18.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.classfile;
import java.util.ArrayList;
import java.util.List;
/**
* See JVMS3 4.4.4.
*
* <p><b>This is NOT part of any API supported by Sun Microsystems. 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 {
Type.MethodType m = (Type.MethodType) getType(constant_pool);
return m.argTypes.size();
}
@Override
public String getParameterTypes(ConstantPool constant_pool) throws ConstantPoolException {
Type.MethodType m = (Type.MethodType) getType(constant_pool);
StringBuilder sb = new StringBuilder();
sb.append("(");
String sep = "";
for (Type argType: m.argTypes) {
sb.append(sep);
sb.append(argType);
sep = ", ";
}
sb.append(")");
return sb.toString();
}
@Override
public String getReturnType(ConstantPool constant_pool) throws ConstantPoolException {
Type.MethodType m = (Type.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<Type> typeArgTypes = null;
if (sig.charAt(sigp) == '<')
typeArgTypes = parseTypeArgTypes();
if (sig.charAt(sigp) == '(') {
List<Type> argTypes = parseTypeSignatures(')');
Type returnType = parseTypeSignature();
List<Type> throwsTypes = null;
while (sigp < sig.length() && sig.charAt(sigp) == '^') {
sigp++;
if (throwsTypes == null)
throwsTypes = new ArrayList<Type>();
throwsTypes.add(parseTypeSignature());
}
return new Type.MethodType(typeArgTypes, argTypes, returnType, throwsTypes);
} else {
Type t = parseTypeSignature();
if (typeArgTypes == null && sigp == sig.length())
return t;
Type superclass = t;
List<Type> superinterfaces = new ArrayList<Type>();
while (sigp < sig.length())
superinterfaces.add(parseTypeSignature());
return new Type.ClassSigType(typeArgTypes, superclass, superinterfaces);
}
}
private Type parseTypeSignature() {
switch (sig.charAt(sigp)) {
case 'B':
sigp++;
return new Type.SimpleType("byte");
case 'C':
sigp++;
return new Type.SimpleType("char");
case 'D':
sigp++;
return new Type.SimpleType("double");
case 'F':
sigp++;
return new Type.SimpleType("float");
case 'I':
sigp++;
return new Type.SimpleType("int");
case 'J':
sigp++;
return new Type.SimpleType("long");
case 'L':
return parseClassTypeSignature();
case 'S':
sigp++;
return new Type.SimpleType("short");
case 'T':
return parseTypeVariableSignature();
case 'V':
sigp++;
return new Type.SimpleType("void");
case 'Z':
sigp++;
return new Type.SimpleType("boolean");
case '[':
sigp++;
return new Type.ArrayType(parseTypeSignature());
case '*':
sigp++;
return new Type.WildcardType();
case '+':
sigp++;
return new Type.WildcardType("extends", parseTypeSignature());
case '-':
sigp++;
return new Type.WildcardType("super", parseTypeSignature());
default:
throw new IllegalStateException(debugInfo());
}
}
private List<Type> parseTypeSignatures(char term) {
sigp++;
List<Type> types = new ArrayList<Type>();
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();
Type t = null;
char sigch;
while (true) {
switch (sigch = sig.charAt(sigp)) {
case '/':
sigp++;
sb.append(".");
break;
case '.':
sigp++;
if (t == null)
t = new Type.SimpleType(sb.toString());
return new Type.InnerClassType(t, parseClassTypeSignatureRest());
case ';':
sigp++;
if (t == null)
t = new Type.SimpleType(sb.toString());
return t;
case '<':
List<Type> argTypes = parseTypeSignatures('>');
t = new Type.ClassType(sb.toString(), argTypes);
break;
default:
sigp++;
sb.append(sigch);
break;
}
}
}
private List<Type> parseTypeArgTypes() {
assert sig.charAt(sigp) == '<';
sigp++;
List<Type> types = null;
types = new ArrayList<Type>();
while (sig.charAt(sigp) != '>')
types.add(parseTypeArgType());
sigp++;
return types;
}
private Type parseTypeArgType() {
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<Type>();
interfaceBounds.add(parseTypeSignature());
}
return new Type.TypeArgType(name, classBound, interfaceBounds);
}
private Type parseTypeVariableSignature() {
sigp++;
int sep = sig.indexOf(';', sigp);
Type t = new Type.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;
}
此差异已折叠。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
A minimalist library to read and write class files into objects closely
based on the corresponding definitions in the Java Virtual Machine
Specification (JVMS).
</body>
</html>
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册