|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavassist.bytecode.ClassFile
public final class ClassFile
ClassFile
represents a Java .class
file, which
consists of a constant pool, methods, fields, and attributes.
CtClass.getClassFile()
Field Summary | |
---|---|
static int |
JAVA_3
The major version number of class files for JDK 1.3. |
static int |
JAVA_5
The major version number of class files for JDK 1.5. |
static int |
JAVA_6
The major version number of class files for JDK 1.6. |
static int |
MAJOR_VERSION
The major version number of class files created from scratch. |
Constructor Summary | |
---|---|
ClassFile(boolean isInterface,
java.lang.String classname,
java.lang.String superclass)
Constructs a class file including no members. |
|
ClassFile(java.io.DataInputStream in)
Constructs a class file from a byte stream. |
Method Summary | |
---|---|
void |
addAttribute(AttributeInfo info)
Appends an attribute. |
void |
addField(FieldInfo finfo)
Appends a field to the class. |
void |
addInterface(java.lang.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(java.lang.String name)
Returns the attribute with the specified name. |
java.util.List |
getAttributes()
Returns all the attributes. |
ConstPool |
getConstPool()
Returns a constant pool table. |
java.util.List |
getFields()
Returns all the fields declared in the class. |
int |
getInnerAccessFlags()
Returns access and property flags of this nested class. |
java.lang.String[] |
getInterfaces()
Returns the names of the interfaces implemented by the class. |
int |
getMajorVersion()
Get the Major version. |
MethodInfo |
getMethod(java.lang.String name)
Returns the method with the specified name. |
java.util.List |
getMethods()
Returns all the methods declared in the class. |
int |
getMinorVersion()
Get the minor version. |
java.lang.String |
getName()
Returns the class name. |
java.lang.String |
getSourceFile()
Returns the source file containing this class. |
MethodInfo |
getStaticInitializer()
Returns a static initializer (class initializer), or null if it does not exist. |
java.lang.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(java.util.Map classnames)
Replaces all occurrences of several class names in the class file. |
void |
renameClass(java.lang.String oldname,
java.lang.String newname)
Replaces all occurrences of a class name in the class file. |
void |
setAccessFlags(int acc)
Changes access flags. |
void |
setInterfaces(java.lang.String[] nameList)
Sets the interfaces. |
void |
setMajorVersion(int major)
Set the major version. |
void |
setMinorVersion(int minor)
Set the minor version. |
void |
setName(java.lang.String name)
Sets the class name. |
void |
setSuperclass(java.lang.String superclass)
Sets the super class. |
void |
setVersionToJava5()
Sets the major and minor version to Java 5. |
void |
write(java.io.DataOutputStream out)
Writes a class file represened by this object into an output stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int JAVA_3
public static final int JAVA_5
public static final int JAVA_6
public static int MAJOR_VERSION
java.lang.StringBuilder
.
Constructor Detail |
---|
public ClassFile(java.io.DataInputStream in) throws java.io.IOException
java.io.IOException
public ClassFile(boolean isInterface, java.lang.String classname, java.lang.String superclass)
isInterface
- true if this is an interface. false if this is a class.classname
- a fully-qualified class namesuperclass
- a fully-qualified super class nameMethod Detail |
---|
public void compact()
public void prune()
public ConstPool getConstPool()
public boolean isInterface()
public boolean isFinal()
public boolean isAbstract()
public int getAccessFlags()
AccessFlag
public void setAccessFlags(int acc)
AccessFlag
public int getInnerAccessFlags()
The returned value is obtained from inner_class_access_flags
of the entry representing this nested class itself
in InnerClasses_attribute
>.
public java.lang.String getName()
public void setName(java.lang.String name)
public java.lang.String getSuperclass()
public int getSuperclassId()
public void setSuperclass(java.lang.String superclass) throws CannotCompileException
The new super class should inherit from the old super class. This method modifies constructors so that they call constructors declared in the new super class.
CannotCompileException
public final void renameClass(java.lang.String oldname, java.lang.String newname)
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.
oldname
- the replaced class namenewname
- the substituted class namepublic final void renameClass(java.util.Map classnames)
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
.renameClass(String,String)
public java.lang.String[] getInterfaces()
public void setInterfaces(java.lang.String[] nameList)
nameList
- the names of the interfaces.public void addInterface(java.lang.String name)
public java.util.List getFields()
FieldInfo
.FieldInfo
public void addField(FieldInfo finfo) throws DuplicateMemberException
DuplicateMemberException
- when the field is already included.public java.util.List getMethods()
MethodInfo
.MethodInfo
public MethodInfo getMethod(java.lang.String name)
public MethodInfo getStaticInitializer()
public void addMethod(MethodInfo minfo) throws DuplicateMemberException
DuplicateMemberException
- when the method is already included.public java.util.List 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.
AttributeInfo
objects.AttributeInfo
public AttributeInfo getAttribute(java.lang.String name)
name
- attribute namegetAttributes()
public void addAttribute(AttributeInfo info)
getAttributes()
public java.lang.String getSourceFile()
public void write(java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public int getMajorVersion()
public void setMajorVersion(int major)
major
- the major versionpublic int getMinorVersion()
public void setMinorVersion(int minor)
minor
- the minor versionpublic void setVersionToJava5()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |