class Type extends Object
Modifier and Type | Field and Description |
---|---|
static Type |
ANY
The "any" type (denotes wild expressions).
|
static Type |
BOOLEAN
The primitive type, boolean.
|
static Type |
BOXED_BOOLEAN
java.lang.Boolean.
|
static Type |
BOXED_CHAR
java.lang.Character.
|
static Type |
BOXED_INT
java.lang.Integer.
|
static Type |
CHAR
The primitive type, char.
|
static Type |
CONSTRUCTOR
A type marker indicating a constructor (having no return type).
|
static Type |
INT
The primitive type, int.
|
static Type |
NULLTYPE
The null void.
|
static Type |
OBJECT
The type java.lang.Object.
|
static Type |
STRING
The type java.lang.String.
|
static Type |
VOID
The void type.
|
Modifier | Constructor and Description |
---|---|
protected |
Type()
This constructor is to keep the compiler happy.
|
Modifier and Type | Method and Description |
---|---|
ArrayList<Method> |
abstractMethods()
Return a list of this class' abstract methods? It does has abstract
methods if (1) Any method declared in the class is abstract, or (2) Its
superclass has an abstract method which is not overridden here.
|
static String |
argTypesAsString(Type[] argTypes)
Convert an array of argument types to a string representation of a
parenthesized list of the types, eg, (int, boolean, java.lang.String).
|
static boolean |
argTypesMatch(Class<?>[] argTypes1,
Class<?>[] argTypes2)
Do argument types match? A helper used for finding candidate methods and
constructors.
|
String |
argumentTypeForAppend()
The String representation for a type being appended to a StringBuffer for
+ and += over strings.
|
static boolean |
checkAccess(int line,
Class referencingType,
Class type)
Check the accessibility of a type.
|
boolean |
checkAccess(int line,
Member member)
Check the accessibility of a member from this type (that is, this type is
the referencing type).
|
boolean |
checkAccess(int line,
Type targetType)
Check the accesibility of a target type (from this type)
|
Class<?> |
classRep()
Return the class representation for a type, appropriate for dealing with
the Java reflection API.
|
Type |
componentType()
An array type's component type.
|
Constructor |
constructorFor(Type[] argTypes)
Find an appropriate constructor in this type, given it's argument types.
|
boolean |
equals(Type that)
Type equality is based on the equality of descriptors.
|
Field |
fieldFor(String name)
Return the Field having this name.
|
boolean |
isAbstract()
Is this type declared abstract?
|
boolean |
isArray()
Is this an Array type?
|
boolean |
isFinal()
Is this type declared final?
|
boolean |
isInterface()
Is this an interface type?
|
boolean |
isJavaAssignableFrom(Type that)
Is this a supertype of that?
|
boolean |
isPrimitive()
Is this a primitive type?
|
boolean |
isReference()
Is this a reference type?
|
String |
jvmName()
The JVM representation for this type's name.
|
boolean |
matchesExpected(Type expected)
Does this type match the expected type? For now, "matches" means
"equals".
|
Method |
methodFor(String name,
Type[] argTypes)
Find an appropriate method in this type, given a message (method) name
and it's argument types.
|
void |
mustMatchExpected(int line,
Type expectedType)
An assertion that this type matches the specified type.
|
void |
mustMatchOneOf(int line,
Type... expectedTypes)
An assertion that this type matches one of the specified types.
|
String |
packageName()
Return the type's package name.
|
Type |
resolve(Context context)
Resolve this type in the given context.
|
void |
setClassRep(Class<?> classRep)
This setter is used by JCompilationUnit.preAnalyze() to set the classRep
to the specified partial class, computed during pre-analysis.
|
static String |
signatureFor(String name,
Type[] argTypes)
A helper for constructing method signatures for reporting unfound methods
and constructors.
|
String |
simpleName()
Return the simple (unqualified) name for this Type.
|
Type |
superClass()
Return the Type's super type (or null if there is none).
|
String |
toDescriptor()
The JVM descriptor for this type.
|
String |
toString()
A printable (j--) string representation of this type.
|
static Type |
typeFor(Class<?> classRep)
Construct a Type representation for a type from its (Java) Class
representation.
|
public static final Type INT
public static final Type CHAR
public static final Type BOOLEAN
public static final Type BOXED_INT
public static final Type BOXED_CHAR
public static final Type BOXED_BOOLEAN
public static Type STRING
public static Type OBJECT
public static final Type VOID
public static final Type NULLTYPE
public static final Type CONSTRUCTOR
public static final Type ANY
public static Type typeFor(Class<?> classRep)
classRep
- the Java representation.public Class<?> classRep()
public void setClassRep(Class<?> classRep)
classRep
- the partial class.public boolean equals(Type that)
that
- the other Type.public boolean isArray()
public Type componentType()
public Type superClass()
public boolean isPrimitive()
public boolean isInterface()
public boolean isReference()
public boolean isFinal()
public boolean isAbstract()
public boolean isJavaAssignableFrom(Type that)
that
- the candidate subtype.public ArrayList<Method> abstractMethods()
public void mustMatchOneOf(int line, Type... expectedTypes)
line
- the line near which the mismatch occurs.expectedTypes
- expected types.public void mustMatchExpected(int line, Type expectedType)
line
- the line near which the mismatch occurs.expectedType
- type with which to match.public boolean matchesExpected(Type expected)
expected
- the type that this might match.public static boolean argTypesMatch(Class<?>[] argTypes1, Class<?>[] argTypes2)
argTypes1
- arguments (classReps) of one method.argTypes2
- arguments (classReps) of another method.public String simpleName()
public String toString()
public String toDescriptor()
public String jvmName()
public String packageName()
public String argumentTypeForAppend()
public Method methodFor(String name, Type[] argTypes)
name
- the method name.argTypes
- the argument types.public Constructor constructorFor(Type[] argTypes)
argTypes
- the argument types.public Field fieldFor(String name)
name
- the name of the field we want.public static String argTypesAsString(Type[] argTypes)
argTypes
- the array of argument types.public boolean checkAccess(int line, Member member)
line
- the line in which the access occurs.member
- the member being accessed.public boolean checkAccess(int line, Type targetType)
line
- line in which the access occurs.targetType
- the type being accessed.public static boolean checkAccess(int line, Class referencingType, Class type)
line
- the line in which the access occurs.referencingType
- the type attempting the access.type
- the type that we want to access.public Type resolve(Context context)
context
- context in which the names are resolved.