javassist.bytecode
public final class ClassFile extends Object
ClassFile
represents a Java .class
file, which
consists of a constant pool, methods, fields, and attributes.
See Also: getClassFile
Constructor Summary | |
---|---|
ClassFile(DataInputStream in)
Constructs a class file from a byte stream. | |
ClassFile(boolean isInterface, String classname, String superclass)
Constructs a class file including no members.
|
Method Summary | |
---|---|
void | addAttribute(AttributeInfo info)
Appends an attribute. |
void | addField(FieldInfo finfo)
Appends a field to the class.
|
void | addInterface(String name)
Appends an interface to the interfaces implemented by the class. |
void | addMethod(MethodInfo minfo)
Appends a method to the class.
|
void | compact()
Eliminates dead constant pool items. |
int | getAccessFlags()
Returns access flags.
|
AttributeInfo | getAttribute(String name)
Returns the attribute with the specified name. |
List | getAttributes()
Returns all the attributes. |
ConstPool | getConstPool()
Returns a constant pool table. |
List | getFields()
Returns all the fields declared in the class.
|
int | getInnerAccessFlags()
Returns access and property flags of this nested class.
|
String[] | getInterfaces()
Returns the names of the interfaces implemented by the class.
|
int | getMajorVersion()
Get the Major version.
|
MethodInfo | getMethod(String name)
Returns the method with the specified name. |
List | getMethods()
Returns all the methods declared in the class.
|
int | getMinorVersion()
Get the minor version.
|
String | getName()
Returns the class name. |
String | getSourceFile()
Returns the source file containing this class.
|
MethodInfo | getStaticInitializer()
Returns a static initializer (class initializer), or null if it does not
exist. |
String | getSuperclass()
Returns the super class name. |
int | getSuperclassId()
Returns the index of the constant pool entry representing the super
class. |
boolean | isAbstract()
Returns true if this is an abstract class or an interface. |
boolean | isFinal()
Returns true if this is a final class or interface. |
boolean | isInterface()
Returns true if this is an interface. |
void | prune()
Discards all attributes, associated with both the class file and the
members such as a code attribute and exceptions attribute. |
void | renameClass(String oldname, String newname)
Replaces all occurrences of a class name in the class file.
|
void | renameClass(Map classnames)
Replaces all occurrences of several class names in the class file.
|
void | setAccessFlags(int acc)
Changes access flags.
|
void | setInterfaces(String[] nameList)
Sets the interfaces.
|
void | setMajorVersion(int major)
Set the major version.
|
void | setMinorVersion(int minor)
Set the minor version.
|
void | setName(String name)
Sets the class name. |
void | setSuperclass(String superclass)
Sets the super class.
|
void | setVersionToJava5()
Sets the major and minor version to Java 5.
|
void | write(DataOutputStream out)
Writes a class file represened by this object into an output stream. |
Parameters: isInterface true if this is an interface. false if this is a class. classname a fully-qualified class name superclass a fully-qualified super class name
See Also: getAttributes
Throws: DuplicateMemberException when the field is already included.
Throws: DuplicateMemberException when the method is already included.
See Also: AccessFlag
Parameters: name attribute name
See Also: getAttributes
List
object
is shared with this object. If you add a new attribute to the list,
the attribute is also added to the classs file represented by this
object. If you remove an attribute from the list, it is also removed
from the class file.
Returns: a list of AttributeInfo
objects.
See Also: AttributeInfo
Returns: a list of FieldInfo
.
See Also: FieldInfo
The returned value is obtained from inner_class_access_flags
of the entry representing this nested class itself
in InnerClasses_attribute
>.
Returns: the major version
Returns: null if no such a method is found.
Returns: a list of MethodInfo
.
See Also: MethodInfo
Returns: the minor version
Returns: null if this information is not available.
If class X is substituted for class Y in the class file, X and Y must have the same signature. If Y provides a method m(), X must provide it even if X inherits m() from the super class. If this fact is not guaranteed, the bytecode verifier may cause an error.
Parameters: oldname the replaced class name newname the substituted class name
Parameters: classnames
specifies which class name is replaced with which new name.
Class names must be described with the JVM-internal
representation like java/lang/Object
.
See Also: renameClass
See Also: AccessFlag
Parameters: nameList the names of the interfaces.
Parameters: major the major version
Parameters: minor the minor version
This method modifies constructors so that they call constructors declared in the new super class.