Represents a Java class, i.e., the data structures, constant pool,
fields, methods and commands contained in a Java .class file.
See
JVM specification for details.
The intent of this class is to represent a parsed or otherwise existing
class file. Those interested in programatically generating classes
should see the
ClassGen class.
FILE
public static final byte FILE
HEAP
public static final byte HEAP
ZIP
public static final byte ZIP
class_name
private String class_name
class_name_index
private int class_name_index
debug
(package private) static boolean debug
fields
private Field[] fields
file_name
private String file_name
interface_names
private String[] interface_names
interfaces
private int[] interfaces
methods
private Method[] methods
package_name
private String package_name
repository
private Repository repository
In cases where we go ahead and create something,
use the default SyntheticRepository, because we
don't know any better.
sep
(package private) static char sep
source
private byte source
source_file_name
private String source_file_name
superclass_name
private String superclass_name
superclass_name_index
private int superclass_name_index
JavaClass
public JavaClass(int class_name_index,
int superclass_name_index,
String file_name,
int major,
int minor,
int access_flags,
ConstantPool constant_pool,
int[] interfaces,
Field[] fields,
Method[] methods,
Attribute[] attributes)
Constructor gets all contents as arguments.
class_name_index
- Class namesuperclass_name_index
- Superclass namefile_name
- File namemajor
- Major compiler versionminor
- Minor compiler versionaccess_flags
- Access rights defined by bit flagsconstant_pool
- Array of constantsinterfaces
- Implemented interfacesfields
- Class fieldsmethods
- Class methodsattributes
- Class attributes
JavaClass
public JavaClass(int class_name_index,
int superclass_name_index,
String file_name,
int major,
int minor,
int access_flags,
ConstantPool constant_pool,
int[] interfaces,
Field[] fields,
Method[] methods,
Attribute[] attributes,
byte source)
Constructor gets all contents as arguments.
class_name_index
- Index into constant pool referencing a
ConstantClass that represents this class.superclass_name_index
- Index into constant pool referencing a
ConstantClass that represents this class's superclass.file_name
- File namemajor
- Major compiler versionminor
- Minor compiler versionaccess_flags
- Access rights defined by bit flagsconstant_pool
- Array of constantsinterfaces
- Implemented interfacesfields
- Class fieldsmethods
- Class methodsattributes
- Class attributessource
- Read from file or generated in memory?
Debug
(package private) static final void Debug(String str)
accept
public void accept(Visitor v)
Called by objects that are traversing the nodes of the tree implicitely
defined by the contents of a Java class. I.e., the hierarchy of methods,
fields, attributes, etc. spawns a tree of objects.
- accept in interface Node
compareTo
public int compareTo(Object obj)
Return the natural ordering of two JavaClasses.
This ordering is based on the class name
dump
public void dump(DataOutputStream file)
throws IOException
Dump Java class to output stream in binary format.
dump
public void dump(File file)
throws IOException
Dump class to a file.
dump
public void dump(OutputStream file)
throws IOException
Dump Java class to output stream in binary format.
dump
public void dump(String _file_name)
throws IOException
Dump class to a file named file_name.
_file_name
- Output file name
equals
public boolean equals(Object obj)
Return value as defined by given BCELComparator strategy.
By default two JavaClass objects are said to be equal when
their class names are equal.
java.lang.Object.equals(java.lang.Object)
getAllInterfaces
public JavaClass[] getAllInterfaces()
throws ClassNotFoundException
Get all interfaces implemented by this JavaClass (transitively).
getAttributes
public Attribute[] getAttributes()
getBytes
public byte[] getBytes()
getClassName
public String getClassName()
getClassNameIndex
public int getClassNameIndex()
getComparator
public static BCELComparator getComparator()
- Comparison strategy object
getFields
public Field[] getFields()
- Fields, i.e., variables of the class. Like the JVM spec
mandates for the classfile format, these fields are those specific to
this class, and not those of the superclass or superinterfaces.
getFileName
public String getFileName()
- File name of class, aka SourceFile attribute value
getInterfaceIndices
public int[] getInterfaceIndices()
- Indices in constant pool of implemented interfaces.
getInterfaceNames
public String[] getInterfaceNames()
- Names of implemented interfaces.
getInterfaces
public JavaClass[] getInterfaces()
throws ClassNotFoundException
Get interfaces directly implemented by this JavaClass.
getMajor
public int getMajor()
- Major number of class file version.
getMethod
public Method getMethod(java.lang.reflect.Method m)
- A org.apache.bcel.classfile.Method corresponding to
java.lang.reflect.Method if any
getMethods
public Method[] getMethods()
getMinor
public int getMinor()
- Minor number of class file version.
getPackageName
public String getPackageName()
getRepository
public Repository getRepository()
Gets the ClassRepository which holds its definition. By default
this is the same as SyntheticRepository.getInstance();
getSource
public final byte getSource()
- returns either HEAP (generated), FILE, or ZIP
getSourceFileName
public String getSourceFileName()
- sbsolute path to file where this class was read from
getSuperClass
public JavaClass getSuperClass()
throws ClassNotFoundException
- the superclass for this JavaClass object, or null if this
is java.lang.Object
getSuperClasses
public JavaClass[] getSuperClasses()
throws ClassNotFoundException
- list of super classes of this class in ascending order, i.e.,
java.lang.Object is always the last element
getSuperclassName
public String getSuperclassName()
getSuperclassNameIndex
public int getSuperclassNameIndex()
hashCode
public int hashCode()
Return value as defined by given BCELComparator strategy.
By default return the hashcode of the class name.
java.lang.Object.hashCode()
implementationOf
public boolean implementationOf(JavaClass inter)
throws ClassNotFoundException
- true, if this class is an implementation of interface inter
indent
private static final String indent(Object obj)
instanceOf
public final boolean instanceOf(JavaClass super_class)
throws ClassNotFoundException
Equivalent to runtime "instanceof" operator.
- true if this JavaClass is derived from the super class
isClass
public final boolean isClass()
isSuper
public final boolean isSuper()
setAttributes
public void setAttributes(Attribute[] attributes)
setClassName
public void setClassName(String class_name)
setClassNameIndex
public void setClassNameIndex(int class_name_index)
setComparator
public static void setComparator(BCELComparator comparator)
comparator
- Comparison strategy object
setConstantPool
public void setConstantPool(ConstantPool constant_pool)
setFields
public void setFields(Field[] fields)
setFileName
public void setFileName(String file_name)
Set File name of class, aka SourceFile attribute value
setInterfaceNames
public void setInterfaceNames(String[] interface_names)
setInterfaces
public void setInterfaces(int[] interfaces)
setMajor
public void setMajor(int major)
setMethods
public void setMethods(Method[] methods)
setMinor
public void setMinor(int minor)
setRepository
public void setRepository(Repository repository)
Sets the ClassRepository which loaded the JavaClass.
Should be called immediately after parsing is done.
setSourceFileName
public void setSourceFileName(String source_file_name)
Set absolute path to file this class was read from.
setSuperclassName
public void setSuperclassName(String superclass_name)
setSuperclassNameIndex
public void setSuperclassNameIndex(int superclass_name_index)
superclass_name_index
- .
toString
public String toString()
- String representing class contents.