gnu.bytecode

Class ClassType

public class ClassType extends ObjectType implements AttrContainer, Externalizable

Field Summary
intaccess_flags
Methodconstructor
static ClassType[]noClasses
Constructor Summary
ClassType()
ClassType(String class_name)
Method Summary
FieldaddField()
Add a new field to this class.
FieldaddField(String name)
Add a new field to this class, and name the field.
FieldaddField(String name, Type type)
FieldaddField(String name, Type type, int flags)
voidaddFields()
Use reflection to add all the declared fields of this class.
voidaddInterface(ClassType newInterface)
Add an interface to the list of implemented interfaces.
MethodaddMethod(String name)
MethodaddMethod(String name, int flags)
MethodaddMethod(String name, Type[] arg_types, Type return_type, int flags)
MethodaddMethod(String name, int flags, Type[] arg_types, Type return_type)
Add a method to this ClassType.
MethodaddMethod(String name, String signature, int flags)
voidaddMethods(Class clas)
Use reflection to add all the declared methods of this class.
voidcleanupAfterCompilation()
Clear various object references, to help garbage collection.
intcompare(Type other)
intcountMethods(Filter filter, int searchSupers)
Count methods matching a given filter.
voiddoFixups()
Do various fixups after generating code but before we can write it out.
AttributegetAttributes()
shortgetClassfileMajorVersion()
shortgetClassfileMinorVersion()
CpoolEntrygetConstant(int i)
ConstantPoolgetConstants()
FieldgetDeclaredField(String name)
Find a field with the given name declared in this class.
MethodgetDeclaredMethod(String name, Type[] arg_types)
Look for a matching method.
MethodgetDeclaredMethod(String name, int argCount)
Get a method with matching name and number of arguments.
MethodgetDeclaredMethods()
FieldgetField(String name, int mask)
Find a field with the given name declared in this class or its ancestors.
FieldgetField(String name)
Find a field with the given name declared in this class or its ancestors.
intgetFieldCount()
FieldgetFields()
Get the fields of this class.
ClassType[]getInterfaces()
Method[]getMatchingMethods(String name, Type[] paramTypes, int flags)
MethodgetMethod(Method method)
Add a method to this ClassType.
MethodgetMethod(String name, Type[] arg_types)
intgetMethodCount()
MethodgetMethods()
Get the methods of this class.
Method[]getMethods(Filter filter, boolean searchSupers)
Method[]getMethods(Filter filter, int searchSupers)
Get methods matching a given filter.
intgetMethods(Filter filter, int searchSupers, Method[] result, int offset)
Helper to get methods satisfying a filtering predicate.
intgetMethods(Filter filter, int searchSupers, Vector result, String context)
Helper to get methods satisfying a filtering predicate.
intgetModifiers()
Return the modifiers (access flags) for this class.
ClassTypegetOuterLinkType()
StringgetPackageName()
ClassTypegetSuperclass()
booleanhasOuterLink()
booleanimplementsInterface(ClassType iface)
True if this class/interface implements the interface iface.
booleanisAccessible(ClassType declaring, int modifiers)
Check if a component is accessible from this class.
booleanisInterface()
booleanisSubclass(String cname)
A more efficient version of isSubclass(ClassType.make(cname)).
booleanisSubclass(ClassType other)
static ClassTypemake(String name)
Find a ClassType with the given name, or create a new one.
static ClassTypemake(String name, ClassType superClass)
voidreadExternal(ObjectInput in)
ObjectreadResolve()
voidsetAttributes(Attribute attributes)
voidsetClassfileVersion(int major, int minor)
voidsetClassfileVersionJava5()
voidsetInterface(boolean val)
voidsetInterfaces(ClassType[] interfaces)
voidsetModifiers(int flags)
Set the modifiers (access flags) for this class.
voidsetName(String name)
Sets the name of the class being defined in this classfile.
FieldsetOuterLink(ClassType outer)
Note that this class needs an other link ("this$0") field.
voidsetSourceFile(String name)
Set the name of the SourceFile associated with this class.
voidsetStratum(String stratum)
Create a SourceDebugExtAttr, if needed, and set the "stratum".
voidsetSuper(String name)
Set the superclass of the is class.
voidsetSuper(ClassType superClass)
StringtoString()
static byte[]to_utf8(String str)
Convert a String to a Utf8 byte array.
voidwriteExternal(ObjectOutput out)
byte[]writeToArray()
voidwriteToFile(String filename)
voidwriteToFile()
voidwriteToStream(OutputStream stream)

