Top Description Fields Constructors Methods
com.sun.org.apache.bcel.internal.generic

public Class ClassGen

extends AccessFlags
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator
Imports
java.util.ArrayList, .Arrays, .Collections, .List, .Objects, com.sun.org.apache.bcel.internal.Const, com.sun.org.apache.bcel.internal.classfile.AccessFlags, .Annotations, .Attribute, .ConstantPool, .Field, .JavaClass, .Method, .RuntimeInvisibleAnnotations, .RuntimeVisibleAnnotations, .SourceFile, .Utility, com.sun.org.apache.bcel.internal.util.BCELComparator

Template class for building up a java class. May be initialized with an existing java class (file).
See Also
JavaClass

Field Summary

Modifier and TypeField and Description
private final List<AnnotationEntryGen>
private final List<Attribute>
private static BCELComparator
private String
private int
private ConstantPoolGen
private final List<Field>
private final String
private final List<String>
private int
private final List<Method>
private int
private List<ClassObserver>
private String
private int
Inherited from com.sun.org.apache.bcel.internal.classfile.AccessFlags:
access_flags

Constructor Summary

AccessConstructor and Description
public
ClassGen(final JavaClass
JavaClass object (e.g. read from file)
clazz
)

Initialize with existing class.

public
ClassGen(final String
fully qualified class name
className
,
final String
fully qualified superclass name
superClassName
,
final String
source file name
fileName
,
final int
access qualifiers
accessFlags
,
final String[]
implemented interfaces
interfaces
)

Convenience constructor to set up some important values initially.

public
ClassGen(final String
fully qualified class name
className
,
final String
fully qualified superclass name
superClassName
,
final String
source file name
fileName
,
final int
access qualifiers
accessFlags
,
final String[]
implemented interfaces
interfaces
,
final ConstantPoolGen
constant pool to use
cp
)

Convenience constructor to set up some important values initially.

Method Summary

Modifier and TypeMethod and Description
public void
public void
addAttribute(final Attribute
attribute to add
a
)

Add an attribute to this class.

public void
addEmptyConstructor(final int
rights for constructor
accessFlags
)

Convenience method.

public void
addField(final Field
field to add
f
)

Add a field to this class.

public void
addInterface(final String
interface to implement (fully qualified class name)
name
)

Add an interface to this class, i.e., this class has to implement it.

public void
addMethod(final Method
method to add
m
)

Add a method to this class.

public void
addObserver(final ClassObserver o)

Add observer for this object.

public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean
public Field

Returns:

field object with given name, or null
containsField
(final String name)

public Method

Returns:

method object with given name and signature, or null
containsMethod
(final String name, final String signature)

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Return value as defined by given BCELComparator strategy.
public AnnotationEntryGen[]
public Attribute[]
public String
public int
public static BCELComparator

Returns:

Comparison strategy object
getComparator
()

public ConstantPoolGen
public Field[]
public String
public String[]
public int[]
public JavaClass

Returns:

the (finally) built up Java class object.
getJavaClass
()

public int

Returns:

major version number of class file
getMajor
()

public Method
getMethodAt(final int pos)

public Method[]
public int

Returns:

minor version number of class file
getMinor
()

public String
public int
public int
hashCode()

Overrides java.lang.Object.hashCode.

Return value as defined by given BCELComparator strategy.
public void
removeAttribute(final Attribute
attribute to remove
a
)

Remove an attribute from this class.

public void
removeField(final Field
field to remove
f
)

Remove a field to this class.

public void
removeInterface(final String
interface to remove (fully qualified name)
name
)

Remove an interface from this class.

public void
removeMethod(final Method
method to remove
m
)

Remove a method from this class.

public void
removeObserver(final ClassObserver o)

Remove observer for this object.

public void
replaceField(final Field old, final Field newField)

Replace given field with new one.

public void
replaceMethod(final Method old, final Method newMethod)

Replace given method with new one.

public void
setClassName(final String name)

public void
setClassNameIndex(final int classNameIndex)

