| Modifier and Type | Field and Description |
|---|---|
static int |
JAVA_1
The major version number of class files
for JDK 1.1.
|
static int |
JAVA_2
The major version number of class files
for JDK 1.2.
|
static int |
JAVA_3
The major version number of class files
for JDK 1.3.
|
static int |
JAVA_4
The major version number of class files
for JDK 1.4.
|
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 |
JAVA_7
The major version number of class files
for JDK 1.7.
|
static int |
MAJOR_VERSION
The major version number of class files created
from scratch.
|
| Constructor and Description |
|---|
ClassFile(boolean isInterface,
String classname,
String superclass)
Constructs a class file including no members.
|
ClassFile(DataInput in)
Constructs a class file from a byte stream.
|
| Modifier and Type | Method and Description |
|---|---|
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)
Just appends a method to the class.
|
void |
compact()
Eliminates dead constant pool items.
|
boolean |
equals(Object obj) |
int |
getAccessFlags()
Returns access flags.
|
Annotation |
getAnnotation(Class<?> annoClass) |
<T extends Annotation> |
getAnnotation(Class<T> annoClass,
ClassLoader loader) |
Annotation |
getAnnotation(String name)
This method is for lazy programmers only;
it checks both runtime and compile annotations.
|
Annotation[] |
getAnnotations() |
AttributeInfo |
getAttribute(String name)
Returns the attribute with the specified name.
|
List<AttributeInfo> |
getAttributes()
Returns all the attributes.
|
Annotation |
getCompileAnnotation(String name)
This method returns any compile annotations on the given classfile.
|
ConstPool |
getConstPool()
Returns a constant pool table.
|
String |
getEnclosedName() |
List<FieldInfo> |
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<MethodInfo> |
getMethods()
Returns all the methods declared in the class.
|
int |
getMinorVersion()
Get the minor version.
|
String |
getName()
Returns the class name.
|
String |
getPackage() |
String |
getQualifiedName() |
String |
getResourceName() |
Annotation |
getRuntimeAnnotation(String name)
This method returns any runtime annotations on the given classfile.
|
String |
getSimpleName() |
String |
getSourceFile()
Returns the source file containing this class.
|
String |
getSuperclass()
Returns the super class name.
|
int |
getSuperclassId()
Returns the index of the constant pool entry representing the super
class.
|
int |
getThisClassIndex() |
boolean |
hasAnnotation(Class<?> annoClass) |
int |
hashCode() |
boolean |
hasSuperClass(String superClass) |
boolean |
isAbstract()
Returns true if this is an abstract class or an interface.
|
boolean |
isClass(String pkg,
String enclosed) |
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(Map<?,?> classnames)
Replaces all occurrences of several class names in the class file.
|
void |
renameClass(String oldname,
String newname)
Replaces all occurrences of a class name 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.
|
String |
toString() |
void |
write(DataOutputStream out)
Writes a class file represented by this object into an output stream.
|
public static final int JAVA_1
public static final int JAVA_2
public static final int JAVA_3
public static final int JAVA_4
public static final int JAVA_5
public static final int JAVA_6
public static final int JAVA_7
public static int MAJOR_VERSION
java.lang.StringBuilder.public ClassFile(DataInput in) throws IOException
IOExceptionpublic ClassFile(boolean isInterface,
String classname,
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 namepublic void compact()
public void prune()
public ConstPool getConstPool()
public boolean isInterface()
public boolean isFinal()
public boolean isAbstract()
public int getAccessFlags()
javassist.bytecode.AccessFlagpublic void setAccessFlags(int acc)
javassist.bytecode.AccessFlagpublic int getInnerAccessFlags()
The returned value is obtained from inner_class_access_flags
of the entry representing this nested class itself
in InnerClasses_attribute>.
public int getThisClassIndex()
public String getName()
public void setName(String name)
public String getSuperclass()
public int getSuperclassId()
public void setSuperclass(String superclass)
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.
public final void renameClass(String oldname, 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(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 String[] getInterfaces()
public void setInterfaces(String[] nameList)
nameList - the names of the interfaces.public void addInterface(String name)
public List<FieldInfo> getFields()
FieldInfo.FieldInfopublic void addField(FieldInfo finfo)
public List<MethodInfo> getMethods()
MethodInfo.MethodInfopublic MethodInfo getMethod(String name)
public final void addMethod(MethodInfo minfo)
public List<AttributeInfo> 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.AttributeInfopublic AttributeInfo getAttribute(String name)
name - attribute namegetAttributes()public void addAttribute(AttributeInfo info)
getAttributes()public String getSourceFile()
public void write(DataOutputStream out) throws IOException
IOExceptionpublic int getMajorVersion()
public void setMajorVersion(int major)
major - the major versionpublic int getMinorVersion()
public void setMinorVersion(int minor)
minor - the minor versionpublic void setVersionToJava5()
public Annotation getAnnotation(String name)
getAnnotation in interface Annotatedname - - The fully qualified annotation namepublic Annotation getAnnotation(Class<?> annoClass)
public boolean hasAnnotation(Class<?> annoClass)
public <T extends Annotation> T getAnnotation(Class<T> annoClass, ClassLoader loader) throws ClassNotFoundException, NoSuchClassError
public Annotation[] getAnnotations()
getAnnotations in interface Annotatedpublic Annotation getRuntimeAnnotation(String name)
name - - The fully qualified annotation namepublic Annotation getCompileAnnotation(String name)
name - - The fully qualified annotation namepublic String getPackage()
public String getEnclosedName()
public String getSimpleName()
public String getQualifiedName()
public String getResourceName()
public boolean hasSuperClass(String superClass)
Copyright © December 07, 2012–2015 The Internet Party. All rights reserved.