Top Description Inners Fields Constructors Methods
org.aspectj.apache.bcel.generic

public Class ClassGen

extends Modifiers
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
java.io.ByteArrayOutputStream, .DataOutputStream, java.lang.reflect.Modifier, java.security.MessageDigest, java.util.ArrayList, .Arrays, .Collection, .Comparator, .List, org.aspectj.apache.bcel.Constants, org.aspectj.apache.bcel.classfile.Attribute, .ConstantPool, .Field, .JavaClass, .Method, .Modifiers, .SourceFile, .Utility, org.aspectj.apache.bcel.classfile.annotation.AnnotationGen, .RuntimeInvisAnnos, .RuntimeVisAnnos

Template class for building up a java class. May be initialized with an existing java class.
Author
M. Dahm Upgraded, Andy Clement 9th Mar 06 - calculates SUID
Version
$Id: ClassGen.java,v 1.15 2009/09/15 19:40:14 aclement Exp $
See Also
JavaClass

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private List<AnnotationGen>
private List<Attribute>
private String
private int
private ConstantPool
private List<Field>
private String
private List<String>
private int
private List<Method>
private int
private String
private int
Inherited from org.aspectj.apache.bcel.classfile.Modifiers:
modifiers

Constructor Summary

AccessConstructor and Description
public
ClassGen(String classname, String superclassname, String filename, int modifiers, String[] interfacenames, ConstantPool cpool)

public
ClassGen(String classname, String superclassname, String filename, int modifiers, String[] interfacenames)

public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
addEmptyConstructor(int
rights for constructor
access_flags
)

Convenience method.

public void
addField(Field
field to add
f
)

Add a field to this class.

public void
public void
public Object
clone()

Overrides java.lang.Object.clone.

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

Returns:

method object with given name and signature, or null if not found
containsMethod
(String name, String signature)

public Field

Returns:

field object with given name, or null if not found
findsField
(String name)

public AnnotationGen[]
public Attribute
getAttribute(String attributeName)

public Collection<Attribute>
public String
public int
public ConstantPool
public Field[]
public String
public String[]
public int[]
public JavaClass

Returns:

build and return a JavaClass
getJavaClass
()

public int
public Method
getMethodAt(int pos)

public Method[]
public int
public long
getSUID()

Calculate the SerialVersionUID for a class.

public String
public int
public boolean
hasAttribute(String attributeName)

public final boolean
public final boolean
public void
public void
public void
public void
public void
public void
replaceField(Field old, Field new_)

Replace given field with new one.

public void
replaceMethod(Method old, Method new_)

Replace given method with new one.

public void
public void
setClassNameIndex(int class_name_index)

public void
public void
public void
setMajor(int major)

public void
setMethodAt(Method method, int pos)

public void
setMethods(Method[] methods)

public void
setMinor(int minor)

public void
public void
setSuperclassNameIndex(int superclass_name_index)

Inherited from org.aspectj.apache.bcel.classfile.Modifiers:
getModifiersisAbstractisBridgeisFinalisInterfaceisNativeisPrivateisProtectedisPublicisStaticisStrictfpisSynchronizedisTransientisVarargsisVolatilesetModifiers

Field Detail

annotationsListback to summary
private List<AnnotationGen> annotationsList
attributesListback to summary
private List<Attribute> attributesList
classnameback to summary
private String classname
classnameIndexback to summary
private int classnameIndex
cpoolback to summary
private ConstantPool cpool
fieldsListback to summary
private List<Field> fieldsList
filenameback to summary
private String filename
interfaceListback to summary
private List<String> interfaceList
majorback to summary
private int major
methodsListback to summary
private List<Method> methodsList
minorback to summary
private int minor
superclassnameback to summary
private String superclassname
superclassnameIndexback to summary
private int superclassnameIndex

Constructor Detail

ClassGenback to summary
public ClassGen(String classname, String superclassname, String filename, int modifiers, String[] interfacenames, ConstantPool cpool)
ClassGenback to summary
public ClassGen(String classname, String superclassname, String filename, int modifiers, String[] interfacenames)
ClassGenback to summary
public ClassGen(JavaClass clazz)

Method Detail

