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)Initialize with existing class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAnnotationEntry(AnnotationEntryGen a)voidaddAttribute(Attribute a)Add an attribute to this class.voidaddEmptyConstructor(int access_flags)Convenience method.voidaddField(Field f)Add a field to this class.voidaddInterface(java.lang.String name)Add an interface to this class, i.e., this class has to implement it.voidaddMethod(Method m)Add a method to this class.voidaddObserver(ClassObserver o)Add observer for this object.java.lang.Objectclone()FieldcontainsField(java.lang.String name)booleancontainsField(Field f)MethodcontainsMethod(java.lang.String name, java.lang.String signature)booleanequals(java.lang.Object obj)Return value as defined by given BCELComparator strategy.AnnotationEntryGen[]getAnnotationEntries()Attribute[]getAttributes()java.lang.StringgetClassName()intgetClassNameIndex()static BCELComparatorgetComparator()ConstantPoolGengetConstantPool()Field[]getFields()java.lang.StringgetFileName()java.lang.String[]getInterfaceNames()int[]getInterfaces()JavaClassgetJavaClass()intgetMajor()MethodgetMethodAt(int pos)Method[]getMethods()intgetMinor()java.lang.StringgetSuperclassName()intgetSuperclassNameIndex()inthashCode()Return value as defined by given BCELComparator strategy.voidremoveAttribute(Attribute a)Remove an attribute from this class.voidremoveField(Field f)Remove a field to this class.voidremoveInterface(java.lang.String name)Remove an interface from this class.voidremoveMethod(Method m)Remove a method from this class.voidremoveObserver(ClassObserver o)Remove observer for this object.voidreplaceField(Field old, Field new_)Replace given field with new one.voidreplaceMethod(Method old, Method new_)Replace given method with new one.voidsetClassName(java.lang.String name)voidsetClassNameIndex(int class_name_index)static voidsetComparator(BCELComparator comparator)voidsetConstantPool(ConstantPoolGen constant_pool)voidsetMajor(int major)Set major version number of class file, default value is 45 (JDK 1.1)voidsetMethodAt(Method method, int pos)voidsetMethods(Method[] methods)voidsetMinor(int minor)Set minor version number of class file, default value is 3 (JDK 1.1)voidsetSuperclassName(java.lang.String name)voidsetSuperclassNameIndex(int superclass_name_index)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
-
-
-
-
Constructor Detail
-
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
-
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(JavaClass clazz)
Initialize with existing class.- Parameters:
clazz- JavaClass object (e.g. read from file)
-
-
Method Detail
-
getJavaClass
public JavaClass getJavaClass()
- Returns:
- the (finally) built up Java class object.
-
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)
-
removeInterface
public void removeInterface(java.lang.String name)
Remove an interface from this class.- Parameters:
name- interface to remove (fully qualified name)
-
getMajor
public int getMajor()
- Returns:
- major version number of class file
-
setMajor
public void setMajor(int major)
Set major version number of class file, default value is 45 (JDK 1.1)- Parameters:
major- major version number
-
setMinor
public void setMinor(int minor)
Set minor version number of class file, default value is 3 (JDK 1.1)- Parameters:
minor- minor version number
-
getMinor
public int getMinor()
- Returns:
- minor version number of class file
-
addAttribute
public void addAttribute(Attribute a)
Add an attribute to this class.- Parameters:
a- attribute to add
-
addAnnotationEntry
public void addAnnotationEntry(AnnotationEntryGen a)
-
addMethod
public void addMethod(Method m)
Add a method to this class.- Parameters:
m- method to add
-
addEmptyConstructor
public void addEmptyConstructor(int access_flags)
Convenience method. Add an empty constructor to this class that does nothing but calling super().- Parameters:
access_flags- rights for constructor
-
addField
public void addField(Field f)
Add a field to this class.- Parameters:
f- field to add
-
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
-
removeAttribute
public void removeAttribute(Attribute a)
Remove an attribute from this class.- Parameters:
a- attribute to remove
-
removeMethod
public void removeMethod(Method m)
Remove a method from this class.- Parameters:
m- method to remove
-
replaceMethod
public void replaceMethod(Method old, Method new_)
Replace given method with new one. If the old one does not exist add the new_ method to the class anyway.
-
replaceField
public void replaceField(Field old, Field new_)
Replace given field with new one. If the old one does not exist add the new_ field to the class anyway.
-
removeField
public void removeField(Field f)
Remove a field to this class.- Parameters:
f- field to remove
-
getClassName
public java.lang.String getClassName()
-
getSuperclassName
public java.lang.String getSuperclassName()
-
getFileName
public java.lang.String getFileName()
-
setClassName
public void setClassName(java.lang.String name)
-
setSuperclassName
public void setSuperclassName(java.lang.String name)
-
getMethods
public Method[] getMethods()
-
setMethods
public void setMethods(Method[] methods)
-
setMethodAt
public void setMethodAt(Method method, int pos)
-
getMethodAt
public Method getMethodAt(int pos)
-
getInterfaceNames
public java.lang.String[] getInterfaceNames()
-
getInterfaces
public int[] getInterfaces()
-
getFields
public Field[] getFields()
-
getAttributes
public Attribute[] getAttributes()
-
getAnnotationEntries
public AnnotationEntryGen[] getAnnotationEntries()
-
getConstantPool
public ConstantPoolGen getConstantPool()
-
setConstantPool
public void setConstantPool(ConstantPoolGen constant_pool)
-
setClassNameIndex
public void setClassNameIndex(int class_name_index)
-
setSuperclassNameIndex
public void setSuperclassNameIndex(int superclass_name_index)
-
getSuperclassNameIndex
public int getSuperclassNameIndex()
-
getClassNameIndex
public int getClassNameIndex()
-
addObserver
public void addObserver(ClassObserver o)
Add observer for this object.
-
removeObserver
public void removeObserver(ClassObserver o)
Remove observer for this object.
-
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 he has finished editing the object.
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
getComparator
public static BCELComparator getComparator()
- Returns:
- Comparison strategy object
-
setComparator
public static void setComparator(BCELComparator comparator)
- Parameters:
comparator- Comparison strategy object
-
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:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()
Return value as defined by given BCELComparator strategy. By default return the hashcode of the class name.- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
-