|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.go.trove.classfile.ClassFile
A class used to create Java class files. Call the writeTo method to produce a class file.
See The Java Virtual Machine Specification (ISBN 0-201-63452-X) for information on how class files are structured. Section 4.1 describes the ClassFile structure.
| Constructor Summary | |
ClassFile(java.lang.String className)
By default, the ClassFile defines public, non-final, concrete classes. |
|
ClassFile(java.lang.String className,
java.lang.Class superClass)
By default, the ClassFile defines public, non-final, concrete classes. |
|
ClassFile(java.lang.String className,
java.lang.String superClassName)
By default, the ClassFile defines public, non-final, concrete classes. |
|
| Method Summary | |
void |
addAttribute(Attribute attr)
Add an attribute to this class. |
MethodInfo |
addConstructor(AccessFlags flags,
TypeDescriptor[] params)
Add a constructor to this class. |
FieldInfo |
addField(AccessFlags flags,
java.lang.String fieldName,
TypeDescriptor type)
Add a field to this class. |
MethodInfo |
addInitializer()
Add a static initializer to this class. |
ClassFile |
addInnerClass(java.lang.String innerClassName)
Add an inner class to this class. |
ClassFile |
addInnerClass(java.lang.String innerClassName,
java.lang.Class superClass)
Add an inner class to this class. |
ClassFile |
addInnerClass(java.lang.String innerClassName,
java.lang.String superClassName)
Add an inner class to this class. |
void |
addInterface(java.lang.Class i)
Add an interface that this class implements. |
void |
addInterface(java.lang.String interfaceName)
Add an interface that this class implements. |
MethodInfo |
addMethod(AccessFlags flags,
java.lang.String methodName,
MethodDescriptor md)
Add a method to this class. |
MethodInfo |
addMethod(AccessFlags flags,
java.lang.String methodName,
TypeDescriptor ret,
TypeDescriptor[] params)
Add a method to this class. |
MethodInfo |
addMethod(java.lang.reflect.Method method)
Add a method to this class. |
AccessFlags |
getAccessFlags()
|
Attribute[] |
getAttributes()
|
int |
getClassDepth()
Returns a value indicating how deeply nested an inner class is with respect to its outermost enclosing class. |
java.lang.String |
getClassName()
|
ConstantPool |
getConstantPool()
Provides access to the ClassFile's ContantPool. |
MethodInfo[] |
getConstructors()
Returns all the constructors defined in this class. |
FieldInfo[] |
getFields()
Returns all the fields defined in this class. |
MethodInfo |
getInitializer()
Returns the static initializer defined in this class or null if there isn't one. |
ClassFile[] |
getInnerClasses()
Returns all the inner classes defined in this class. |
java.lang.String |
getInnerClassName()
If this ClassFile represents a non-anonymous inner class, returns its short inner class name. |
java.lang.String[] |
getInterfaces()
Returns the names of all the interfaces that this class implements. |
MethodInfo[] |
getMethods()
Returns all the methods defined in this class, not including constructors and static initializers. |
ClassFile |
getOuterClass()
Returns null if this ClassFile does not represent an inner class. |
java.lang.String |
getSourceFile()
Returns the source file of this class file or null if not set. |
java.lang.String |
getSuperClassName()
|
TypeDescriptor |
getType()
Returns a TypeDescriptor for the type of this ClassFile. |
boolean |
isDeprecated()
|
boolean |
isInnerClass()
Returns true if this ClassFile represents an inner class. |
boolean |
isSynthetic()
|
void |
markDeprecated()
Mark this class as being deprecated by adding a special attribute. |
void |
markSynthetic()
Mark this class as being synthetic by adding a special attribute. |
static ClassFile |
readFrom(java.io.DataInput din)
Reads a ClassFile from the given DataInput. |
static ClassFile |
readFrom(java.io.DataInput din,
ClassFileDataLoader loader,
AttributeFactory attrFactory)
Reads a ClassFile from the given DataInput. |
static ClassFile |
readFrom(java.io.InputStream in)
Reads a ClassFile from the given InputStream. |
static ClassFile |
readFrom(java.io.InputStream in,
ClassFileDataLoader loader,
AttributeFactory attrFactory)
Reads a ClassFile from the given InputStream. |
void |
setSourceFile(java.lang.String fileName)
Set the source file of this class file by adding a source file attribute. |
void |
setVersion(int major,
int minor)
Sets the version to use when writing the generated ClassFile. |
void |
writeTo(java.io.DataOutput dout)
Writes the ClassFile to the given DataOutput. |
void |
writeTo(java.io.OutputStream out)
Writes the ClassFile to the given OutputStream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ClassFile(java.lang.String className)
Use the access flags to change the default
modifiers for this class or to turn it into an interface.
className - Full class name of the form ex: "java.lang.String".
public ClassFile(java.lang.String className,
java.lang.Class superClass)
Use the access flags to change the default
modifiers for this class or to turn it into an interface.
className - Full class name of the form ex: "java.lang.String".superClass - Super class.
public ClassFile(java.lang.String className,
java.lang.String superClassName)
Use the access flags to change the default
modifiers for this class or to turn it into an interface.
className - Full class name of the form ex: "java.lang.String".superClassName - Full super class name.| Method Detail |
public java.lang.String getClassName()
public java.lang.String getSuperClassName()
public TypeDescriptor getType()
public AccessFlags getAccessFlags()
public java.lang.String[] getInterfaces()
public FieldInfo[] getFields()
public MethodInfo[] getMethods()
public MethodInfo[] getConstructors()
public MethodInfo getInitializer()
public ClassFile[] getInnerClasses()
public boolean isInnerClass()
public java.lang.String getInnerClassName()
public ClassFile getOuterClass()
isInnerClass()public int getClassDepth()
public java.lang.String getSourceFile()
public boolean isSynthetic()
public boolean isDeprecated()
public ConstantPool getConstantPool()
public void addInterface(java.lang.String interfaceName)
interfaceName - Full interface name.public void addInterface(java.lang.Class i)
public FieldInfo addField(AccessFlags flags,
java.lang.String fieldName,
TypeDescriptor type)
public MethodInfo addMethod(AccessFlags flags,
java.lang.String methodName,
TypeDescriptor ret,
TypeDescriptor[] params)
ret - Is null if method returns void.params - May be null if method accepts no parameters.
public MethodInfo addMethod(AccessFlags flags,
java.lang.String methodName,
MethodDescriptor md)
public MethodInfo addMethod(java.lang.reflect.Method method)
public MethodInfo addConstructor(AccessFlags flags,
TypeDescriptor[] params)
params - May be null if constructor accepts no parameters.public MethodInfo addInitializer()
public ClassFile addInnerClass(java.lang.String innerClassName)
innerClassName - Optional short inner class name.
public ClassFile addInnerClass(java.lang.String innerClassName,
java.lang.Class superClass)
innerClassName - Optional short inner class name.superClass - Super class.
public ClassFile addInnerClass(java.lang.String innerClassName,
java.lang.String superClassName)
innerClassName - Optional short inner class name.superClassName - Full super class name.isStatic - True specifies a static inner class.public void setSourceFile(java.lang.String fileName)
public void markSynthetic()
public void markDeprecated()
public void addAttribute(Attribute attr)
public Attribute[] getAttributes()
public void setVersion(int major,
int minor)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - when the version isn't supported
public void writeTo(java.io.OutputStream out)
throws java.io.IOException
public void writeTo(java.io.DataOutput dout)
throws java.io.IOException
public static ClassFile readFrom(java.io.InputStream in)
throws java.io.IOException
in - source of class file datajava.io.IOException - for I/O error or if classfile is invalid.java.lang.ArrayIndexOutOfBoundsException - if a constant pool index is out
of range.java.lang.ClassCastException - if a constant pool index references the
wrong type.
public static ClassFile readFrom(java.io.DataInput din)
throws java.io.IOException
din - source of class file datajava.io.IOException - for I/O error or if classfile is invalid.java.lang.ArrayIndexOutOfBoundsException - if a constant pool index is out
of range.java.lang.ClassCastException - if a constant pool index references the
wrong type.
public static ClassFile readFrom(java.io.InputStream in,
ClassFileDataLoader loader,
AttributeFactory attrFactory)
throws java.io.IOException
ClassFileDataLoader may be provided, which allows inner class
definitions to be loaded. Also, an AttributeFactory may be
provided, which allows non-standard attributes to be read. All
remaining unknown attribute types are captured, but are not decoded.in - source of class file dataloader - optional loader for reading inner class definitionsattrFactory - optional factory for reading custom attributesjava.io.IOException - for I/O error or if classfile is invalid.java.lang.ArrayIndexOutOfBoundsException - if a constant pool index is out
of range.java.lang.ClassCastException - if a constant pool index references the
wrong type.
public static ClassFile readFrom(java.io.DataInput din,
ClassFileDataLoader loader,
AttributeFactory attrFactory)
throws java.io.IOException
ClassFileDataLoader may be provided, which allows inner class
definitions to be loaded. Also, an AttributeFactory may be
provided, which allows non-standard attributes to be read. All
remaining unknown attribute types are captured, but are not decoded.din - source of class file dataloader - optional loader for reading inner class definitionsattrFactory - optional factory for reading custom attributesjava.io.IOException - for I/O error or if classfile is invalid.java.lang.ArrayIndexOutOfBoundsException - if a constant pool index is out
of range.java.lang.ClassCastException - if a constant pool index references the
wrong type.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||