|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.rice.cs.cunit.classFile.ClassFile
public class ClassFile
Represents a Java class file.
Field Summary | |
---|---|
private java.util.ArrayList<AAttributeInfo> |
_attributes
Attributes of the class. |
private short |
_classAccessFlags
Class access flags. |
private ConstantPool |
_constantPool
Constant pool. |
private java.util.ArrayList<FieldInfo> |
_fields
Fields in the class. |
private java.util.ArrayList<ClassPoolInfo> |
_interfaces
Class information about implemented interfaces. |
private short |
_majorVersion
Major version. |
private java.util.ArrayList<MethodInfo> |
_methods
Methods in the class. |
private short |
_minorVersion
Minor version. |
private ClassPoolInfo |
_superClass
Class information about the superclass. |
private ClassPoolInfo |
_thisClass
Class information about this class. |
static int |
ACC_ABSTRACT
|
static int |
ACC_ANNOTATION
|
static int |
ACC_BRIDGE
|
static int |
ACC_ENUM
|
static int |
ACC_FINAL
|
static int |
ACC_INTERFACE
|
static int |
ACC_NATIVE
|
static int |
ACC_PRIVATE
|
static int |
ACC_PROTECTED
|
static int |
ACC_PUBLIC
|
static int |
ACC_STATIC
|
static int |
ACC_STRICT
|
static int |
ACC_SYNCHRONIZED
|
static int |
ACC_SYNTHETIC
|
static int |
ACC_TRANSIENT
|
static int |
ACC_VARARGS
|
static int |
ACC_VOLATILE
|
private static int |
JAVA_FILE_MAGIC
Java file magic, 0xCAFEBABE. |
Constructor Summary | |
---|---|
ClassFile(byte[] b)
Constructor. |
|
ClassFile(java.io.InputStream in)
Constructor. |
|
ClassFile(short majorVersion,
short minorVersion,
short classAccessFlags,
java.lang.String thisClassName,
java.lang.String superClassName)
|
Method Summary | |
---|---|
void |
addAttribute(AAttributeInfo newAttribute)
Add an attribute to the class. |
int[] |
addConstantPoolItems(APoolInfo[] items)
Add new items to the constant pool. |
int |
addField(java.lang.String className,
java.lang.String fieldName,
java.lang.String fieldDescriptor,
boolean addToFields,
short accessFlags)
Add the constant pool items for a field "fieldName:fieldDescriptor" in class "className". |
int |
addLongToConstantPool(long value)
Add a long constant value to the constant pool. |
int |
addMethodToConstantPool(java.lang.String className,
java.lang.String methodName,
java.lang.String methodDescriptor)
Add the constant pool items for a method "methodName:methodDescriptor" in class "className". |
int |
findMethodInConstantPool(java.lang.String className,
java.lang.String methodName,
java.lang.String methodDescriptor)
Find the method info in the constant pool for a method "methodName:methodDescriptor" in class "className". |
AAttributeInfo |
getAttribute(java.lang.String name)
Return the attribute with the specified name. |
java.util.ArrayList<AAttributeInfo> |
getAttributes()
Accessor for the attributes list. |
short |
getClassAccessFlags()
Accessor for the class access flags. |
ConstantPool |
getConstantPool()
Accessor for the constant pool. |
APoolInfo |
getConstantPoolItem(int index)
Return a constant pool item from this class. |
java.util.ArrayList<FieldInfo> |
getFields()
Accessor for the fields list. |
java.util.ArrayList<ClassPoolInfo> |
getInterfaces()
Accessor for the interface list. |
short |
getMajorVersion()
Accessor for the major version. |
java.util.ArrayList<MethodInfo> |
getMethods()
Accessor for the methods list. |
short |
getMinorVersion()
Accessor for the minor version. |
ClassPoolInfo |
getSuperClass()
Accessor for the superclass. |
java.lang.String |
getSuperClassName()
Return the name of the super class or the empty string, if this class is java.lang.Object. |
ClassPoolInfo |
getThisClass()
Accessor for this class. |
java.lang.String |
getThisClassName()
Return the name of this class. |
protected void |
readAttributes(PositionDataInputStream di)
Read class file attributes. |
protected void |
readClassInfo(PositionDataInputStream di)
Read class information. |
protected void |
readConstantPool(PositionDataInputStream di)
Read constant pool. |
protected void |
readFields(PositionDataInputStream di)
Read class file fields. |
protected void |
readHeader(PositionDataInputStream di)
Read a class file header |
protected void |
readInterfaces(PositionDataInputStream di)
Read class file interfaces. |
protected void |
readMethods(PositionDataInputStream di)
Read class file methods. |
void |
setClassAccessFlags(short classAccessFlags)
Mutator for the class access flags. |
void |
setMajorVersion(short majorVersion)
Mutator for the major version |
void |
setMinorVersion(short minorVersion)
Mutator for the minor version |
void |
setSuperClass(ClassPoolInfo cpi)
Mutator for the superclass. |
void |
setThisClass(ClassPoolInfo cpi)
Mutator for the this class. |
java.lang.String |
toString()
Return a human-readable version of this class. |
java.lang.String |
toStringVerbose()
Return a verbose human-readable version of this class. |
java.lang.String |
toStringVerbose(boolean lineNumbers,
boolean PCs)
Return a verbose human-readable version of this class. |
void |
write(java.io.OutputStream out)
Write class file into stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private short _majorVersion
private short _minorVersion
private ConstantPool _constantPool
private short _classAccessFlags
private ClassPoolInfo _thisClass
private ClassPoolInfo _superClass
private java.util.ArrayList<ClassPoolInfo> _interfaces
private java.util.ArrayList<FieldInfo> _fields
private java.util.ArrayList<MethodInfo> _methods
private java.util.ArrayList<AAttributeInfo> _attributes
public static final int ACC_PUBLIC
public static final int ACC_PRIVATE
public static final int ACC_PROTECTED
public static final int ACC_STATIC
public static final int ACC_FINAL
public static final int ACC_SYNCHRONIZED
public static final int ACC_VOLATILE
public static final int ACC_BRIDGE
public static final int ACC_TRANSIENT
public static final int ACC_VARARGS
public static final int ACC_NATIVE
public static final int ACC_INTERFACE
public static final int ACC_ABSTRACT
public static final int ACC_STRICT
public static final int ACC_SYNTHETIC
public static final int ACC_ANNOTATION
public static final int ACC_ENUM
private static final int JAVA_FILE_MAGIC
Constructor Detail |
---|
public ClassFile(short majorVersion, short minorVersion, short classAccessFlags, java.lang.String thisClassName, java.lang.String superClassName)
public ClassFile(java.io.InputStream in) throws java.io.IOException, java.lang.ClassFormatError
in
- input stream with class file
java.io.IOException
java.lang.ClassFormatError
public ClassFile(byte[] b) throws java.io.IOException, java.lang.ClassFormatError
b
- byte array
java.io.IOException
java.lang.ClassFormatError
Method Detail |
---|
protected void readHeader(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
protected void readConstantPool(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
protected void readClassInfo(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
protected void readInterfaces(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
protected void readFields(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
protected void readMethods(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
protected void readAttributes(PositionDataInputStream di) throws java.io.IOException, java.lang.ClassFormatError
di
- stream
java.io.IOException
java.lang.ClassFormatError
public void write(java.io.OutputStream out) throws java.io.IOException
out
- stream
java.io.IOException
public java.lang.String getThisClassName()
public java.lang.String getSuperClassName()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringVerbose()
public java.lang.String toStringVerbose(boolean lineNumbers, boolean PCs)
lineNumbers
- print line numbersPCs
- print PC values
public APoolInfo getConstantPoolItem(int index)
index
- index of the item
public int[] addConstantPoolItems(APoolInfo[] items)
items
- array of new items
public void addAttribute(AAttributeInfo newAttribute)
newAttribute
- new attributepublic AAttributeInfo getAttribute(java.lang.String name)
name
- attribute name
public short getMinorVersion()
public void setMinorVersion(short minorVersion)
minorVersion
- new minor versionpublic short getMajorVersion()
public void setMajorVersion(short majorVersion)
majorVersion
- new major versionpublic short getClassAccessFlags()
public void setClassAccessFlags(short classAccessFlags)
classAccessFlags
- new flagspublic ClassPoolInfo getSuperClass()
public void setSuperClass(ClassPoolInfo cpi)
cpi
- superclass informationpublic ClassPoolInfo getThisClass()
public void setThisClass(ClassPoolInfo cpi)
cpi
- this class informationpublic java.util.ArrayList<ClassPoolInfo> getInterfaces()
public java.util.ArrayList<FieldInfo> getFields()
public java.util.ArrayList<MethodInfo> getMethods()
public java.util.ArrayList<AAttributeInfo> getAttributes()
public ConstantPool getConstantPool()
public int addMethodToConstantPool(java.lang.String className, java.lang.String methodName, java.lang.String methodDescriptor)
className
- class namemethodName
- method namemethodDescriptor
- method descriptor
public int addLongToConstantPool(long value)
value
- constant value
public int addField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldDescriptor, boolean addToFields, short accessFlags)
className
- class namefieldName
- field namefieldDescriptor
- field descriptoraddToFields
- true if a new field should be added to the fields list as wellaccessFlags
- access flags (only if addToFields is true)
public int findMethodInConstantPool(java.lang.String className, java.lang.String methodName, java.lang.String methodDescriptor)
className
- class namemethodName
- method namemethodDescriptor
- method descriptor
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |