org.aspectj.apache.bcel.classfile
Class JavaClass

java.lang.Object
  extended by org.aspectj.apache.bcel.classfile.Modifiers
      extended by org.aspectj.apache.bcel.classfile.JavaClass
All Implemented Interfaces:
java.lang.Cloneable, Node

public class JavaClass
extends Modifiers
implements java.lang.Cloneable, Node

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.

See Also:
ClassGen

Field Summary
 
Fields inherited from class org.aspectj.apache.bcel.classfile.Modifiers
modifiers
 
Constructor Summary
JavaClass(int classnameIndex, int superclassnameIndex, java.lang.String filename, int major, int minor, int access_flags, ConstantPool cpool, int[] interfaces, Field[] fields, Method[] methods, Attribute[] attributes)
           
 
Method Summary
 void accept(ClassVisitor v)
          Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
 void dump(java.io.DataOutputStream file)
          Dump Java class to output stream in binary format.
 void dump(java.io.File file)
          Dump class to a file.
 void dump(java.io.OutputStream file)
          Dump Java class to output stream in binary format.
 void dump(java.lang.String file_name)
          Dump class to a file named file_name.
 java.util.Collection<JavaClass> getAllInterfaces()
          Get all interfaces implemented by this JavaClass (transitively).
 AnnotationGen[] getAnnotations()
           
 Attribute[] getAttributes()
           
 byte[] getBytes()
           
 java.lang.String getClassName()
           
 int getClassNameIndex()
           
 ConstantPool getConstantPool()
           
 Field getField(java.lang.reflect.Field field)
           
 Field[] getFields()
           
 java.lang.String getFileName()
           
 java.lang.String getGenericSignature()
          Hunts for a signature attribute on the member and returns its contents.
 int[] getInterfaceIndices()
           
 java.lang.String[] getInterfaceNames()
           
 JavaClass[] getInterfaces()
          Get interfaces directly implemented by this JavaClass.
 int getMajor()
           
 Method getMethod(java.lang.reflect.Constructor<?> c)
           
 Method getMethod(java.lang.reflect.Method m)
           
 Method[] getMethods()
           
 int getMinor()
           
 java.lang.String getPackageName()
           
 Repository getRepository()
          Gets the ClassRepository which holds its definition.
 Signature getSignatureAttribute()
           
 java.lang.String getSourceFileName()
           
 JavaClass getSuperClass()
           
 JavaClass[] getSuperClasses()
           
 java.lang.String getSuperclassName()
           
 int getSuperclassNameIndex()
           
 boolean implementationOf(JavaClass inter)
           
 boolean instanceOf(JavaClass super_class)
          Equivalent to runtime "instanceof" operator.
 boolean isAnnotation()
          Returns true if this class represents an annotation, i.e.
 boolean isAnonymous()
           
 boolean isClass()
           
 boolean isEnum()
          Returns true if this class represents an enum type
 boolean isGeneric()
           
 boolean isNested()
           
 boolean isSuper()
           
 void setAttributes(Attribute[] attributes)
           
 void setClassName(java.lang.String class_name)
           
 void setClassNameIndex(int class_name_index)
           
 void setConstantPool(ConstantPool constant_pool)
           
 void setFields(Field[] fields)
           
 void setFileName(java.lang.String file_name)
          Set File name of class, aka SourceFile attribute value
 void setInterfaceNames(java.lang.String[] interface_names)
           
 void setInterfaces(int[] interfaces)
           
 void setMajor(int major)
           
 void setMethods(Method[] methods)
           
 void setMinor(int minor)
           
 void setRepository(Repository repository)
          Sets the ClassRepository which loaded the JavaClass.
 void setSourceFileName(java.lang.String source_file_name)
          Set absolute path to file this class was read from.
 void setSuperclassName(java.lang.String superclass_name)
           
 void setSuperclassNameIndex(int superclass_name_index)
           
 java.lang.String toString()
           
 
Methods inherited from class org.aspectj.apache.bcel.classfile.Modifiers
getModifiers, isAbstract, isBridge, isFinal, isInterface, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVarargs, isVolatile, setModifiers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JavaClass

public JavaClass(int classnameIndex,
                 int superclassnameIndex,
                 java.lang.String filename,
                 int major,
                 int minor,
                 int access_flags,
                 ConstantPool cpool,
                 int[] interfaces,
                 Field[] fields,
                 Method[] methods,
                 Attribute[] attributes)
Method Detail

accept

