public class ClassFile extends java.lang.Object implements ClassInfo
| Constructor and Description |
|---|
ClassFile(java.io.File file,
ClassInfoLoader loader,
java.io.DataInputStream in)
Constructor.
|
ClassFile(int modifiers,
int classIndex,
int superClassIndex,
int[] interfaceIndexes,
java.util.List constants,
ClassInfoLoader loader)
Creates a new
ClassFile from scratch. |
| Modifier and Type | Method and Description |
|---|---|
FieldInfo |
addNewField(int modifiers,
int typeIndex,
int nameIndex)
Creates a new field in this classfile
|
FieldInfo |
addNewField(int modifiers,
int typeIndex,
int nameIndex,
int cvNameIndex,
int constantValueIndex)
Creates a new field in this classfile
|
MethodInfo |
addNewMethod(int modifiers,
int typeIndex,
int nameIndex,
int exceptionIndex,
int[] exceptionTypeIndices,
int codeIndex)
Creates a new method in this class
|
int |
classIndex()
Get the index into the constant pool of the name of the class.
|
void |
commit()
Commit any changes back to a file in the output directory.
|
void |
commitOnly(java.util.Set methods,
java.util.Set fields)
Commits only certain methods and fields.
|
Constant[] |
constants()
Get an array of the constants in the constant pool.
|
void |
deleteField(int nameIndex)
Removes the field whose name is at the given index in the constant pool.
|
void |
deleteMethod(int nameIndex,
int typeIndex)
Deletes a method from this class
|
FieldInfo[] |
fields()
Get an array of FieldInfo structures for each field in the class.
|
java.io.File |
file()
Returns the File from which this
ClassFile was created. |
int[] |
interfaceIndices()
Get the indices into the constant pool of the names of the class's
interfaces.
|
ClassInfoLoader |
loader()
Get the class info loader for the class.
|
MethodInfo[] |
methods()
Returns an array of MethodInfo structures for each method in the class.
|
int |
modifiers()
Get the modifiers of the class.
|
java.lang.String |
name()
Get the name of the class, including the package name.
|
java.io.File |
outputFile()
Creates a new File object to hold this class.
|
void |
print(java.io.PrintStream out)
Prints a textual representation of this classfile to a PrintStream.
|
void |
print(java.io.PrintWriter out) |
void |
setClassIndex(int index)
Set the index into the constant pool of the name of the class.
|
void |
setConstants(Constant[] constants)
Set all the constants in the constant pool.
|
void |
setInterfaceIndices(int[] indices)
Set the indices into the constant pool of the names of the class's
interfaces.
|
void |
setMethods(MethodInfo[] methods)
Sets the methods in this class.
|
void |
setModifiers(int modifiers)
Set the modifiers of the class.
|
void |
setSuperclassIndex(int index)
Set the index into the constant pool of the name of the class's
superclass.
|
int |
superclassIndex()
Get the index into the constant pool of the name of the class's
superclass.
|
java.lang.String |
toString() |
public ClassFile(java.io.File file,
ClassInfoLoader loader,
java.io.DataInputStream in)
file - The file in which the class resides.loader - The class info loader which loaded the class.in - The data stream containing the class.java.lang.ClassFormatError - When the class could not be parsed.public ClassFile(int modifiers,
int classIndex,
int superClassIndex,
int[] interfaceIndexes,
java.util.List constants,
ClassInfoLoader loader)
ClassFile from scratch. It has no fields or
methods.modifiers - The modifiers describing the newly-created classclassIndex - The index of the type of the newly-created class in its
constant poolsuperClassIndex - The index of the type of the newly-created class's superclass
in its constant poolinterfaceIndexes - The indexes of the types of the interfaces that the
newly-created class implementsconstants - The constant pool for the newly created class (a list of
Constants).public ClassInfoLoader loader()
public java.lang.String name()
public void setClassIndex(int index)
setClassIndex in interface ClassInfoindex - The index of the name of the class.public void setSuperclassIndex(int index)
setSuperclassIndex in interface ClassInfoindex - The index of the name of the superclass.public void setInterfaceIndices(int[] indices)
setInterfaceIndices in interface ClassInfoindices - The indices of the names of the interfaces.public int classIndex()
classIndex in interface ClassInfopublic int superclassIndex()
superclassIndex in interface ClassInfopublic int[] interfaceIndices()
interfaceIndices in interface ClassInfopublic void setModifiers(int modifiers)
setModifiers in interface ClassInfomodifiers - A bit vector of modifier flags for the class.Modifierspublic int modifiers()
public FieldInfo[] fields()
public MethodInfo[] methods()
public void setMethods(MethodInfo[] methods)
setMethods in interface ClassInfopublic Constant[] constants()
public void setConstants(Constant[] constants)
setConstants in interface ClassInfoconstants - The array of Constants.Constantpublic java.io.File file()
ClassFile was created. If
this ClassFile was created from scratch, null
is returned.public java.io.File outputFile()
public void commit()
public void commitOnly(java.util.Set methods,
java.util.Set fields)
ClassInfocommitOnly in interface ClassInfomethods - Methods (MethodInfos) to commit. If null,
all methods are committed.fields - Fields (FieldInfos) to commit. If null,
all fields are committed.public FieldInfo addNewField(int modifiers, int typeIndex, int nameIndex)
addNewField in interface ClassInfopublic FieldInfo addNewField(int modifiers, int typeIndex, int nameIndex, int cvNameIndex, int constantValueIndex)
addNewField in interface ClassInfocvNameIndex - The index in the class's constant pool for the UTF8 constant
"ConstantValue"constantValueIndex - The index in the class's constant pool for the constant valuepublic void deleteField(int nameIndex)
deleteField in interface ClassInfonameIndex - Index in the constant pool of the name of the field to be
deletedjava.lang.IllegalArgumentException - The class does not contain a field whose
name is at the given indexpublic void deleteMethod(int nameIndex,
int typeIndex)
deleteMethod in interface ClassInfonameIndex - Index in the constant pool of the name of the method to be
deletedtypeIndex - Index in the constant pool of the type of the method to be
deletedjava.lang.IllegalArgumentException - The class modeled by this
ClassInfo does not contain a method whose name and
type are not at the given indicespublic MethodInfo addNewMethod(int modifiers, int typeIndex, int nameIndex, int exceptionIndex, int[] exceptionTypeIndices, int codeIndex)
addNewMethod in interface ClassInfomodifiers - The modifiers
for the new methodtypeIndex - The index of the type (conglomeration of the parameter types
and the return type) for this method in the class's constant
poolnameIndex - The index of the name of the method in the class's constant
poolexceptionIndex - The index of the UTF8 string "Exceptions" in the class's
constant poolexceptionTypeIndices - The indices in the class's constant pool of the type of the
exceptions thrown by this methodcodeIndex - The index of the UTF8 string "Code" in the class's constant
poolpublic void print(java.io.PrintStream out)