public class ClassFile extends AbstractStructureWithAttributes
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SYSTEM_PROPERTY_SKIP_CONSTANT_POOL
Set this JVM System property to true to skip reading of constant pool
entries.
|
attributes
classFile, debug, SYSTEM_PROPERTY_DEBUG
Constructor and Description |
---|
ClassFile()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
enlargeConstantPool(CPInfo[] enlargedConstantPool)
Set the array with all constant pool entries where the new array
of constant pool entries starts with the old constant pool.
|
int |
getAccessFlags()
Get the access flags of this class.
|
java.lang.String |
getAccessFlagsVerbose()
Get the verbose description of the access flags of this class.
|
CPInfo[] |
getConstantPool()
Get the array with all constant pool entries.
|
CPInfo |
getConstantPoolEntry(int index,
java.lang.Class entryClass)
Get the constant pool entry at the specified index and cast it to a specified class.
|
java.lang.String |
getConstantPoolEntryName(int index)
Get an approximate verbose description of the content of the constant pool entry
at the specified index.
|
int |
getConstantPoolIndex(CPInfo cpInfo)
Get the index of an equivalent constant pool entry.
|
ConstantUtf8Info |
getConstantPoolUtf8Entry(int index)
Get the ConstantUtf8Info constant pool entry at the specified index.
|
FieldInfo |
getField(java.lang.String name,
java.lang.String descriptor)
Get the FieldInfo for given field name and signature.
|
int |
getFieldIndex(java.lang.String name,
java.lang.String descriptor)
Get the index of a field for given field name and signature.
|
FieldInfo[] |
getFields()
Get the array with the FieldInfo structures for the fields of this class.
|
java.lang.String |
getFormattedAccessFlags()
Get the the access flags of this class as a hex string.
|
int[] |
getInterfaces()
Get the array with the constant pool entries of all interfaces.
|
int |
getMajorVersion()
Get the major version of the class file format.
|
MethodInfo |
getMethod(java.lang.String name,
java.lang.String descriptor)
Get the MethodInfo for given method name and signature.
|
int |
getMethodIndex(java.lang.String name,
java.lang.String descriptor)
Get the index of a method for given method name and signature.
|
MethodInfo[] |
getMethods()
Get the array with the MethodInfo structures for the methods of this class.
|
int |
getMinorVersion()
Get the minor version of the class file format.
|
int |
getSuperClass()
Get the constant pool index of the super class of this class.
|
java.lang.String |
getSuperClassName()
Get the name of the super class.
|
int |
getThisClass()
Get the constant pool index of this class.
|
java.lang.String |
getThisClassName()
Get the name of this class.
|
protected java.lang.String |
printAccessFlagsVerbose(int accessFlags)
Utility method for derived structures.
|
void |
read(java.io.DataInput in)
Read this structure from the given DataInput.
|
protected void |
readAttributes(java.io.DataInput in)
Read the attributes of this structure from the given DataInput.
|
void |
registerConstantPoolEntry(int index)
Register the constant pool entry at a given index, so that it can
be found through the getConstantPoolIndex method.
|
void |
setAccessFlags(int accessFlags)
Set the access flags of this class.
|
void |
setConstantPool(CPInfo[] constantPool)
Set the array with all constant pool entries.
|
void |
setFields(FieldInfo[] fields)
Set the array with the FieldInfo structures for the fields of this class.
|
void |
setInterfaces(int[] interfaces)
Set the array with the constant pool entries of all interfaces.
|
void |
setMajorVersion(int majorVersion)
Set the major version of the class file format.
|
void |
setMethods(MethodInfo[] methods)
Set the array with the MethodInfo structures for the methods of this class.
|
void |
setMinorVersion(int minorVersion)
Set the minor version of the class file format.
|
void |
setSuperClass(int superClass)
Set the constant pool index of the super class of this class.
|
void |
setThisClass(int thisClass)
Set the constant pool index of this class.
|
void |
unregisterConstantPoolEntry(int index)
Unregister the constant pool entry at a given index, so that it can
no longer be found through the getConstantPoolIndex method.
|
void |
write(java.io.DataOutput in)
Write this structure to the given DataOutput.
|
protected void |
writeAttributes(java.io.DataOutput out)
Write the attributes of this structure to the given DataOutput.
|
findAttribute, getAttributes, getTotalAttributesLength, setAttributes
debug, getClassFile, getDebug, getLength, printAccessFlags, printAccessFlagsVerbose, printBytes, setClassFile, setDebug
public static final java.lang.String SYSTEM_PROPERTY_SKIP_CONSTANT_POOL
public int getMinorVersion()
public void setMinorVersion(int minorVersion)
minorVersion
- the minor versionpublic int getMajorVersion()
public void setMajorVersion(int majorVersion)
majorVersion
- the major versionpublic CPInfo[] getConstantPool()
public int getConstantPoolIndex(CPInfo cpInfo)
cpInfo
- the constant pool entrypublic void setConstantPool(CPInfo[] constantPool)
constantPool
- the arraypublic void enlargeConstantPool(CPInfo[] enlargedConstantPool)
enlargedConstantPool
- the arraypublic void registerConstantPoolEntry(int index)
index
- the indexpublic void unregisterConstantPoolEntry(int index)
index
- the indexpublic int getAccessFlags()
public void setAccessFlags(int accessFlags)
accessFlags
- the access flagspublic int getThisClass()
public void setThisClass(int thisClass)
thisClass
- the indexpublic java.lang.String getThisClassName() throws InvalidByteCodeException
InvalidByteCodeException
public int getSuperClass()
public void setSuperClass(int superClass)
superClass
- the indexpublic java.lang.String getSuperClassName() throws InvalidByteCodeException
InvalidByteCodeException
public int[] getInterfaces()
public void setInterfaces(int[] interfaces)
interfaces
- the arraypublic FieldInfo[] getFields()
public void setFields(FieldInfo[] fields)
fields
- the arraypublic MethodInfo[] getMethods()
public void setMethods(MethodInfo[] methods)
methods
- the arraypublic java.lang.String getFormattedAccessFlags()
public java.lang.String getAccessFlagsVerbose()
public ConstantUtf8Info getConstantPoolUtf8Entry(int index) throws InvalidByteCodeException
index
- the indexInvalidByteCodeException
- if the entry is not a ConstantUtf8Infopublic CPInfo getConstantPoolEntry(int index, java.lang.Class entryClass) throws InvalidByteCodeException
index
- the indexentryClass
- the required subtype of CPInfoInvalidByteCodeException
- if the entry is of a different class than expectedpublic java.lang.String getConstantPoolEntryName(int index) throws InvalidByteCodeException
index
- the indexInvalidByteCodeException
- if the entry is invalidpublic int getFieldIndex(java.lang.String name, java.lang.String descriptor) throws InvalidByteCodeException
name
- the field name.descriptor
- the signature.InvalidByteCodeException
public FieldInfo getField(java.lang.String name, java.lang.String descriptor) throws InvalidByteCodeException
name
- the field name.descriptor
- the signature.InvalidByteCodeException
public int getMethodIndex(java.lang.String name, java.lang.String descriptor) throws InvalidByteCodeException
name
- the method name.descriptor
- the signature.InvalidByteCodeException
public MethodInfo getMethod(java.lang.String name, java.lang.String descriptor) throws InvalidByteCodeException
name
- the method name.descriptor
- the signature.InvalidByteCodeException
public void read(java.io.DataInput in) throws InvalidByteCodeException, java.io.IOException
AbstractStructure
Excpects DataInput to be in JVM class file format and just before a structure of this kind. No look ahead parsing since the class file format is deterministic.
read
in class AbstractStructure
in
- the DataInput from which to readInvalidByteCodeException
- if the byte code is invalidjava.io.IOException
- if an exception occurs with the DataInputpublic void write(java.io.DataOutput in) throws InvalidByteCodeException, java.io.IOException
AbstractStructure
The written bytes are in JVM class file format.
write
in class AbstractStructure
in
- the DataOutput to which to writeInvalidByteCodeException
- if the structure is internally inconsistentjava.io.IOException
- if an exception occurs with the DataOutputprotected void readAttributes(java.io.DataInput in) throws InvalidByteCodeException, java.io.IOException
AbstractStructureWithAttributes
Excpects DataInput to be in JVM class file format and just before an attribute length field.
readAttributes
in class AbstractStructureWithAttributes
in
- the DataInput from which to readInvalidByteCodeException
- if the byte code is invalidjava.io.IOException
- if an exception occurs with the DataInputprotected void writeAttributes(java.io.DataOutput out) throws InvalidByteCodeException, java.io.IOException
AbstractStructureWithAttributes
The written bytes are in JVM class file format.
writeAttributes
in class AbstractStructureWithAttributes
out
- the DataOutput to which to writeInvalidByteCodeException
- if the structure is internally inconsistentjava.io.IOException
- if an exception occurs with the DataOutputprotected java.lang.String printAccessFlagsVerbose(int accessFlags)
AbstractStructure
printAccessFlagsVerbose
in class AbstractStructure
accessFlags
- the unsigned short value to print as a hex string