Package org.apache.bcel.generic
Class ClassGen
java.lang.Object
org.apache.bcel.classfile.AccessFlags
org.apache.bcel.generic.ClassGen
- All Implemented Interfaces:
Cloneable
Template class for building up a java class. May be initialized with an existing Java class (file).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<AnnotationEntryGen> private static BCELComparator<ClassGen> private Stringprivate intprivate ConstantPoolGenprivate final Stringprivate intprivate intprivate List<ClassObserver> private Stringprivate intFields inherited from class org.apache.bcel.classfile.AccessFlags
access_flags -
Constructor Summary
ConstructorsConstructorDescriptionClassGen(String className, String superClassName, String fileName, int accessFlags, String[] interfaces) Convenience constructor to set up some important values initially.ClassGen(String className, String superClassName, String fileName, int accessFlags, String[] interfaces, ConstantPoolGen cp) Convenience constructor to set up some important values initially.Initialize with existing class. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidAdd an attribute to this class.voidaddEmptyConstructor(int accessFlags) Convenience method.voidAdd a field to this class.voidaddInterface(String name) Add an interface to this class, i.e., this class has to implement it.voidAdd a method to this class.voidAdd observer for this object.clone()containsField(String name) booleancontainsMethod(String name, String signature) booleanReturn value as defined by given BCELComparator strategy.intstatic BCELComparator<ClassGen> Field[]String[]int[]intgetMajor()getMethodAt(int pos) Method[]intgetMinor()intinthashCode()Return value as defined by given BCELComparator strategy.voidRemove an attribute from this class.voidremoveField(Field f) Remove a field to this class.voidremoveInterface(String name) Remove an interface from this class.voidRemove a method from this class.voidRemove observer for this object.voidreplaceField(Field old, Field newField) Replace given field with new one.voidreplaceMethod(Method old, Method newMethod) Replace given method with new one.voidsetClassName(String name) voidsetClassNameIndex(int classNameIndex) static voidsetComparator(BCELComparator<ClassGen> comparator) voidsetConstantPool(ConstantPoolGen constantPool) voidsetMajor(int major) Sets major version number of class file, default value is 45 (JDK 1.1)voidsetMethodAt(Method method, int pos) voidsetMethods(Method[] methods) voidsetMinor(int minor) Sets minor version number of class file, default value is 3 (JDK 1.1)voidsetSuperclassName(String name) voidsetSuperclassNameIndex(int superclassNameIndex) private AnnotationEntryGen[]unpackAnnotations(Attribute[] attrs) Look for attributes representing annotations and unpack them.voidupdate()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
-
Field Details
-
bcelComparator
-
className
-
superClassName
-
fileName
-
classNameIndex
private int classNameIndex -
superclassNameIndex
private int superclassNameIndex -
major
private int major -
minor
private int minor -
cp
-
fieldList
-
methodList
-
attributeList
-
interfaceList
-
annotationList
-
observers
-
-
Constructor Details
-
ClassGen
Initialize with existing class.- Parameters:
clazz- JavaClass object (e.g. read from file)
-
ClassGen
public ClassGen(String className, String superClassName, String fileName, int accessFlags, 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(String className, String superClassName, String fileName, int accessFlags, 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 Details
-
getComparator
- Returns:
- Comparison strategy object
-
setComparator
- Parameters:
comparator- Comparison strategy object
-
addAnnotationEntry
-
addAttribute
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
-
addField
Add a field to this class.- Parameters:
f- field to add
-
addInterface
Add an interface to this class, i.e., this class has to implement it.- Parameters:
name- interface to implement (fully qualified class name)
-
addMethod
Add a method to this class.- Parameters:
m- method to add
-
addObserver
Add observer for this object. -
clone
-
containsField
-
containsField
- Returns:
- field object with given name, or null
-
containsMethod
- Returns:
- method object with given name and signature, or null
-
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. -
getAnnotationEntries
-
getAttributes
-
getClassName
-
getClassNameIndex
public int getClassNameIndex() -
getConstantPool
-
getFields
-
getFileName
-
getInterfaceNames
-
getInterfaces
public int[] getInterfaces() -
getJavaClass
- Returns:
- the (finally) built up Java class object.
-
getMajor
public int getMajor()- Returns:
- major version number of class file
-
getMethodAt
-
getMethods
-
getMinor
public int getMinor()- Returns:
- minor version number of class file
-
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. -
removeAttribute
Remove an attribute from this class.- Parameters:
a- attribute to remove
-
removeField
Remove a field to this class.- Parameters:
f- field to remove
-
removeInterface
Remove an interface from this class.- Parameters:
name- interface to remove (fully qualified name)
-
removeMethod
Remove a method from this class.- Parameters:
m- method to remove
-
removeObserver
Remove observer for this object. -
replaceField
Replace given field with new one. If the old one does not exist add the new_ field to the class anyway. -
replaceMethod
Replace given method with new one. If the old one does not exist add the newMethod method to the class anyway. -
setClassName
-
setClassNameIndex
public void setClassNameIndex(int classNameIndex) -
setConstantPool
-
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
-
setMethods
-
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
-
setSuperclassNameIndex
public void setSuperclassNameIndex(int superclassNameIndex) -
unpackAnnotations
Look for attributes representing annotations and unpack them. -
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.
-