addAnnotationback to summary
public void addAnnotation(AnnotationGen a)
addAttributeback to summary
public void addAttribute(Attribute a)
addEmptyConstructorback to summary
public void addEmptyConstructor(int access_flags)

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

Parameters
access_flags:int

rights for constructor

addFieldback to summary
public void addField(Field f)

Add a field to this class.

Parameters
f:Field

field to add

addInterfaceback to summary
public void addInterface(String name)
addMethodback to summary
public void addMethod(Method m)
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(Field f)
containsMethodback to summary
public Method containsMethod(String name, String signature)
Returns:Method

method object with given name and signature, or null if not found

findsFieldback to summary
public Field findsField(String name)
Returns:Field

field object with given name, or null if not found

getAnnotationsback to summary
public AnnotationGen[] getAnnotations()
getAttributeback to summary
public Attribute getAttribute(String attributeName)
getAttributesback to summary
public Collection<Attribute> getAttributes()
getClassNameback to summary
public String getClassName()
getClassNameIndexback to summary
public int getClassNameIndex()
getConstantPoolback to summary
public ConstantPool 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

build and return a JavaClass

getMajorback to summary
public int getMajor()
getMethodAtback to summary
public Method getMethodAt(int pos)
getMethodsback to summary
public Method[] getMethods()
getMinorback to summary
public int getMinor()
getSUIDback to summary
public long getSUID()

Calculate the SerialVersionUID for a class.

getSuperclassNameback to summary
public String getSuperclassName()
getSuperclassNameIndexback to summary
public int getSuperclassNameIndex()
hasAttributeback to summary
public boolean hasAttribute(String attributeName)
isAnnotationback to summary
public final boolean isAnnotation()
isEnumback to summary
public final boolean isEnum()
removeAnnotationback to summary
public void removeAnnotation(AnnotationGen a)
removeAttributeback to summary
public void removeAttribute(Attribute a)
removeFieldback to summary
public void removeField(Field f)
removeInterfaceback to summary
public void removeInterface(String name)
removeMethodback to summary
public void removeMethod(Method m)
replaceFieldback to summary
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.

replaceMethodback to summary
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.

setClassNameback to summary
public void setClassName(String name)
setClassNameIndexback to summary
public void setClassNameIndex(int class_name_index)
setConstantPoolback to summary
public void setConstantPool(ConstantPool constant_pool)
setFieldsback to summary
public void setFields(Field[] fs)
setMajorback to summary
public void setMajor(int major)
setMethodAtback to summary
public void setMethodAt(Method method, int pos)
setMethodsback to summary
public void setMethods(Method[] methods)
setMinorback to summary
public void setMinor(int minor)
setSuperclassNameback to summary
public void setSuperclassName(String name)
setSuperclassNameIndexback to summary
public void setSuperclassNameIndex(int superclass_name_index)
org.aspectj.apache.bcel.generic back to summary

private Class ClassGen.ConstructorComparator

extends Object
implements Comparator<Method>
Class Inheritance
  • java.lang.Object
  • org.aspectj.apache.bcel.generic.ClassGen.ConstructorComparator
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(Method
the first object to be compared.
m0
,
Method
the second object to be compared.
m1
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ConstructorComparatorback to summary
private ConstructorComparator()

Method Detail

compareback to summary
public int compare(Method m0, Method m1)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
m0:Method

the first object to be compared.

m1:Method

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

org.aspectj.apache.bcel.generic back to summary

private Class ClassGen.FieldComparator

extends Object
implements Comparator<Field>
Class Inheritance
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(Field
the first object to be compared.
f0
,
Field
the second object to be compared.
f1
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FieldComparatorback to summary
private FieldComparator()

Method Detail

compareback to summary
public int compare(Field f0, Field f1)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
f0:Field

the first object to be compared.

f1:Field

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

org.aspectj.apache.bcel.generic back to summary

private Class ClassGen.MethodComparator

extends Object
implements Comparator<Method>
Class Inheritance
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(Method
the first object to be compared.
m0
,
Method
the second object to be compared.
m1
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MethodComparatorback to summary
private MethodComparator()

Method Detail

compareback to summary
public int compare(Method m0, Method m1)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
m0:Method

the first object to be compared.

m1:Method

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.