Field Detail

access_flags

public int access_flags

constructor

public Method constructor

noClasses

public static final ClassType[] noClasses

Constructor Detail

ClassType

public ClassType()

ClassType

public ClassType(String class_name)

Method Detail

addField

public Field addField()
Add a new field to this class.

addField

public Field addField(String name)
Add a new field to this class, and name the field.

Parameters: name the name of the new field

addField

public final Field addField(String name, Type type)

addField

public final Field addField(String name, Type type, int flags)

addFields

public void addFields()
Use reflection to add all the declared fields of this class. Does not add private or package-private fields. Does not check for duplicate (already-known) fields. Is not thread-safe if another thread may access this ClassType.

addInterface

public void addInterface(ClassType newInterface)
Add an interface to the list of implemented interfaces.

addMethod

public Method addMethod(String name)

addMethod

public Method addMethod(String name, int flags)

addMethod

public Method addMethod(String name, Type[] arg_types, Type return_type, int flags)

addMethod

public Method addMethod(String name, int flags, Type[] arg_types, Type return_type)
Add a method to this ClassType. If an existing method matches, return that. Otherwise, create a new one. In contrast, the other addMethod methods always create new Methods.

addMethod

public Method addMethod(String name, String signature, int flags)

addMethods

public void addMethods(Class clas)
Use reflection to add all the declared methods of this class. Does not add constructors nor private or package-private methods. Does not check for duplicate (already-known) methods.

Parameters: clas should be the same as getReflectClass().

cleanupAfterCompilation

public void cleanupAfterCompilation()
Clear various object references, to help garbage collection.

compare

public int compare(Type other)

countMethods

public final int countMethods(Filter filter, int searchSupers)
Count methods matching a given filter.

Parameters: filter to select methods to return searchSupers 0 if only current class should be searched, 1 if superclasses should also be searched, 2 if super-interfaces should also be search

Returns: number of methods that match

doFixups

public void doFixups()
Do various fixups after generating code but before we can write it out. This includes assigning constant pool indexes where needed, finalizing labels, etc.

getAttributes

public final Attribute getAttributes()

getClassfileMajorVersion

public short getClassfileMajorVersion()

getClassfileMinorVersion

public short getClassfileMinorVersion()

getConstant

public final CpoolEntry getConstant(int i)

getConstants

public final ConstantPool getConstants()

getDeclaredField

public Field getDeclaredField(String name)
Find a field with the given name declared in this class.

Returns: the matching field, or null if there is no such field.

getDeclaredMethod

public Method getDeclaredMethod(String name, Type[] arg_types)
Look for a matching method.

Parameters: name method name arg_types parameter types that must match. Can also be null, to match any parameter type list. Otherwise, an element of arg_types must be the same type (equals), though a null element of arg_types is a wildcard that matches any type.

getDeclaredMethod

public Method getDeclaredMethod(String name, int argCount)
Get a method with matching name and number of arguments.

getDeclaredMethods

public final Method getDeclaredMethods()

getField

public Field getField(String name, int mask)
Find a field with the given name declared in this class or its ancestors.

Parameters: name the name of the field. mask of match a field whose modifiers has one of these bits set. Howeve, if mask is -1, ignore the access flags.

Returns: the matching field, or null if there is no such field.

getField

public Field getField(String name)
Find a field with the given name declared in this class or its ancestors.

Returns: the matching field, or null if there is no such field.

getFieldCount

public final int getFieldCount()

getFields

public final Field getFields()
Get the fields of this class.

getInterfaces

public ClassType[] getInterfaces()

Returns: the interfaces this class is declared to implement (not those inherited from its superclass/superinterfaces).

getMatchingMethods

public Method[] getMatchingMethods(String name, Type[] paramTypes, int flags)

getMethod

public Method getMethod(Method method)
Add a method to this ClassType. If an existing method matches, return that. Otherwise, create a new one.

getMethod

public Method getMethod(String name, Type[] arg_types)

getMethodCount

public final int getMethodCount()

getMethods

public final Method getMethods()
Get the methods of this class.

