Top Description Fields Constructors Methods
org.aspectj.apache.bcel.classfile

public Class JavaClass

extends Modifiers
implements Cloneable, Node
Class Inheritance
All Implemented Interfaces
org.aspectj.apache.bcel.classfile.Node, java.lang.Cloneable
Imports
java.io.ByteArrayOutputStream, .DataOutputStream, .File, .FileOutputStream, .IOException, .OutputStream, java.util.ArrayList, .Collection, .Collections, .LinkedList, .List, .Queue, .StringTokenizer, org.aspectj.apache.bcel.Constants, org.aspectj.apache.bcel.classfile.annotation.AnnotationGen, .RuntimeAnnos, org.aspectj.apache.bcel.generic.Type, org.aspectj.apache.bcel.util.SyntheticRepository

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.
Author
M. Dahm
Version
$Id: JavaClass.java,v 1.22 2009/09/15 19:40:14 aclement Exp $
See Also
org.aspectj.apache.bcel.generic.ClassGen

Field Summary

Modifier and TypeField and Description
private AnnotationGen[]
private boolean
private Attribute[]
private String
private int
private boolean
private ConstantPool
private Field[]
private String
private String[]
private int[]
private boolean
private boolean
private boolean
private int
private Method[]
private int
private static final int[]
private static final String[]
private String
private transient Repository
repository

In cases where we go ahead and create something, use the default SyntheticRepository, because we don't know any better.

private boolean
private Signature
private String
private String
private String
private int
Inherited from org.aspectj.apache.bcel.classfile.Modifiers:
modifiers

Constructor Summary

AccessConstructor and Description
public
JavaClass(int classnameIndex, int superclassnameIndex, String filename, int major, int minor, int access_flags, ConstantPool cpool, int[] interfaces, Field[] fields, Method[] methods, Attribute[] attributes)

Method Summary

Modifier and TypeMethod and Description
public void
accept(ClassVisitor
Visitor object
v
)

Implements org.aspectj.apache.bcel.classfile.Node.accept.

Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
private final void
public void
dump(File
Output file
file
)

Dump class to a file.

public void
dump(String
Output file name
file_name
)

Dump class to a file named file_name.

public void
dump(OutputStream file)

Dump Java class to output stream in binary format.

public void
dump(DataOutputStream file)

Dump Java class to output stream in binary format.

public Collection<JavaClass>
getAllInterfaces()

Get all interfaces implemented by this JavaClass (transitively).

public AnnotationGen[]
public Attribute[]
public byte[]

Returns:

class in binary format
getBytes
()

public String

Returns:

Class name.
getClassName
()

public int
public ConstantPool
public Field
getField(Field field)

public Field[]

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.
getFields
()

public String

Returns:

File name of class, aka SourceFile attribute value
getFileName
()

public final String
getGenericSignature()

Hunts for a signature attribute on the member and returns its contents.

public int[]

Returns:

Indices in constant pool of implemented interfaces.
getInterfaceIndices
()

public String[]

Returns:

Names of implemented interfaces.
getInterfaceNames
()

public JavaClass[]
getInterfaces()

Get interfaces directly implemented by this JavaClass.

public int
public Method

Returns:

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

public Method
public Method[]

Returns:

Methods of the class.
getMethods
()

public int

Returns:

Minor number of class file version.
getMinor
()

public String

Returns:

Package name.
getPackageName
()

public Repository
getRepository()

Gets the ClassRepository which holds its definition.

public final Signature
public String

Returns:

sbsolute path to file where this class was read from
getSourceFileName
()

public JavaClass

Returns:

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

public JavaClass[]

Returns:

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

public String

Returns:

Superclass name.
getSuperclassName
()

public int

Returns:

Class name index.
getSuperclassNameIndex
()

public boolean

Returns:

true, if clazz is an implementation of interface inter
implementationOf
(JavaClass inter)

private static final String
public final boolean

Returns:

true if this JavaClass is derived from teh super class
instanceOf
(JavaClass super_class)

Equivalent to runtime "instanceof" operator.

public final boolean
isAnnotation()

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

public final boolean
public final boolean
public final boolean
isEnum()

Returns true if this class represents an enum type

public boolean
public final boolean
public final boolean
private void
public void
setAttributes(Attribute[]
.
attributes
)

public void
setClassName(String
.
class_name
)

