public class ClassType extends ObjectType implements AttrContainer, java.io.Externalizable, Member
Type.NeverReturns
Modifier and Type | Field and Description |
---|---|
Method |
constructor |
static int |
JAVA_10_VERSION |
static int |
JAVA_9_VERSION |
static int |
JDK_1_1_VERSION |
static int |
JDK_1_2_VERSION |
static int |
JDK_1_3_VERSION |
static int |
JDK_1_4_VERSION |
static int |
JDK_1_5_VERSION |
static int |
JDK_1_6_VERSION |
static int |
JDK_1_7_VERSION |
static int |
JDK_1_8_VERSION |
static ClassType[] |
noClasses |
flags
boolean_ctype, boolean_type, booleanType, booleanValue_method, byte_type, byteType, char_type, charType, clone_method, double_type, doubleType, doubleValue_method, errorType, float_type, floatType, floatValue_method, int_type, intType, intValue_method, java_lang_Class_type, javalangannotationAnnotationType, javalangBooleanType, javalangCharacterType, javalangClassType, javalanginvokeMethodHandleType, javalangNumberType, javalangObjectType, javalangStringType, javalangThrowableType, long_type, longType, longValue_method, neverReturnsType, nullType, number_type, objectType, pointer_type, reflectClass, short_type, shortType, string_type, throwable_type, toString_method, tostring_type, toStringType, typeArray0, void_type, voidType
Constructor and Description |
---|
ClassType() |
ClassType(java.lang.String class_name) |
Modifier and Type | Method and Description |
---|---|
Field |
addField()
Add a new field to this class.
|
Field |
addField(java.lang.String name)
Add a new field to this class, and name the field.
|
Field |
addField(java.lang.String name,
Type type) |
Field |
addField(java.lang.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.
|
void |
addMemberClass(ClassType member) |
void |
addMemberClasses() |
Method |
addMethod(java.lang.reflect.Constructor method) |
Method |
addMethod(java.lang.reflect.Method method) |
Method |
addMethod(java.lang.String name) |
Method |
addMethod(java.lang.String name,
int flags) |
Method |
addMethod(java.lang.String name,
int flags,
Type[] arg_types,
Type return_type)
Add a method to this ClassType.
|
Method |
addMethod(java.lang.String name,
java.lang.String signature,
int flags) |
Method |
addMethod(java.lang.String name,
Type[] arg_types,
Type return_type,
int flags) |
void |
addMethods(java.lang.Class clas)
Use reflection to add all the declared methods of this class.
|
void |
addModifiers(int flags) |
Method |
checkSingleAbstractMethod()
Check to see if this is a Single Abstract Method (SAM) type.
|
void |
cleanupAfterCompilation()
Clear various object references, to help garbage collection.
|
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.
|
Method[] |
getAbstractMethods() |
ClassType[] |
getAllInterfaces()
Get all the interfaces this class implements.
|
<T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.Class<T> clas) |
Attribute |
getAttributes()
Get the (first) Attribute of this container.
|
short |
getClassfileMajorVersion() |
short |
getClassfileMinorVersion() |
int |
getClassfileVersion() |
CpoolEntry |
getConstant(int i) |
ConstantPool |
getConstants() |
ClassType |
getDeclaredClass(java.lang.String simpleName) |
Field |
getDeclaredField(java.lang.String name)
Find a field with the given name declared in this class.
|
Method |
getDeclaredMethod(java.lang.String name,
int argCount)
Get a method with matching name and number of arguments.
|
Method |
getDeclaredMethod(java.lang.String name,
Type[] arg_types)
Look for a matching method.
|
Method |
getDeclaredMethods() |
Method |
getDeclaredStaticMethod(java.lang.String name,
int argCount)
Get a static method with matching name and number of arguments.
|
ClassType |
getDeclaringClass() |
Method |
getDefaultConstructor() |
Member |
getEnclosingMember() |
Field |
getField(java.lang.String name)
Find a field with the given name declared in this class or its ancestors.
|
Field |
getField(java.lang.String name,
int mask)
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(java.lang.String name,
Type[] paramTypes,
int flags) |
Method |
getMethod(java.lang.reflect.Method method)
Add a method to this ClassType.
|
Method |
getMethod(java.lang.String name,
Type[] arg_types)
Looks for a method matching the name and types.
|
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,
java.util.List<Method> result)
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.
|
ClassType |
getOuterLinkType() |
java.lang.String |
getPackageName() |
java.lang.String |
getSimpleName() |
boolean |
getStaticFlag() |
ClassType |
getSuperclass() |
TypeVariable[] |
getTypeParameters() |
boolean |
hasOuterLink() |
boolean |
implementsInterface(ClassType iface)
True if this class/interface implements the interface iface.
|
static boolean |
isAccessible(ClassType caller,
ClassType declaring,
ObjectType receiver,
int modifiers)
Check if a component is accessible from this class.
|
boolean |
isAccessible(Member member,
ObjectType receiver)
Check if a member is accessible from this class.
|
boolean |
isAnnotation() |
int |
isCompatibleWithValue(Type valueType)
If this is the target type, is a given source type compatible?
|
boolean |
isFinal() |
boolean |
isInterface() |
boolean |
isSubclass(ClassType other) |
boolean |
isSubclass(java.lang.String cname)
A more efficient version of isSubclass(ClassType.make(cname)).
|
static ClassType |
make(java.lang.String name)
Find a ClassType with the given name, or create a new one.
|
static ClassType |
make(java.lang.String name,
ClassType superClass)
Deprecated.
|
static java.lang.String |
nameToSignature(java.lang.String name) |
void |
readExternal(java.io.ObjectInput in) |
java.lang.Object |
readResolve() |
void |
removeField(Field field,
Field prev) |
void |
setAttributes(Attribute attributes)
Set the (list of) Attributes of this container.
|
void |
setClassfileVersion(int code) |
void |
setClassfileVersion(int major,
int minor) |
void |
setClassfileVersionJava5() |
void |
setEnclosingMember(Member member) |
void |
setInterface(boolean val) |
void |
setInterfaces(ClassType[] interfaces) |
void |
setModifiers(int flags)
Set the modifiers (access flags) for this class.
|
void |
setName(java.lang.String name)
Sets the name of the class being defined in this classfile.
|
Field |
setOuterLink(ClassType outer)
Note that this class needs an other link ("this$0") field.
|
void |
setSourceFile(java.lang.String name)
Set the name of the SourceFile associated with this class.
|
void |
setStratum(java.lang.String stratum)
Create a
SourceDebugExtAttr , if needed, and
set the "stratum". |
void |
setSuper(ClassType superClass) |
void |
setSuper(java.lang.String name)
Set the superclass of the is class.
|
static byte[] |
to_utf8(java.lang.String str)
Convert a String to a Utf8 byte array.
|
java.lang.String |
toString() |
void |
writeExternal(java.io.ObjectOutput out) |
byte[] |
writeToArray() |
void |
writeToFile() |
void |
writeToFile(java.lang.String filename) |
void |
writeToStream(java.io.OutputStream stream) |
coerceFromObject, emitCoerceFromObject, getContextClass, getContextClassLoader, getInternalName, getMethods, getReflectClass, isExisting, isInstance, setExisting
coerceToObject, emitCoerceToObject, emitConvertFromPrimitive, emitIsInstance, getGenericSignature, getImplementationType, getMaybeGenericSignature, getName, getRawType, getRealType, getSignature, getSize, getSizeInWords, getType, hashCode, isCompatibleWithValue, isMoreSpecific, isSame, isSubtype, isValidJavaTypeName, isVoid, lookupType, lowestCommonSharedType, lowestCommonSuperType, make, make, printSignature, promote, promoteIfUnsigned, registerTypeForClass, setGenericSignature, setReflectClass, setSignature, signatureLength, signatureLength, signatureToName, signatureToPrimitive, signatureToType, signatureToType, swappedCompareResult
public static final int JDK_1_1_VERSION
public static final int JDK_1_2_VERSION
public static final int JDK_1_3_VERSION
public static final int JDK_1_4_VERSION
public static final int JDK_1_5_VERSION
public static final int JDK_1_6_VERSION
public static final int JDK_1_7_VERSION
public static final int JDK_1_8_VERSION
public static final int JAVA_9_VERSION
public static final int JAVA_10_VERSION
public static final ClassType[] noClasses
public Method constructor
public ClassType()
public ClassType(java.lang.String class_name)
public short getClassfileMajorVersion()
public short getClassfileMinorVersion()
public void setClassfileVersion(int major, int minor)
public void setClassfileVersion(int code)
public int getClassfileVersion()
public void setClassfileVersionJava5()
public static ClassType make(java.lang.String name)
name
- the name of the class (e..g. "java.lang.String").@Deprecated public static ClassType make(java.lang.String name, ClassType superClass)
public final Attribute getAttributes()
AttrContainer
getAttributes
in interface AttrContainer
public final void setAttributes(Attribute attributes)
AttrContainer
setAttributes
in interface AttrContainer
public final ConstantPool getConstants()
getConstants
in interface AttrContainer
public final CpoolEntry getConstant(int i)
public final int getModifiers()
getModifiers
in interface Member
public final boolean getStaticFlag()
getStaticFlag
in interface Member
public final void setModifiers(int flags)
public final void addModifiers(int flags)
public java.lang.String getSimpleName()
public void addMemberClass(ClassType member)
public ClassType getDeclaredClass(java.lang.String simpleName)
public ClassType getDeclaringClass()
getDeclaringClass
in interface Member
public Member getEnclosingMember()
public void setEnclosingMember(Member member)
public void addMemberClasses()
public final boolean hasOuterLink()
public ClassType getOuterLinkType()
public final Field setOuterLink(ClassType outer)
"<init>"
methods to take the extra
implicit parameter.outer
- the outer classpublic boolean isAccessible(Member member, ObjectType receiver)
member
- the member (Field, Method) we're trting to access.receiver
- the type of the receiver object, if applicable.public static boolean isAccessible(ClassType caller, ClassType declaring, ObjectType receiver, int modifiers)
caller
- the class containing the calling method,
or null if unspecified classdeclaring
- the class containing the component (a field, method,
or inner class)receiver
- the type of the receiver object, if applicable.modifiers
- the access flags of the componentpublic void setName(java.lang.String name)
public static java.lang.String nameToSignature(java.lang.String name)
public void setStratum(java.lang.String stratum)
SourceDebugExtAttr
, if needed, and
set the "stratum". The stratum is typically a programming language
such as "JSP", "Scheme", or "Java" (the default).public void setSourceFile(java.lang.String name)
public TypeVariable[] getTypeParameters()
public void setSuper(java.lang.String name)
name
- name of super class, or null if this is "Object".public void setSuper(ClassType superClass)
public ClassType getSuperclass()
getSuperclass
in class ObjectType
public java.lang.String getPackageName()
public ClassType[] getInterfaces()
getInterfaces
in class ObjectType
public ClassType[] getAllInterfaces()
public void setInterfaces(ClassType[] interfaces)
public void addInterface(ClassType newInterface)
public final boolean isInterface()
isInterface
in class Type
public final void setInterface(boolean val)
public final boolean isFinal()
public final boolean isAnnotation()
public final Field getFields()
public final int getFieldCount()
public Field getDeclaredField(java.lang.String name)
public Field getField(java.lang.String name, int mask)
getField
in class ObjectType
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.public Field getField(java.lang.String name)
public Field addField()
public Field addField(java.lang.String name)
name
- the name of the new fieldpublic void addFields()
public final Method getMethods()
public final int getMethodCount()
public Method addMethod(java.lang.String name)
public Method addMethod(java.lang.String name, int flags)
public Method addMethod(java.lang.String name, Type[] arg_types, Type return_type, int flags)
public Method addMethod(java.lang.String name, int flags, Type[] arg_types, Type return_type)
public Method addMethod(java.lang.reflect.Method method)
public Method addMethod(java.lang.reflect.Constructor method)
public Method addMethod(java.lang.String name, java.lang.String signature, int flags)
public Method getMethod(java.lang.reflect.Method method)
public final Method getDeclaredMethods()
public final int countMethods(Filter filter, int searchSupers)
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 searchedpublic Method[] getMethods(Filter filter, int searchSupers)
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@Deprecated public int getMethods(Filter filter, int searchSupers, Method[] result, int offset)
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 resultpublic int getMethods(Filter filter, int searchSupers, java.util.List<Method> result)
getMethods
in class 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
- List to add selected methods inpublic Method[] getAbstractMethods()
public Method getDeclaredMethod(java.lang.String name, Type[] arg_types)
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.public Method getDeclaredMethod(java.lang.String name, int argCount)
public Method getDeclaredStaticMethod(java.lang.String name, int argCount)
public Method getMethod(java.lang.String name, Type[] arg_types)
getMethod
in class ObjectType
public Method getDefaultConstructor()
public void addMethods(java.lang.Class clas)
clas
- should be the same as getReflectClass().public Method[] getMatchingMethods(java.lang.String name, Type[] paramTypes, int flags)
public <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<T> clas)
getAnnotation
in interface Member
public void doFixups()
public void writeToStream(java.io.OutputStream stream) throws java.io.IOException
java.io.IOException
public void writeToFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public void writeToFile() throws java.io.IOException
java.io.IOException
public byte[] writeToArray()
public static byte[] to_utf8(java.lang.String str)
str
- the input String.public final boolean implementsInterface(ClassType iface)
public final boolean isSubclass(java.lang.String cname)
cname
- a class name - cannot be an interface namepublic final boolean isSubclass(ClassType other)
public int isCompatibleWithValue(Type valueType)
Type
isCompatibleWithValue
in class Type
public int compare(Type other)
Type
compare
in class ObjectType
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
public java.lang.Object readResolve() throws java.io.ObjectStreamException
java.io.ObjectStreamException
public void cleanupAfterCompilation()
public Method checkSingleAbstractMethod()