public static void
setComparator(final BCELComparator
Comparison strategy object
comparator
)

public void
setConstantPool(final ConstantPoolGen constantPool)

public void
setMajor(final int
major version number
major
)

Set major version number of class file, default value is 45 (JDK 1.1)

public void
setMethodAt(final Method method, final int pos)

public void
setMethods(final Method[] methods)

public void
setMinor(final int
minor version number
minor
)

Set minor version number of class file, default value is 3 (JDK 1.1)

public void
public void
setSuperclassNameIndex(final int superclassNameIndex)

private AnnotationEntryGen[]
unpackAnnotations(final Attribute[] attrs)

Look for attributes representing annotations and unpack them.

public void
update()

Call notify() method on all observers.

Inherited from com.sun.org.apache.bcel.internal.classfile.AccessFlags:
getAccessFlagsgetModifiersisAbstractisAbstractisAnnotationisAnnotationisEnumisEnumisFinalisFinalisInterfaceisInterfaceisNativeisNativeisPrivateisPrivateisProtectedisProtectedisPublicisPublicisStaticisStaticisStrictfpisStrictfpisSynchronizedisSynchronizedisSyntheticisSyntheticisTransientisTransientisVarArgsisVarArgsisVolatileisVolatilesetAccessFlagssetModifiers

Field Detail

annotationListback to summary
private final List<AnnotationEntryGen> annotationList
attributeListback to summary
private final List<Attribute> attributeList
bcelComparatorback to summary
private static BCELComparator bcelComparator
classNameback to summary
private String className
classNameIndexback to summary
private int classNameIndex
cpback to summary
private ConstantPoolGen cp
fieldListback to summary
private final List<Field> fieldList
fileNameback to summary
private final String fileName
interfaceListback to summary
private final List<String> interfaceList
majorback to summary
private int major
methodListback to summary
private final List<Method> methodList
minorback to summary
private int minor
observersback to summary
private List<ClassObserver> observers
superClassNameback to summary
private String superClassName
superclassNameIndexback to summary
private int superclassNameIndex

Constructor Detail

ClassGenback to summary
public ClassGen(final JavaClass clazz)

Initialize with existing class.

Parameters
clazz:JavaClass

JavaClass object (e.g. read from file)

ClassGenback to summary
public ClassGen(final String className, final String superClassName, final String fileName, final int accessFlags, final String[] interfaces)

Convenience constructor to set up some important values initially.

Parameters
className:String

fully qualified class name

superClassName:String

fully qualified superclass name

fileName:String

source file name

accessFlags:int

access qualifiers

interfaces:String[]

implemented interfaces

ClassGenback to summary
public ClassGen(final String className, final String superClassName, final String fileName, final int accessFlags, final String[] interfaces, final ConstantPoolGen cp)

Convenience constructor to set up some important values initially.

Parameters
className:String

fully qualified class name

superClassName:String

fully qualified superclass name

fileName:String

source file name

accessFlags:int

access qualifiers

interfaces:String[]

implemented interfaces

cp:ConstantPoolGen

constant pool to use

Method Detail

addAnnotationEntryback to summary
public void addAnnotationEntry(final AnnotationEntryGen a)
addAttributeback to summary
public void addAttribute(final Attribute a)

Add an attribute to this class.

Parameters
a:Attribute

attribute to add

addEmptyConstructorback to summary
public void addEmptyConstructor(final int accessFlags)

Convenience method. Add an empty constructor to this class that does nothing but calling super().

Parameters
accessFlags:int

rights for constructor

addFieldback to summary
public void addField(final Field f)

Add a field to this class.

Parameters
f:Field

field to add

addInterfaceback to summary
public void addInterface(final String name)

Add an interface to this class, i.e., this class has to implement it.

Parameters
name:String

interface to implement (fully qualified class name)

addMethodback to summary
public void addMethod(final Method m)

Add a method to this class.

Parameters
m:Method

method to add

addObserverback to summary
public void addObserver(final ClassObserver o)