public void
setClassNameIndex(int
.
class_name_index
)

public void
setConstantPool(ConstantPool
.
constant_pool
)

public void
setFields(Field[]
.
fields
)

public void
setFileName(String file_name)

Set File name of class, aka SourceFile attribute value

public void
setInterfaceNames(String[]
.
interface_names
)

public void
setInterfaces(int[]
.
interfaces
)

public void
setMajor(int major)

public void
setMethods(Method[] methods)

public void
setMinor(int minor)

public void
setRepository(Repository repository)

Sets the ClassRepository which loaded the JavaClass.

public void
setSourceFileName(String source_file_name)

Set absolute path to file this class was read from.

public void
setSuperclassName(String
.
superclass_name
)

public void
setSuperclassNameIndex(int
.
superclass_name_index
)

public String

Returns:

String representing class contents.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.aspectj.apache.bcel.classfile.Modifiers:
getModifiersisAbstractisBridgeisFinalisInterfaceisNativeisPrivateisProtectedisPublicisStaticisStrictfpisSynchronizedisTransientisVarargsisVolatilesetModifiers

Field Detail

annotationsback to summary
private AnnotationGen[] annotations
annotationsOutOfDateback to summary
private boolean annotationsOutOfDate
attributesback to summary
private Attribute[] attributes
classnameback to summary
private String classname
classnameIdxback to summary
private int classnameIdx
computedNestedTypeStatusback to summary
private boolean computedNestedTypeStatus
cpoolback to summary
private ConstantPool cpool
fieldsback to summary
private Field[] fields
fileNameback to summary
private String fileName
interfacenamesback to summary
private String[] interfacenames
interfacesback to summary
private int[] interfaces
isAnonymousback to summary
private boolean isAnonymous
isGenericback to summary
private boolean isGeneric
isNestedback to summary
private boolean isNested
majorback to summary
private int major
methodsback to summary
private Method[] methods
minorback to summary
private int minor
NoInterfaceIndicesback to summary
private static final int[] NoInterfaceIndices
NoInterfaceNamesback to summary
private static final String[] NoInterfaceNames
packageNameback to summary
private String packageName
repositoryback to summary
private transient Repository repository

In cases where we go ahead and create something, use the default SyntheticRepository, because we don't know any better.

searchedForSignatureAttributeback to summary
private boolean searchedForSignatureAttribute
signatureAttributeback to summary
private Signature signatureAttribute
signatureAttributeStringback to summary
private String signatureAttributeString
sourcefileNameback to summary
private String sourcefileName
superclassnameback to summary
private String superclassname
superclassnameIdxback to summary
private int superclassnameIdx

Constructor Detail

JavaClassback to summary
public JavaClass(int classnameIndex, int superclassnameIndex, String filename, int major, int minor, int access_flags, ConstantPool cpool, int[] interfaces, Field[] fields, Method[] methods, Attribute[] attributes)

Method Detail

acceptback to summary
public void accept(ClassVisitor v)

Implements org.aspectj.apache.bcel.classfile.Node.accept.

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.

Parameters
v:ClassVisitor

Visitor object

computeNestedTypeStatusback to summary
private final void computeNestedTypeStatus()
dumpback to summary
public void dump(File file) throws IOException

Dump class to a file.

Parameters
file:File

Output file

dumpback to summary
public void dump(String file_name) throws IOException

Dump class to a file named file_name.

Parameters
file_name:String

Output file name

dumpback to summary
public void dump(OutputStream file) throws IOException

Dump Java class to output stream in binary format.

dumpback to summary
public void dump(DataOutputStream file) throws IOException

Dump Java class to output stream in binary format.

getAllInterfacesback to summary
public Collection<JavaClass> getAllInterfaces()

Get all interfaces implemented by this JavaClass (transitively).

getAnnotationsback to summary
public AnnotationGen[] getAnnotations()
getAttributesback to summary
public Attribute[] getAttributes()
getBytesback to summary
public byte[] getBytes()
Returns:byte[]

class in binary format

getClassNameback to summary
public String getClassName()
Returns:String

Class name.

getClassNameIndexback to summary
public int getClassNameIndex()
getConstantPoolback to summary
public ConstantPool getConstantPool()
getFieldback to summary
public Field getField(Field field)
getFieldsback to summary
public Field[] getFields()
Returns:Field[]

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.

getFileNameback to summary
public String getFileName()
Returns:String