public void accept(ClassVisitor 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.

Specified by:
accept in interface Node
Parameters:
v - Visitor object

dump

public void dump(java.io.File file)
          throws java.io.IOException
Dump class to a file.

Parameters:
file - Output file
Throws:
java.io.IOException

dump

public void dump(java.lang.String file_name)
          throws java.io.IOException
Dump class to a file named file_name.

Parameters:
file_name - Output file name
Throws:
java.io.IOException

getBytes

public byte[] getBytes()
Returns:
class in binary format

dump

public void dump(java.io.OutputStream file)
          throws java.io.IOException
Dump Java class to output stream in binary format.

Throws:
java.io.IOException

dump

public void dump(java.io.DataOutputStream file)
          throws java.io.IOException
Dump Java class to output stream in binary format.

Throws:
java.io.IOException

getAttributes

public Attribute[] getAttributes()

getAnnotations

public AnnotationGen[] getAnnotations()

getClassName

public java.lang.String getClassName()
Returns:
Class name.

getPackageName

public java.lang.String getPackageName()
Returns:
Package name.

getClassNameIndex

public int getClassNameIndex()

getConstantPool

public ConstantPool getConstantPool()

getFields

public Field[] getFields()
Returns:
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 java.lang.String getFileName()
Returns:
File name of class, aka SourceFile attribute value

getInterfaceNames

public java.lang.String[] getInterfaceNames()
Returns:
Names of implemented interfaces.

getInterfaceIndices

public int[] getInterfaceIndices()
Returns:
Indices in constant pool of implemented interfaces.

getMajor

public int getMajor()

getMethods

public Method[] getMethods()
Returns:
Methods of the class.

getMethod

public Method getMethod(java.lang.reflect.Method m)
Returns:
A org.aspectj.apache.bcel.classfile.Method corresponding to java.lang.reflect.Method if any

getMethod

public Method getMethod(java.lang.reflect.Constructor<?> c)

getField

public Field getField(java.lang.reflect.Field field)

getMinor

public int getMinor()
Returns:
Minor number of class file version.

getSourceFileName

public java.lang.String getSourceFileName()
Returns:
sbsolute path to file where this class was read from

getSuperclassName

public java.lang.String getSuperclassName()
Returns:
Superclass name.

getSuperclassNameIndex

public int getSuperclassNameIndex()
Returns:
Class name index.

setAttributes

public void setAttributes(Attribute[] attributes)
Parameters:
attributes - .

setClassName

public void setClassName(java.lang.String class_name)
Parameters:
class_name - .

setClassNameIndex

public void setClassNameIndex(int class_name_index)
Parameters:
class_name_index - .

setConstantPool

public void setConstantPool(ConstantPool constant_pool)
Parameters:
constant_pool - .

setFields

public void setFields(Field[] fields)
Parameters:
fields - .

setFileName

public void setFileName(java.lang.String file_name)
Set File name of class, aka SourceFile attribute value


setInterfaceNames

public void setInterfaceNames(java.lang.String[] interface_names)
Parameters:
interface_names - .

setInterfaces

public void setInterfaces(int[] interfaces)
Parameters:
interfaces - .

setMajor

public void setMajor(int major)

setMethods

public void setMethods(Method[] methods)

setMinor

public void setMinor(int minor)

setSourceFileName

public void setSourceFileName(java.lang.String source_file_name)
Set absolute path to file this class was read from.


setSuperclassName

public void setSuperclassName(java.lang.String superclass_name)
Parameters:
superclass_name - .

setSuperclassNameIndex

public void setSuperclassNameIndex(int superclass_name_index)
Parameters:
superclass_name_index - .

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String representing class contents.

isSuper

public final boolean isSuper()

isClass

public final boolean isClass()

isAnonymous

public final boolean isAnonymous()

isNested

public final boolean isNested()

isAnnotation

public final boolean isAnnotation()
Returns true if this class represents an annotation, i.e. it was a 'public @interface blahblah' declaration


isEnum

public final boolean isEnum()
Returns true if this class represents an enum type


getRepository

public Repository getRepository()
Gets the ClassRepository which holds its definition. By default this is the same as SyntheticRepository.getInstance();


setRepository

public void setRepository(Repository repository)
Sets the ClassRepository which loaded the JavaClass. Should be called immediately after parsing is done.


instanceOf

public final boolean instanceOf(JavaClass super_class)
Equivalent to runtime "instanceof" operator.

Returns:
true if this JavaClass is derived from teh super class

implementationOf

public boolean implementationOf(JavaClass inter)
Returns:
true, if clazz is an implementation of interface inter

getSuperClass

public JavaClass getSuperClass()
Returns:
the superclass for this JavaClass object, or null if this is java.lang.Object

getSuperClasses

public JavaClass[] getSuperClasses()
Returns:
list of super classes of this class in ascending order, i.e., java.lang.Object is always the last element

getInterfaces

public JavaClass[] getInterfaces()
Get interfaces directly implemented by this JavaClass.


getAllInterfaces

public java.util.Collection<JavaClass> getAllInterfaces()
Get all interfaces implemented by this JavaClass (transitively).


getGenericSignature

public final java.lang.String getGenericSignature()
Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature may be Ljava/util/Vector; the signature attribute will tell us e.g. "Ljava/lang/Object". We can learn the type variable names, their bounds, and the true superclass and superinterface types (including any parameterizations) Coded for performance - searches for the attribute only when requested - only searches for it once.


isGeneric

public boolean isGeneric()

getSignatureAttribute

public final Signature getSignatureAttribute()