getMethods

public Method[] getMethods(Filter filter, boolean searchSupers)

getMethods

public Method[] getMethods(Filter filter, int searchSupers)
Get methods matching a given filter.

Parameters: filter to select methods to return searchSupers 0 if only current class should be searched, 1 if superclasses should also be searched, 2 if super-interfaces should also be searched

Returns: a fresh array containing the methods satisfying the filter

getMethods

public int getMethods(Filter filter, int searchSupers, Method[] result, int offset)

Deprecated:

Helper to get methods satisfying a filtering predicate.

Parameters: filter to select methods to return searchSupers 0 if only current class should be searched, 1 if superclasses should also be searched, 2 if super-interfaces should also be searched result array to place selected methods in offset start of where in result to place result

Returns: number of methods placed in result array

getMethods

public int getMethods(Filter filter, int searchSupers, Vector result, String context)
Helper to get methods satisfying a filtering predicate.

Parameters: filter to select methods to return searchSupers 0 if only current class should be searched, 1 if superclasses should also be searched, 2 if super-interfaces should also be searched result Vector to add selected methods in context If non-null, skip if class not visible in named package.

Returns: number of methods placed in result array

getModifiers

public final int getModifiers()
Return the modifiers (access flags) for this class.

getOuterLinkType

public ClassType getOuterLinkType()

getPackageName

public String getPackageName()

getSuperclass

public ClassType getSuperclass()

hasOuterLink

public final boolean hasOuterLink()

implementsInterface

public final boolean implementsInterface(ClassType iface)
True if this class/interface implements the interface iface.

isAccessible

public boolean isAccessible(ClassType declaring, int modifiers)
Check if a component is accessible from this class.

Parameters: declaring the class containing the component (a field, method, or inner class) modifiers the access flags of the component

Returns: true if the specified component can be accessed from this class.

isInterface

public final boolean isInterface()

isSubclass

public final boolean isSubclass(String cname)
A more efficient version of isSubclass(ClassType.make(cname)). Does not cause the named class be loaded if it hasn't been.

Parameters: cname a class name - cannot be an interface name

isSubclass

public final boolean isSubclass(ClassType other)

make

public static ClassType make(String name)
Find a ClassType with the given name, or create a new one. Use this for "library classes", where you need the field/method types, but not one where you are about to generate code for.

Parameters: name the name of the class (e..g. "java.lang.String").

make

public static ClassType make(String name, ClassType superClass)

readExternal

public void readExternal(ObjectInput in)

readResolve

public Object readResolve()

setAttributes

public final void setAttributes(Attribute attributes)

setClassfileVersion

public void setClassfileVersion(int major, int minor)

setClassfileVersionJava5

public void setClassfileVersionJava5()

setInterface

public final void setInterface(boolean val)

setInterfaces

public void setInterfaces(ClassType[] interfaces)

setModifiers

public final void setModifiers(int flags)
Set the modifiers (access flags) for this class.

setName

public void setName(String name)
Sets the name of the class being defined in this classfile.

Parameters: name the name to give to the class

setOuterLink

public final Field setOuterLink(ClassType outer)
Note that this class needs an other link ("this$0") field. This is only allowed if !isExisting(). Adjust any existing "" methods to take the extra implicit parameter.

Parameters: outer the outer class

setSourceFile

public void setSourceFile(String name)
Set the name of the SourceFile associated with this class.

setStratum

public void setStratum(String stratum)
Create a SourceDebugExtAttr, if needed, and set the "stratum". The stratum is typically a programming language such as "JSP", "Scheme", or "Java" (the default).

setSuper

public void setSuper(String name)
Set the superclass of the is class.

Parameters: name name of super class, or null if this is "Object".

setSuper

public void setSuper(ClassType superClass)

toString

public String toString()

to_utf8

public static byte[] to_utf8(String str)
Convert a String to a Utf8 byte array.

Parameters: str the input String.

Returns: the input encoded as a utf8 byte array.

writeExternal

public void writeExternal(ObjectOutput out)

Serial Data: Write the class name (as given by getName()) using writeUTF.

writeToArray

public byte[] writeToArray()

writeToFile

public void writeToFile(String filename)

writeToFile

public void writeToFile()

writeToStream

public void writeToStream(OutputStream stream)