Class ClassFile
- java.lang.Object
-
- org.codehaus.janino.util.ClassFile
-
- All Implemented Interfaces:
Annotatable
public class ClassFile extends java.lang.Object implements Annotatable
An object that implements the Java "class file" format.ClassFile(InputStream)
reads bytecode from anInputStream
and creates aClassFile
object from it.store(OutputStream)
generates JVM bytecode which is suitable for being processed by a Java virtual machine, and writes it to anOutputStream
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassFile.Annotation
The structure of theannotations
array as described in JVMS8 4.7.16.static class
ClassFile.AnnotationDefaultAttribute
Representation of anAnnotationDefault
attribute (see JVMS8 4.7.22).static class
ClassFile.AnnotationsAttribute
Representation of aRuntime[In]visibleAnnotations
attribute (see JVMS8 4.7.16/17).static class
ClassFile.ArrayElementValue
Representation of the "array_value" structure.static class
ClassFile.AttributeInfo
Representation of a class file attribute (see JVMS7 4.7).static class
ClassFile.BooleanElementValue
static class
ClassFile.ByteElementValue
static class
ClassFile.CharElementValue
static class
ClassFile.ClassElementValue
static class
ClassFile.ClassFileException
Unchecked exception that represents an error condition that could occur during processing of class files, e.g.static class
ClassFile.CodeAttribute
Representation of an unmodifiableCode
attribute, as read from a class file.static class
ClassFile.ConstantClassInfo
See JVMS7 4.4.1.static class
ClassFile.ConstantElementValue
Convenience class for element values that are constants (as opposed to annotations, enum constants and arrays).static class
ClassFile.ConstantFieldrefInfo
See JVMS7 4.4.2.static class
ClassFile.ConstantInterfaceMethodrefInfo
See JVMS7 4.4.2.static class
ClassFile.ConstantInvokeDynamicInfo
See JVMS7 4.4.10.static class
ClassFile.ConstantMethodHandleInfo
See JVMS7 4.4.8.static class
ClassFile.ConstantMethodrefInfo
See JVMS7 4.4.2.static class
ClassFile.ConstantMethodTypeInfo
See JVMS7 4.4.9.static class
ClassFile.ConstantNameAndTypeInfo
See JVMS7 4.4.6.static class
ClassFile.ConstantPoolInfo
Base for various the constant pool table entry types.static class
ClassFile.ConstantUtf8Info
See JVMS7 4.4.7.static class
ClassFile.ConstantValueAttribute
Representation of aConstantValue
attribute (see JVMS 4.7.2).static class
ClassFile.ConstantValuePoolInfo
Intermediate base class for constant pool table entry types that have 'value' semantics: Double, Float, Integer, Long, Stringstatic class
ClassFile.DeprecatedAttribute
Representation of aDeprecated
attribute (see JVMS 4.7.10).static class
ClassFile.DoubleElementValue
static interface
ClassFile.ElementValue
Representation of the "element_value" structure (see JVMS8 4.7.16.1).static class
ClassFile.EnumConstValue
Representation of the "enum_const_value" element in the "element_value" structure.static class
ClassFile.ExceptionsAttribute
Representation of anExceptions
attribute (see JVMS 4.7.4).class
ClassFile.FieldInfo
Representation of a "method_info" structure, as defined by JVMS7 4.5.static class
ClassFile.FloatElementValue
static class
ClassFile.InnerClassesAttribute
Representation of anInnerClasses
attribute (see JVMS 4.7.5).static class
ClassFile.IntElementValue
static class
ClassFile.LineNumberTableAttribute
Representation of aLineNumberTable
attribute (see JVMS 4.7.8).static class
ClassFile.LocalVariableTableAttribute
Representation of aLocalVariableTable
attribute (see JVMS 4.7.9).static class
ClassFile.LongElementValue
class
ClassFile.MethodInfo
Representation of a "method_info" structure, as defined by JVMS7 4.6.static class
ClassFile.ShortElementValue
static class
ClassFile.SignatureAttribute
Representation of aSignature
attribute (see JVMS 4.7.9).static class
ClassFile.SourceFileAttribute
Representation of aSourceFile
attribute (see JVMS 4.7.7).static class
ClassFile.StackMapTableAttribute
Representation of an unmodifiableStackMapTable
attribute, as read from a class file.static class
ClassFile.StringElementValue
static class
ClassFile.SyntheticAttribute
Representation of aSynthetic
attribute (see JVMS 4.7.6).
-
Field Summary
Fields Modifier and Type Field Description short
accessFlags
The access flags of the class.java.util.List<ClassFile.FieldInfo>
fieldInfos
TheClassFile.FieldInfo
s of the field members of this class or interface.short[]
interfaces
The constant pool indexes ofClassFile.ConstantClassInfo
which describe the interfaces that this class implements, resp. that this interface extends.static short
MAJOR_VERSION_JDK_1_1
Major version number of a class file that was generated by a Java 1.1-compliant compiler.static short
MAJOR_VERSION_JDK_1_10
Major version number of a class file that was generated by a Java 1.10-compliant compiler.static short
MAJOR_VERSION_JDK_1_11
Major version number of a class file that was generated by a Java 1.11-compliant compiler.static short
MAJOR_VERSION_JDK_1_12
Major version number of a class file that was generated by a Java 1.12-compliant compiler.static short
MAJOR_VERSION_JDK_1_2
Major version number of a class file that was generated by a Java 1.2-compliant compiler.static short
MAJOR_VERSION_JDK_1_3
Major version number of a class file that was generated by a Java 1.3-compliant compiler.static short
MAJOR_VERSION_JDK_1_4
Major version number of a class file that was generated by a Java 1.4-compliant compiler.static short
MAJOR_VERSION_JDK_1_5
Major version number of a class file that was generated by a Java 1.5-compliant compiler.static short
MAJOR_VERSION_JDK_1_6
Major version number of a class file that was generated by a Java 1.6-compliant compiler.static short
MAJOR_VERSION_JDK_1_7
Major version number of a class file that was generated by a Java 1.7-compliant compiler.static short
MAJOR_VERSION_JDK_1_8
Major version number of a class file that was generated by a Java 1.8-compliant compiler.static short
MAJOR_VERSION_JDK_1_9
Major version number of a class file that was generated by a Java 1.9-compliant compiler.java.util.List<ClassFile.MethodInfo>
methodInfos
TheClassFile.MethodInfo
s of the methods of this class or interface.static short
MINOR_VERSION_JDK_1_1
Minor version number of a class file that was generated by a Java 1.1-compliant compiler.static short
MINOR_VERSION_JDK_1_10
Minor version number of a class file that was generated by a Java 1.10-compliant compiler.static short
MINOR_VERSION_JDK_1_11
Minor version number of a class file that was generated by a Java 1.11-compliant compiler.static short
MINOR_VERSION_JDK_1_12
Minor version number of a class file that was generated by a Java 1.12-compliant compiler.static short
MINOR_VERSION_JDK_1_2
Minor version number of a class file that was generated by a Java 1.2-compliant compiler.static short
MINOR_VERSION_JDK_1_3
Minor version number of a class file that was generated by a Java 1.3-compliant compiler.static short
MINOR_VERSION_JDK_1_4
Minor version number of a class file that was generated by a Java 1.4-compliant compiler.static short
MINOR_VERSION_JDK_1_5
Minor version number of a class file that was generated by a Java 1.5-compliant compiler.static short
MINOR_VERSION_JDK_1_6
Minor version number of a class file that was generated by a Java 1.6-compliant compiler.static short
MINOR_VERSION_JDK_1_7
Minor version number of a class file that was generated by a Java 1.7-compliant compiler.static short
MINOR_VERSION_JDK_1_8
Minor version number of a class file that was generated by a Java 1.8-compliant compiler.static short
MINOR_VERSION_JDK_1_9
Minor version number of a class file that was generated by a Java 1.9-compliant compiler.short
superclass
The constant pool index of theClassFile.ConstantClassInfo
that describes the superclass of this class.short
thisClass
The constant pool index of theClassFile.ConstantClassInfo
that describes this class.
-
Constructor Summary
Constructors Constructor Description ClassFile(short accessFlags, java.lang.String thisClassFd, java.lang.String superclassFd, java.lang.String[] interfaceFds)
Constructs a class with no fields and methods.ClassFile(java.io.InputStream inputStream)
Reads "class file" data from the inputStream and construct aClassFile
object from it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAnnotationsAttributeEntry(boolean runtimeVisible, java.lang.String fieldDescriptor, java.util.Map<java.lang.Short,ClassFile.ElementValue> elementValuePairs)
Creates aRuntime[In]visibleAnnotations
attribute on the class (if it does not yet exist) and adds an entry to it.short
addConstantClassInfo(java.lang.String typeFd)
Returns the constant index number for a "CONSTANT_Class_info" structure to the class file.short
addConstantDoubleInfo(double value)
Adds a "CONSTANT_Double_info" structure to the class file.short
addConstantFieldrefInfo(java.lang.String classFd, java.lang.String fieldName, java.lang.String fieldFd)
Adds a "CONSTANT_Fieldref_info" structure to the class file.short
addConstantFloatInfo(float value)
Adds a "CONSTANT_Float_info" structure to the class file.short
addConstantIntegerInfo(int value)
Adds a "CONSTANT_Integer_info" structure to the class file.short
addConstantInterfaceMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
Adds a "CONSTANT_InterfaceMethodref_info" structure to the class file.short
addConstantLongInfo(long value)
Adds a "CONSTANT_Long_info" structure to the class file.short
addConstantMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
Adds a "CONSTANT_Methodref_info" structure to the class file.short
addConstantStringInfo(java.lang.String string)
Adds a "CONSTANT_String_info" structure to the class file.short
addConstantUtf8Info(java.lang.String s)
Adds a "CONSTANT_Utf8_info" structure to the class file if no equal entry exists.void
addDeprecatedAttribute()
Adds theDeprecated
attribute to this class.ClassFile.FieldInfo
addFieldInfo(short accessFlags, java.lang.String fieldName, java.lang.String fieldTypeFd, java.lang.Object constantValue)
Creates aClassFile.FieldInfo
and adds it to this class.void
addInnerClassesAttributeEntry(ClassFile.InnerClassesAttribute.Entry entry)
Creates anInnerClasses
attribute if it does not exist, then adds the entry to theInnerClasses
attribute.ClassFile.MethodInfo
addMethodInfo(short accessFlags, java.lang.String methodName, MethodDescriptor methodMd)
Creates aClassFile.MethodInfo
and adds it to this class.void
addSourceFileAttribute(java.lang.String sourceFileName)
Adds aSourceFile
attribute to this class file.ClassFile.Annotation[]
getAnnotations(boolean runtimeVisible)
static java.lang.String
getClassFileResourceName(java.lang.String className)
Constructs the name of a resource that could contain the class file of the class with the className.ClassFile.ConstantClassInfo
getConstantClassInfo(short index)
ClassFile.ConstantFieldrefInfo
getConstantFieldrefInfo(short index)
ClassFile.ConstantInterfaceMethodrefInfo
getConstantInterfaceMethodrefInfo(short index)
ClassFile.ConstantInvokeDynamicInfo
getConstantInvokeDynamicInfo(short index)
ClassFile.ConstantMethodHandleInfo
getConstantMethodHandleInfo(short index)
ClassFile.ConstantMethodrefInfo
getConstantMethodrefInfo(short index)
ClassFile.ConstantMethodTypeInfo
getConstantMethodTypeInfo(short index)
ClassFile.ConstantNameAndTypeInfo
getConstantNameAndTypeInfo(short index)
ClassFile.ConstantPoolInfo
getConstantPoolInfo(short index)
int
getConstantPoolSize()
java.lang.String
getConstantUtf8(short index)
Shorthand forgetConstantUtf8Info(index).s
.ClassFile.ConstantUtf8Info
getConstantUtf8Info(short index)
ClassFile.ConstantValuePoolInfo
getConstantValuePoolInfo(short index)
ClassFile.InnerClassesAttribute
getInnerClassesAttribute()
Finds theInnerClasses
attribute of this class file.short
getMajorVersion()
short
getMinorVersion()
ClassFile.SignatureAttribute
getSignatureAttribute()
static java.lang.String
getSourceResourceName(java.lang.String className)
Constructs the name of a resource that could contain the source code of the class with the className.java.lang.String
getThisClassName()
ClassFile.StackMapTableAttribute.ObjectVariableInfo
newObjectVariableInfo(java.lang.String fieldDescriptor)
ClassFile.StackMapTableAttribute.UninitializedVariableInfo
newUninitializedVariableInfo(short offset)
void
setVersion(short majorVersion, short minorVersion)
Sets the major and minor class file version numbers (JVMS 4.1).void
store(java.io.OutputStream os)
WritesClassFile
to anOutputStream
, in "class file" format.byte[]
toByteArray()
Returns the byte code of thisClassFile
as a byte array.java.lang.String
toString()
-
-
-
Field Detail
-
MAJOR_VERSION_JDK_1_1
public static final short MAJOR_VERSION_JDK_1_1
Major version number of a class file that was generated by a Java 1.1-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_1
public static final short MINOR_VERSION_JDK_1_1
Minor version number of a class file that was generated by a Java 1.1-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_2
public static final short MAJOR_VERSION_JDK_1_2
Major version number of a class file that was generated by a Java 1.2-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_2
public static final short MINOR_VERSION_JDK_1_2
Minor version number of a class file that was generated by a Java 1.2-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_3
public static final short MAJOR_VERSION_JDK_1_3
Major version number of a class file that was generated by a Java 1.3-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_3
public static final short MINOR_VERSION_JDK_1_3
Minor version number of a class file that was generated by a Java 1.3-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_4
public static final short MAJOR_VERSION_JDK_1_4
Major version number of a class file that was generated by a Java 1.4-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_4
public static final short MINOR_VERSION_JDK_1_4
Minor version number of a class file that was generated by a Java 1.4-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_5
public static final short MAJOR_VERSION_JDK_1_5
Major version number of a class file that was generated by a Java 1.5-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_5
public static final short MINOR_VERSION_JDK_1_5
Minor version number of a class file that was generated by a Java 1.5-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_6
public static final short MAJOR_VERSION_JDK_1_6
Major version number of a class file that was generated by a Java 1.6-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_6
public static final short MINOR_VERSION_JDK_1_6
Minor version number of a class file that was generated by a Java 1.6-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_7
public static final short MAJOR_VERSION_JDK_1_7
Major version number of a class file that was generated by a Java 1.7-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_7
public static final short MINOR_VERSION_JDK_1_7
Minor version number of a class file that was generated by a Java 1.7-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_8
public static final short MAJOR_VERSION_JDK_1_8
Major version number of a class file that was generated by a Java 1.8-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_8
public static final short MINOR_VERSION_JDK_1_8
Minor version number of a class file that was generated by a Java 1.8-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_9
public static final short MAJOR_VERSION_JDK_1_9
Major version number of a class file that was generated by a Java 1.9-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_9
public static final short MINOR_VERSION_JDK_1_9
Minor version number of a class file that was generated by a Java 1.9-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_10
public static final short MAJOR_VERSION_JDK_1_10
Major version number of a class file that was generated by a Java 1.10-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_10
public static final short MINOR_VERSION_JDK_1_10
Minor version number of a class file that was generated by a Java 1.10-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_11
public static final short MAJOR_VERSION_JDK_1_11
Major version number of a class file that was generated by a Java 1.11-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_11
public static final short MINOR_VERSION_JDK_1_11
Minor version number of a class file that was generated by a Java 1.11-compliant compiler.- See Also:
- Constant Field Values
-
MAJOR_VERSION_JDK_1_12
public static final short MAJOR_VERSION_JDK_1_12
Major version number of a class file that was generated by a Java 1.12-compliant compiler.- See Also:
- Constant Field Values
-
MINOR_VERSION_JDK_1_12
public static final short MINOR_VERSION_JDK_1_12
Minor version number of a class file that was generated by a Java 1.12-compliant compiler.- See Also:
- Constant Field Values
-
accessFlags
public final short accessFlags
The access flags of the class.- See Also:
and consorts
-
thisClass
public final short thisClass
The constant pool index of theClassFile.ConstantClassInfo
that describes this class.
-
superclass
public final short superclass
The constant pool index of theClassFile.ConstantClassInfo
that describes the superclass of this class. Zero for classObject
,Object
for interfaces.- See Also:
- "JVMS11 4.1, The ClassFile Structure"
-
interfaces
public final short[] interfaces
The constant pool indexes ofClassFile.ConstantClassInfo
which describe the interfaces that this class implements, resp. that this interface extends.
-
fieldInfos
public final java.util.List<ClassFile.FieldInfo> fieldInfos
TheClassFile.FieldInfo
s of the field members of this class or interface.
-
methodInfos
public final java.util.List<ClassFile.MethodInfo> methodInfos
TheClassFile.MethodInfo
s of the methods of this class or interface.
-
-
Constructor Detail
-
ClassFile
public ClassFile(short accessFlags, java.lang.String thisClassFd, @Nullable java.lang.String superclassFd, java.lang.String[] interfaceFds)
Constructs a class with no fields and methods. An application would typically add fields and methods before saving it.By default, the .class file major and minor version are that of the currently executing JVM (system property
"java.class.version"
).- Parameters:
accessFlags
- As defined byMod
thisClassFd
- The field descriptor for this classsuperclassFd
- The field descriptor for the extended class (e.g. "Ljava/lang/Object;");null
forObject
interfaceFds
- The field descriptors for the implemented interfaces- See Also:
setVersion(short, short)
,addFieldInfo(short, String, String, Object)
,addMethodInfo(short, String, MethodDescriptor)
-
ClassFile
public ClassFile(java.io.InputStream inputStream) throws java.io.IOException
Reads "class file" data from the inputStream and construct aClassFile
object from it.If the
ClassFile
is created with this constructor, then most modifying operations lead to aUnsupportedOperationException
; only fields, methods and attributes can be added.- Throws:
java.io.IOException
-
-
Method Detail
-
addSourceFileAttribute
public void addSourceFileAttribute(java.lang.String sourceFileName)
Adds aSourceFile
attribute to this class file. (Does not check whether one exists already.)- Parameters:
sourceFileName
-
-
addDeprecatedAttribute
public void addDeprecatedAttribute()
Adds theDeprecated
attribute to this class.
-
getInnerClassesAttribute
@Nullable public ClassFile.InnerClassesAttribute getInnerClassesAttribute()
Finds theInnerClasses
attribute of this class file.- Returns:
null
if this class has no "InnerClasses" attribute
-
getSignatureAttribute
@Nullable public ClassFile.SignatureAttribute getSignatureAttribute()
-
addInnerClassesAttributeEntry
public void addInnerClassesAttributeEntry(ClassFile.InnerClassesAttribute.Entry entry)
Creates anInnerClasses
attribute if it does not exist, then adds the entry to theInnerClasses
attribute.
-
getAnnotations
public ClassFile.Annotation[] getAnnotations(boolean runtimeVisible)
- Specified by:
getAnnotations
in interfaceAnnotatable
- Returns:
- The annotations on this element; an empty array iff there are no annotations
-
addAnnotationsAttributeEntry
public void addAnnotationsAttributeEntry(boolean runtimeVisible, java.lang.String fieldDescriptor, java.util.Map<java.lang.Short,ClassFile.ElementValue> elementValuePairs)
Creates aRuntime[In]visibleAnnotations
attribute on the class (if it does not yet exist) and adds an entry to it.- Specified by:
addAnnotationsAttributeEntry
in interfaceAnnotatable
- Parameters:
elementValuePairs
- Maps element-name constant-pool-index (ClassFile.ConstantUtf8Info
) to element value
-
getThisClassName
public java.lang.String getThisClassName()
- Returns:
- The fully qualified name of this class, e.g. "pkg1.pkg2.Outer$Inner"
-
setVersion
public void setVersion(short majorVersion, short minorVersion)
Sets the major and minor class file version numbers (JVMS 4.1).ClassFile
declares a set of valid major-minor version number pairs, e.g.MAJOR_VERSION_JDK_1_6
andMINOR_VERSION_JDK_1_6
.
-
getMajorVersion
public short getMajorVersion()
- Returns:
- The current major class file version number
-
getMinorVersion
public short getMinorVersion()
- Returns:
- The current minor class file version number
-
addConstantClassInfo
public short addConstantClassInfo(java.lang.String typeFd)
Returns the constant index number for a "CONSTANT_Class_info" structure to the class file. If the class hasn't been added before, adds it to the constant pool. Otherwise returns the constant number for that element of the pool.- See Also:
- JVM specification, section 4.4.1
-
addConstantFieldrefInfo
public short addConstantFieldrefInfo(java.lang.String classFd, java.lang.String fieldName, java.lang.String fieldFd)
Adds a "CONSTANT_Fieldref_info" structure to the class file.- See Also:
- JVM specification, section 4.4.2
-
addConstantMethodrefInfo
public short addConstantMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
Adds a "CONSTANT_Methodref_info" structure to the class file.- See Also:
- JVM specification, section 4.4.2
-
addConstantInterfaceMethodrefInfo
public short addConstantInterfaceMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
Adds a "CONSTANT_InterfaceMethodref_info" structure to the class file.- See Also:
- JVM specification, section 4.4.2
-
addConstantStringInfo
public short addConstantStringInfo(java.lang.String string)
Adds a "CONSTANT_String_info" structure to the class file.- See Also:
- JVM specification, section 4.4.3
-
addConstantIntegerInfo
public short addConstantIntegerInfo(int value)
Adds a "CONSTANT_Integer_info" structure to the class file.- See Also:
- JVM specification, section 4.4.4
-
addConstantFloatInfo
public short addConstantFloatInfo(float value)
Adds a "CONSTANT_Float_info" structure to the class file.- See Also:
- JVM specification, section 4.4.4
-
addConstantLongInfo
public short addConstantLongInfo(long value)
Adds a "CONSTANT_Long_info" structure to the class file.- See Also:
- JVM specification, section 4.4.5
-
addConstantDoubleInfo
public short addConstantDoubleInfo(double value)
Adds a "CONSTANT_Double_info" structure to the class file.- See Also:
- JVM specification, section 4.4.5
-
addConstantUtf8Info
public short addConstantUtf8Info(java.lang.String s)
Adds a "CONSTANT_Utf8_info" structure to the class file if no equal entry exists.- Returns:
- The index of the already existing or newly created entry
- See Also:
- JVM specification, section 4.4.7
-
addFieldInfo
public ClassFile.FieldInfo addFieldInfo(short accessFlags, java.lang.String fieldName, java.lang.String fieldTypeFd, @Nullable java.lang.Object constantValue)
Creates aClassFile.FieldInfo
and adds it to this class. The return value can be used e.g. to add attributes (Deprecated
, ...) to the field.
-
addMethodInfo
public ClassFile.MethodInfo addMethodInfo(short accessFlags, java.lang.String methodName, MethodDescriptor methodMd)
Creates aClassFile.MethodInfo
and adds it to this class. The return value can be used e.g. to add attributes (Code
,Deprecated
,Exceptions
, ...) to the method.
-
getConstantPoolInfo
public ClassFile.ConstantPoolInfo getConstantPoolInfo(short index)
- Returns:
- The (read-only) constant pool entry indexed by index
- Throws:
ClassFile.ClassFileException
- index is invalid
-
getConstantClassInfo
public ClassFile.ConstantClassInfo getConstantClassInfo(short index)
- Returns:
- The (read-only) constant class info indexed by index
-
getConstantFieldrefInfo
public ClassFile.ConstantFieldrefInfo getConstantFieldrefInfo(short index)
- Returns:
- The (read-only) constant fieldref info indexed by index
-
getConstantInterfaceMethodrefInfo
public ClassFile.ConstantInterfaceMethodrefInfo getConstantInterfaceMethodrefInfo(short index)
- Returns:
- The (read-only) constant interface methodref info indexed by index
-
getConstantInvokeDynamicInfo
public ClassFile.ConstantInvokeDynamicInfo getConstantInvokeDynamicInfo(short index)
- Returns:
- The (read-only) constant invoke dynamic info indexed by index
-
getConstantMethodHandleInfo
public ClassFile.ConstantMethodHandleInfo getConstantMethodHandleInfo(short index)
- Returns:
- The (read-only) constant method handle info indexed by index
-
getConstantMethodrefInfo
public ClassFile.ConstantMethodrefInfo getConstantMethodrefInfo(short index)
- Returns:
- The (read-only) constant methodref info indexed by index
-
getConstantMethodTypeInfo
public ClassFile.ConstantMethodTypeInfo getConstantMethodTypeInfo(short index)
- Returns:
- The (read-only) constant method type info indexed by index
-
getConstantNameAndTypeInfo
public ClassFile.ConstantNameAndTypeInfo getConstantNameAndTypeInfo(short index)
- Returns:
- The (read-only) constant name and type info indexed by index
-
getConstantUtf8Info
public ClassFile.ConstantUtf8Info getConstantUtf8Info(short index)
- Returns:
- The (read-only) constant utf8 info indexed by index
-
getConstantValuePoolInfo
public ClassFile.ConstantValuePoolInfo getConstantValuePoolInfo(short index)
- Returns:
- The (read-only) constant value pool info indexed by index
-
getConstantPoolSize
public int getConstantPoolSize()
- Returns:
- The size of the constant pool
-
getConstantUtf8
public java.lang.String getConstantUtf8(short index)
Shorthand forgetConstantUtf8Info(index).s
.- Parameters:
index
- Index to aCONSTANT_Utf8_info
in the constant pool- Returns:
- The string represented by the structure
-
store
public void store(java.io.OutputStream os) throws java.io.IOException
WritesClassFile
to anOutputStream
, in "class file" format.Notice that if an
IOException
is thrown, the class file is probably written incompletely and thus invalid. The calling method must take care of this situation, e.g. by closing the output stream and then deleting the file.- Throws:
java.io.IOException
-
getSourceResourceName
public static java.lang.String getSourceResourceName(java.lang.String className)
Constructs the name of a resource that could contain the source code of the class with the className.Notice that member types are declared inside a different type, so the relevant source file is that of the outermost declaring class.
- Parameters:
className
- Fully qualified class name, e.g."pkg1.pkg2.Outer$Inner"
- Returns:
- the name of the resource, e.g.
"pkg1/pkg2/Outer.java"
-
getClassFileResourceName
public static java.lang.String getClassFileResourceName(java.lang.String className)
Constructs the name of a resource that could contain the class file of the class with the className.- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
- the name of the resource, e.g. "pkg1/pkg2/Outer$Inner.class"
-
toByteArray
public byte[] toByteArray()
Returns the byte code of thisClassFile
as a byte array.
-
newObjectVariableInfo
public ClassFile.StackMapTableAttribute.ObjectVariableInfo newObjectVariableInfo(java.lang.String fieldDescriptor)
-
newUninitializedVariableInfo
public ClassFile.StackMapTableAttribute.UninitializedVariableInfo newUninitializedVariableInfo(short offset)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-