Add observer for this object.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
containsFieldback to summary
public boolean containsField(final Field f)
containsFieldback to summary
public Field containsField(final String name)
Returns:Field

field object with given name, or null

containsMethodback to summary
public Method containsMethod(final String name, final String signature)
Returns:Method

method object with given name and signature, or null

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Return value as defined by given BCELComparator strategy. By default two ClassGen objects are said to be equal when their class names are equal.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
See Also
Object#equals(Object)
getAnnotationEntriesback to summary
public AnnotationEntryGen[] getAnnotationEntries()
getAttributesback to summary
public Attribute[] getAttributes()
getClassNameback to summary
public String getClassName()
getClassNameIndexback to summary
public int getClassNameIndex()
getComparatorback to summary
public static BCELComparator getComparator()
Returns:BCELComparator

Comparison strategy object

getConstantPoolback to summary
public ConstantPoolGen getConstantPool()
getFieldsback to summary
public Field[] getFields()
getFileNameback to summary
public String getFileName()
getInterfaceNamesback to summary
public String[] getInterfaceNames()
getInterfacesback to summary
public int[] getInterfaces()
getJavaClassback to summary
public JavaClass getJavaClass()
Returns:JavaClass

the (finally) built up Java class object.

getMajorback to summary
public int getMajor()
Returns:int

major version number of class file

getMethodAtback to summary
public Method getMethodAt(final int pos)
getMethodsback to summary
public Method[] getMethods()
getMinorback to summary
public int getMinor()
Returns:int

minor version number of class file

getSuperclassNameback to summary
public String getSuperclassName()
getSuperclassNameIndexback to summary
public int getSuperclassNameIndex()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Return value as defined by given BCELComparator strategy. By default return the hashcode of the class name.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object

Annotations
@Override
See Also
Object#hashCode()
removeAttributeback to summary
public void removeAttribute(final Attribute a)

Remove an attribute from this class.

Parameters
a:Attribute

attribute to remove

removeFieldback to summary
public void removeField(final Field f)

Remove a field to this class.

Parameters
f:Field

field to remove

removeInterfaceback to summary
public void removeInterface(final String name)

Remove an interface from this class.

Parameters
name:String

interface to remove (fully qualified name)

removeMethodback to summary
public void removeMethod(final Method m)

Remove a method from this class.

Parameters
m:Method

method to remove

removeObserverback to summary
public void removeObserver(final ClassObserver o)

Remove observer for this object.

replaceFieldback to summary
public void replaceField(final Field old, final Field newField)

Replace given field with new one. If the old one does not exist add the new_ field to the class anyway.

replaceMethodback to summary
public void replaceMethod(final Method old, final Method newMethod)

Replace given method with new one. If the old one does not exist add the newMethod method to the class anyway.

setClassNameback to summary
public void setClassName(final String name)
setClassNameIndexback to summary
public void setClassNameIndex(final int classNameIndex)
setComparatorback to summary
public static void setComparator(final BCELComparator comparator)
Parameters
comparator:BCELComparator

Comparison strategy object

setConstantPoolback to summary
public void setConstantPool(final ConstantPoolGen constantPool)
setMajorback to summary
public void setMajor(final int major)

Set major version number of class file, default value is 45 (JDK 1.1)

Parameters
major:int

major version number

setMethodAtback to summary
public void setMethodAt(final Method method, final int pos)
setMethodsback to summary
public void setMethods(final Method[] methods)
setMinorback to summary
public void setMinor(final int minor)

Set minor version number of class file, default value is 3 (JDK 1.1)

Parameters
minor:int

minor version number

setSuperclassNameback to summary
public void setSuperclassName(final String name)
setSuperclassNameIndexback to summary
public void setSuperclassNameIndex(final int superclassNameIndex)
unpackAnnotationsback to summary
private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs)

Look for attributes representing annotations and unpack them.

updateback to summary
public void update()

Call notify() method on all observers. This method is not called automatically whenever the state has changed, but has to be called by the user after they have finished editing the object.