File name of class, aka SourceFile attribute value

getGenericSignatureback to summary
public final 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.

getInterfaceIndicesback to summary
public int[] getInterfaceIndices()
Returns:int[]

Indices in constant pool of implemented interfaces.

getInterfaceNamesback to summary
public String[] getInterfaceNames()
Returns:String[]

Names of implemented interfaces.

getInterfacesback to summary
public JavaClass[] getInterfaces()

Get interfaces directly implemented by this JavaClass.

getMajorback to summary
public int getMajor()
getMethodback to summary
public Method getMethod(Method m)
Returns:Method

A org.aspectj.apache.bcel.classfile.Method corresponding to java.lang.reflect.Method if any

getMethodback to summary
public Method getMethod(Constructor<?> c)
getMethodsback to summary
public Method[] getMethods()
Returns:Method[]

Methods of the class.

getMinorback to summary
public int getMinor()
Returns:int

Minor number of class file version.

getPackageNameback to summary
public String getPackageName()
Returns:String

Package name.

getRepositoryback to summary
public Repository getRepository()

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

getSignatureAttributeback to summary
public final Signature getSignatureAttribute()
getSourceFileNameback to summary
public String getSourceFileName()
Returns:String

sbsolute path to file where this class was read from

getSuperClassback to summary
public JavaClass getSuperClass()
Returns:JavaClass

the superclass for this JavaClass object, or null if this is java.lang.Object

getSuperClassesback to summary
public JavaClass[] getSuperClasses()
Returns:JavaClass[]

list of super classes of this class in ascending order, i.e., java.lang.Object is always the last element

getSuperclassNameback to summary
public String getSuperclassName()
Returns:String

Superclass name.

getSuperclassNameIndexback to summary
public int getSuperclassNameIndex()
Returns:int

Class name index.

implementationOfback to summary
public boolean implementationOf(JavaClass inter)
Returns:boolean

true, if clazz is an implementation of interface inter

indentback to summary
private static final String indent(Object obj)
instanceOfback to summary
public final boolean instanceOf(JavaClass super_class)

Equivalent to runtime "instanceof" operator.

Returns:boolean

true if this JavaClass is derived from teh super class

isAnnotationback to summary
public final boolean isAnnotation()

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

isAnonymousback to summary
public final boolean isAnonymous()
isClassback to summary
public final boolean isClass()
isEnumback to summary
public final boolean isEnum()

Returns true if this class represents an enum type

isGenericback to summary
public boolean isGeneric()
isNestedback to summary
public final boolean isNested()
isSuperback to summary
public final boolean isSuper()
loadGenericSignatureInfoIfNecessaryback to summary
private void loadGenericSignatureInfoIfNecessary()
setAttributesback to summary
public void setAttributes(Attribute[] attributes)
Parameters
attributes:Attribute[]

.

setClassNameback to summary
public void setClassName(String class_name)
Parameters
class_name:String

.

setClassNameIndexback to summary
public void setClassNameIndex(int class_name_index)
Parameters
class_name_index:int

.

setConstantPoolback to summary
public void setConstantPool(ConstantPool constant_pool)
Parameters
constant_pool:ConstantPool

.

setFieldsback to summary
public void setFields(Field[] fields)
Parameters
fields:Field[]

.

setFileNameback to summary
public void setFileName(String file_name)

Set File name of class, aka SourceFile attribute value

setInterfaceNamesback to summary
public void setInterfaceNames(String[] interface_names)
Parameters
interface_names:String[]

.

setInterfacesback to summary
public void setInterfaces(int[] interfaces)
Parameters
interfaces:int[]

.

setMajorback to summary
public void setMajor(int major)
setMethodsback to summary
public void setMethods(Method[] methods)
setMinorback to summary
public void setMinor(int minor)
setRepositoryback to summary
public void setRepository(Repository repository)

Sets the ClassRepository which loaded the JavaClass. Should be called immediately after parsing is done.

setSourceFileNameback to summary
public void setSourceFileName(String source_file_name)

Set absolute path to file this class was read from.

setSuperclassNameback to summary
public void setSuperclassName(String superclass_name)
Parameters
superclass_name:String

.

setSuperclassNameIndexback to summary
public void setSuperclassNameIndex(int superclass_name_index)
Parameters
superclass_name_index:int

.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

String representing class contents.

Annotations
@Override