gnu.bytecode

Class ClassType

Implemented Interfaces:
AttrContainer, Externalizable
Known Direct Subclasses:
PairClassType

public class ClassType
extends ObjectType
implements AttrContainer, Externalizable

Field Summary

int
access_flags
Method
constructor
static int
major_version
static int
minor_version
static ClassType[]
noClasses

Fields inherited from class gnu.bytecode.ObjectType

flags

Fields inherited from class gnu.bytecode.Type

booleanValue_method, boolean_ctype, boolean_type, byte_type, char_type, doubleValue_method, double_type, floatValue_method, float_type, intValue_method, int_type, java_lang_Class_type, longValue_method, long_type, neverReturnsType, nullType, number_type, pointer_type, reflectClass, short_type, string_type, throwable_type, toString_method, tostring_type, typeArray0, void_type

Constructor Summary

ClassType()
ClassType(String class_name)

Method Summary

Field
addField()
Add a new field to this class.
Field
addField(String name)
Add a new field to this class, and name the field.
Field
addField(String name, Type type)
Field
addField(String name, Type type, int flags)
void
addFields()
Use reflection to add all the declared fields of this class.
void
addInterface(ClassType newInterface)
Add an interface to the list of implemented interfaces.
Method
addMethod(String name)
Method
addMethod(String name, String signature, int flags)
Method
addMethod(String name, Type[] arg_types, Type return_type, int flags)
Method
addMethod(String name, int flags)
Method
addMethod(String name, int flags, Type[] arg_types, Type return_type)
Add a method to this ClassType.
void
addMethods(Class clas)
Use reflection to add all the declared methods of this class.
int
compare(Type other)
Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common.
int
countMethods(Filter filter, int searchSupers)
Count methods matching a given filter.
void
doFixups()
Do various fixups after generating code but before we can write it out.
Attribute
getAttributes()
CpoolEntry
getConstant(int i)
ConstantPool
getConstants()
Field
getDeclaredField(String name)
Find a field with the given name declared in this class.
Method
getDeclaredMethod(String name, Type[] arg_types)
Method
getDeclaredMethod(String name, int argCount)
Get a method with matching name and number of arguments.
Method
getDeclaredMethods()
Field
getField(String name)
Find a field with the given name declared in this class or its ancestors.
int
getFieldCount()
Field
getFields()
Get the fields of this class.
ClassType[]
getInterfaces()
Method[]
getMatchingMethods(String name, Type[] paramTypes, int flags)
Method
getMethod(String name, Type[] arg_types)
Method
getMethod(java.lang.reflect.Method method)
Add a method to this ClassType.
int
getMethodCount()
Method
getMethods()
Get the methods of this class.
Method[]
getMethods(Filter filter, boolean searchSupers)
Method[]
getMethods(Filter filter, int searchSupers)
Get methods matching a given filter.
int
getMethods(Filter filter, int searchSupers, Vector result, String context)
Helper to get methods satisfying a filtering predicate.
int
getMethods(Filter filter, int searchSupers, Method[] result, int offset)
Deprecated.
int
getModifiers()
Return the modifiers (access flags) for this class.
String
getPackageName()
ClassType
getSuperclass()
boolean
implementsInterface(ClassType iface)
True if this class/interface implements the interface iface.
boolean
isAccessible(ClassType declaring, int modifiers)
Check if a component is accessible from this class.
boolean
isInterface()
boolean
isSubclass(ClassType other)
static ClassType
make(String name)
Find a ClassType with the given name, or create a new one.
static ClassType
make(String name, ClassType superClass)
void
readExternal(ObjectInput in)
Object
readResolve()
void
setAttributes(Attribute attributes)
void
setInterface(boolean val)
void
setInterfaces(ClassType[] interfaces)
void
setModifiers(int flags)
Set the modifiers (access flags) for this class.
void
setName(String name)
Sets the name of the class being defined in this classfile.
void
setSourceFile(String name)
Set the name of the SourceFile associated with this class.
void
setStratum(String stratum)
Create a SourceDebugExtAttr, if needed, and set the "stratum".
void
setSuper(String name)
Set the superclass of the is class.
void
setSuper(ClassType superClass)
String
toString()
static byte[]
to_utf8(String str)
Convert a String to a Utf8 byte array.
void
writeExternal(ObjectOutput out)
byte[]
writeToArray()
void
writeToFile()
void
writeToFile(String filename)
void
writeToStream(OutputStream stream)

Methods inherited from class gnu.bytecode.ObjectType

coerceFromObject, compare, emitCoerceFromObject, getImplementationType, getInternalName, getReflectClass, isExisting, promote, setExisting

Methods inherited from class gnu.bytecode.Type

coerceFromObject, coerceToObject, compare, emitCoerceFromObject, emitCoerceToObject, emitIsInstance, getImplementationType, getName, getReflectClass, getSignature, getSize, getType, hashCode, isInstance, isMoreSpecific, isSubtype, isValidJavaTypeName, isVoid, lookupType, lowestCommonSuperType, make, promote, registerTypeForClass, setName, setReflectClass, setSignature, signatureLength, signatureLength, signatureToName, signatureToPrimitive, signatureToType, signatureToType, swappedCompareResult, toString

Field Details

access_flags

public int access_flags

constructor

public Method constructor

major_version

public static final int major_version
Field Value:
45

minor_version

public static final int minor_version
Field Value:
3

noClasses

public static final ClassType[] noClasses

Constructor Details

ClassType

public ClassType()

ClassType

public ClassType(String class_name)

Method Details

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,
                        String signature,
                        int flags)

addMethod

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

addMethod

public Method addMethod(String name,
                        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.

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().

compare

public int compare(Type other)
Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common. "Same member" is rather loose; by "A is a subtype of B" we mean that all instance of A can be "widened" to B. More formally, A.compare(B) returns: 1: all B values can be converted to A without a coercion failure (i.e. a ClassCastException or overflow or major loss of information), but not vice versa. 0: all A values can be converted to B without a coercion failure and vice versa; -1: all A values can be converted to B without a coercion failure not not vice versa; -2: there are (potentially) some A values that can be converted to B, and some B values can be converted to A; -3: there are no A values that can be converted to B, and neither are there any B values that can be converted to A.
Overrides:
compare in interface ObjectType

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()
Specified by:
getAttributes in interface AttrContainer

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)

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)
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(String name,
                        Type[] arg_types)

getMethod

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

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,
                      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 search
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

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 search
result - array to place selected methods in
offset - start of where in result to place result
Returns:
number of methods placed in result array

getModifiers

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

getPackageName

public String getPackageName()

getSuperclass

public ClassType getSuperclass()

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(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)
            throws IOException,
                   ClassNotFoundException

readResolve

public Object readResolve()
            throws ObjectStreamException

setAttributes

public final void setAttributes(Attribute attributes)
Specified by:
setAttributes in interface AttrContainer

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.
Overrides:
setName in interface Type
Parameters:
name - the name to give to the 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()
Overrides:
toString in interface Type

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)
            throws IOException

writeToArray

public byte[] writeToArray()

writeToFile

public void writeToFile()
            throws java.io.IOException

writeToFile

public void writeToFile(String filename)
            throws java.io.IOException

writeToStream

public void writeToStream(OutputStream stream)
            throws java.io.IOException