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.
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.
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)
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.
- compare in interface ObjectType
countMethods
public final int countMethods(Filter filter,
int searchSupers)
Count methods matching a given filter.
filter
- to select methods to returnsearchSupers
- 0 if only current class should be searched,
1 if superclasses should also be searched,
2 if super-interfaces should also be search
- 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.
getClassfileMajorVersion
public short getClassfileMajorVersion()
getClassfileMinorVersion
public short getClassfileMinorVersion()
getConstant
public final CpoolEntry getConstant(int i)
getDeclaredField
public Field getDeclaredField(String name)
Find a field with the given name declared in this class.
- 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.
name
- method namearg_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)
Find a field with the given name declared in this class or its ancestors.
- the matching field, or null if there is no such field.
getField
public Field getField(String name,
int mask)
Find a field with the given name declared in this class or its ancestors.
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.
- 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()
- 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.
filter
- to select methods to returnsearchSupers
- 0 if only current class should be searched,
1 if superclasses should also be searched,
2 if super-interfaces should also be searched
- 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.
- getMethods in interface ObjectType
filter
- to select methods to returnsearchSupers
- 0 if only current class should be searched,
1 if superclasses should also be searched,
2 if super-interfaces should also be searchedresult
- Vector to add selected methods incontext
- If non-null, skip if class not visible in named package.
- number of methods placed in result array
getMethods
public int getMethods(Filter filter,
int searchSupers,
Method[] result,
int offset)
Helper to get methods satisfying a filtering predicate.
filter
- to select methods to returnsearchSupers
- 0 if only current class should be searched,
1 if superclasses should also be searched,
2 if super-interfaces should also be searchedresult
- array to place selected methods inoffset
- start of where in result to place result
- 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.
declaring
- the class containing the component (a field, method,
or inner class)modifiers
- the access flags of the component
- 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.
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.
name
- the name of the class (e..g. "java.lang.String").
readExternal
public void readExternal(ObjectInput in)
throws IOException,
ClassNotFoundException
readResolve
public Object readResolve()
throws ObjectStreamException
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.
- setName in interface Type
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.
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.
name
- name of super class, or null if this is "Object".
setSuper
public void setSuper(ClassType superClass)
to_utf8
public static byte[] to_utf8(String str)
Convert a String to a Utf8 byte array.
- 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