Package org.apache.bcel.generic
Class ClassGen
- java.lang.Object
-
- org.apache.bcel.classfile.AccessFlags
-
- org.apache.bcel.generic.ClassGen
-
- All Implemented Interfaces:
java.lang.Cloneable
public class ClassGen extends AccessFlags implements java.lang.Cloneable
Template class for building up a java class. May be initialized with an existing Java class (file).- See Also:
JavaClass
-
-
Field Summary
-
Fields inherited from class org.apache.bcel.classfile.AccessFlags
access_flags
-
-
Constructor Summary
Constructors Constructor Description ClassGen(java.lang.String className, java.lang.String superClassName, java.lang.String fileName, int accessFlags, java.lang.String[] interfaces)
Convenience constructor to set up some important values initially.ClassGen(java.lang.String className, java.lang.String superClassName, java.lang.String fileName, int accessFlags, java.lang.String[] interfaces, ConstantPoolGen cp)
Convenience constructor to set up some important values initially.ClassGen(JavaClass clazz)
Constructs a new instance from an existing class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAnnotationEntry(AnnotationEntryGen a)
void
addAttribute(Attribute a)
Add an attribute to this class.void
addEmptyConstructor(int accessFlags)
Convenience method.void
addField(Field f)
Add a field to this class.void
addInterface(java.lang.String name)
Add an interface to this class, i.e., this class has to implement it.void
addMethod(Method m)
Add a method to this class.void
addObserver(ClassObserver o)
Add observer for this object.java.lang.Object
clone()
Field
containsField(java.lang.String name)
boolean
containsField(Field f)
Method
containsMethod(java.lang.String name, java.lang.String signature)
boolean
equals(java.lang.Object obj)
Return value as defined by given BCELComparator strategy.AnnotationEntryGen[]
getAnnotationEntries()
Attribute[]
getAttributes()
java.lang.String
getClassName()
int
getClassNameIndex()
static BCELComparator<ClassGen>
getComparator()
ConstantPoolGen
getConstantPool()
Field[]
getFields()
java.lang.String
getFileName()
java.lang.String[]
getInterfaceNames()
int[]
getInterfaces()
JavaClass
getJavaClass()
int
getMajor()
Method
getMethodAt(int pos)
Method[]
getMethods()
int
getMinor()
java.lang.String
getSuperclassName()
int
getSuperclassNameIndex()
int
hashCode()
Return value as defined by given BCELComparator strategy.void
removeAttribute(Attribute a)
Remove an attribute from this class.void
removeField(Field f)
Remove a field to this class.void
removeInterface(java.lang.String name)
Remove an interface from this class.void
removeMethod(Method m)
Remove a method from this class.void
removeObserver(ClassObserver o)
Remove observer for this object.void
replaceField(Field old, Field newField)
Replace given field with new one.void
replaceMethod(Method old, Method newMethod)
Replace given method with new one.void
setClassName(java.lang.String name)
void
setClassNameIndex(int classNameIndex)
static void
setComparator(BCELComparator<ClassGen> comparator)
void
setConstantPool(ConstantPoolGen constantPool)
void
setMajor(int major)
Sets major version number of class file, default value is 45 (JDK 1.1)void
setMethodAt(Method method, int pos)
void
setMethods(Method[] methods)
void
setMinor(int minor)
Sets minor version number of class file, default value is 3 (JDK 1.1)void
setSuperclassName(java.lang.String name)
void
setSuperclassNameIndex(int superclassNameIndex)
void
update()
Call notify() method on all observers.-
Methods inherited from class org.apache.bcel.classfile.AccessFlags
getAccessFlags, getModifiers, isAbstract, isAbstract, isAnnotation, isAnnotation, isEnum, isEnum, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isSynthetic, isSynthetic, isTransient, isTransient, isVarArgs, isVarArgs, isVolatile, isVolatile, setAccessFlags, setModifiers
-
-
-
-
Constructor Detail
-
ClassGen
public ClassGen(JavaClass clazz)
Constructs a new instance from an existing class.- Parameters:
clazz
- JavaClass object (e.g. read from file)
-
ClassGen
public ClassGen(java.lang.String className, java.lang.String superClassName, java.lang.String fileName, int accessFlags, java.lang.String[] interfaces)
Convenience constructor to set up some important values initially.- Parameters:
className
- fully qualified class namesuperClassName
- fully qualified superclass namefileName
- source file nameaccessFlags
- access qualifiersinterfaces
- implemented interfaces
-
ClassGen
public ClassGen(java.lang.String className, java.lang.String superClassName, java.lang.String fileName, int accessFlags, java.lang.String[] interfaces, ConstantPoolGen cp)
Convenience constructor to set up some important values initially.- Parameters:
className
- fully qualified class namesuperClassName
- fully qualified superclass namefileName
- source file nameaccessFlags
- access qualifiersinterfaces
- implemented interfacescp
- constant pool to use
-
-
Method Detail
-
getComparator
public static BCELComparator<ClassGen> getComparator()
- Returns:
- Comparison strategy object
-
setComparator
public static void setComparator(BCELComparator<ClassGen> comparator)
- Parameters:
comparator
- Comparison strategy object
-
addAnnotationEntry
public void addAnnotationEntry(AnnotationEntryGen a)
-
addAttribute
public void addAttribute(Attribute a)
Add an attribute to this class.- Parameters:
a
- attribute to add
-
addEmptyConstructor
public void addEmptyConstructor(int accessFlags)
Convenience method. Add an empty constructor to this class that does nothing but calling super().- Parameters:
accessFlags
- rights for constructor
-
addInterface
public void addInterface(java.lang.String name)
Add an interface to this class, i.e., this class has to implement it.- Parameters:
name
- interface to implement (fully qualified class name)
-
addMethod
public void addMethod(Method m)
Add a method to this class.- Parameters:
m
- method to add
-
addObserver
public void addObserver(ClassObserver o)
Add observer for this object.
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
containsField
public boolean containsField(Field f)
-
containsField
public Field containsField(java.lang.String name)
- Returns:
- field object with given name, or null
-
containsMethod
public Method containsMethod(java.lang.String name, java.lang.String signature)
- Returns:
- method object with given name and signature, or null
-
equals
public boolean equals(java.lang.Object obj)
Return value as defined by given BCELComparator strategy. By default two ClassGen objects are said to be equal when their class names are equal.- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(Object)
-
getAnnotationEntries
public AnnotationEntryGen[] getAnnotationEntries()
-
getAttributes
public Attribute[] getAttributes()
-
getClassName
public java.lang.String getClassName()
-
getClassNameIndex
public int getClassNameIndex()
-
getConstantPool
public ConstantPoolGen getConstantPool()
-
getFileName
public java.lang.String getFileName()
-
getInterfaceNames
public java.lang.String[] getInterfaceNames()
-
getInterfaces
public int[] getInterfaces()
-
getJavaClass
public JavaClass getJavaClass()
- Returns:
- the (finally) built up Java class object.
-
getMajor
public int getMajor()
- Returns:
- major version number of class file
-
getMethodAt
public Method getMethodAt(int pos)
-
getMethods
public Method[] getMethods()
-
getMinor
public int getMinor()
- Returns:
- minor version number of class file
-
getSuperclassName
public java.lang.String getSuperclassName()
-
getSuperclassNameIndex
public int getSuperclassNameIndex()
-
hashCode
public int hashCode()
Return value as defined by given BCELComparator strategy. By default return the hash code of the class name.- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
removeAttribute
public void removeAttribute(Attribute a)
Remove an attribute from this class.- Parameters:
a
- attribute to remove
-
removeField
public void removeField(Field f)
Remove a field to this class.- Parameters:
f
- field to remove
-
removeInterface
public void removeInterface(java.lang.String name)
Remove an interface from this class.- Parameters:
name
- interface to remove (fully qualified name)
-
removeMethod
public void removeMethod(Method m)
Remove a method from this class.- Parameters:
m
- method to remove
-
removeObserver
public void removeObserver(ClassObserver o)
Remove observer for this object.
-
replaceField
public void replaceField(Field old, Field newField)
Replace given field with new one. If the old one does not exist add the new_ field to the class anyway.
-
replaceMethod
public void replaceMethod(Method old, Method newMethod)
Replace given method with new one. If the old one does not exist add the newMethod method to the class anyway.
-
setClassName
public void setClassName(java.lang.String name)
-
setClassNameIndex
public void setClassNameIndex(int classNameIndex)
-
setConstantPool
public void setConstantPool(ConstantPoolGen constantPool)
-
setMajor
public void setMajor(int major)
Sets major version number of class file, default value is 45 (JDK 1.1)- Parameters:
major
- major version number
-
setMethodAt
public void setMethodAt(Method method, int pos)
-
setMethods
public void setMethods(Method[] methods)
-
setMinor
public void setMinor(int minor)
Sets minor version number of class file, default value is 3 (JDK 1.1)- Parameters:
minor
- minor version number
-
setSuperclassName
public void setSuperclassName(java.lang.String name)
-
setSuperclassNameIndex
public void setSuperclassNameIndex(int superclassNameIndex)
-
update
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.
-
-