|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjparse.Type
Information on a Java type. This is either a
SourceType
object from the Java parser or a
CompiledType
object representing a compiled
class. The static members of this class provide a type caching and
lookup service.
Field Summary | |
static CompiledType |
booleanType
The boolean type |
static CompiledType |
byteType
The byte type |
static CompiledType |
charType
The char type |
private static String[] |
classPath
The classpath to use for finding classes |
static CompiledType |
doubleType
The double type |
static CompiledType |
floatType
The float type |
static CompiledType |
intType
The int type |
static CompiledType |
longType
The long type |
protected static HashMap |
map
A mapping from fully qualified names to Type objects |
static CompiledType |
objectType
The object type |
private static HashMap |
parsedMap
A mapping from File objects to FileAST
objects |
protected static HashMap |
pkgMap
A mapping from package names to File objects |
static CompiledType |
shortType
The short type |
static CompiledType |
stringType
The string type |
static CompiledType |
voidType
The void type |
Constructor Summary | |
Type()
|
Method Summary | |
static Type |
arithType(Type t1,
Type t2)
Determine the type of the result of arithmetic on two types, using the rules for Java type promotion |
protected static String |
demangle(String name)
Demangle an internal JVM fully qualified name to a Java source fully qualified name |
abstract void |
dump()
Dump information about this type to standard error |
static boolean |
exists(String className)
Determine whether a fully qualified name corresponds to a class |
private static void |
explodeString(String s,
char c,
ArrayList list)
Break up a string by finding the location of a certain character, and add the constituent parts to a list, if they are not already there |
private static File |
findFile(String name,
boolean source)
Find a file in the classpath. |
static Type |
forClass(Class theClass)
Find a type based on a class. |
static Type |
forName(String className)
Find a type based on its name. |
abstract Type |
getArrayType()
Get the type that corresponds to an array of this type |
abstract Type[] |
getClasses()
Returns an array containing Type objects representing all
the classes and interfaces that are members of this type. |
abstract Type |
getComponentType()
Get the component type of an array, or return null if this
type does not represent an array |
abstract Constructor |
getConstructor(Type[] params,
Type caller)
Get an object representing the constructor for this class with the specified parameter types |
abstract Type |
getDeclaringClass()
If this is an inner class, return the outer class. |
abstract Type |
getInner(String name)
Get an inner class with a specified name. |
abstract Type[] |
getInterfaces()
Get the interfaces implemented by this type (if it is a class) or extended by this type (if it is an interface) |
abstract Method |
getMethod(String methName,
Type[] paramTypes,
Type caller)
Get an object representing a method in this class with the specified parameter types |
abstract Method[] |
getMethods()
Returns an array containing Method objects representing
all the methods that are members of this type. |
abstract Method[] |
getMeths(String name,
Type[] params,
Type caller)
Retrieve matching methods |
abstract int |
getModifiers()
Get the modifiers for this class, encoded as per The Java Virtual Machine Specification, table 4.1. |
abstract String |
getName()
Get the fully qualified name of a type |
abstract String |
getPackage()
Get the package in which the type definition resides |
abstract Type |
getSuperclass()
Get the supertype of this Type object |
boolean |
implementsInterface(Type type)
Determine whether this type implements an interface |
abstract boolean |
isArray()
Determine whether this type represents an array type |
abstract boolean |
isAssignableFrom(Type type)
Determine whether this type, as a formal parameter, can have a value of type type assigned to it as an actual parameter. |
abstract boolean |
isInner()
Determine whether this type is an inner class |
abstract boolean |
isInterface()
Determine whether this type represents an interface |
abstract boolean |
isPrimitive()
Determine whether this type represents a Java primitive type |
protected static String |
mangle(String name)
Mangle a Java source fully qualified name to an internal JVM fully qualified name. |
static Type[] |
mergeTypeLists(Type[] list1,
Type[] list2)
Merge two lists of types, removing duplicates and subclasses |
static FileAST |
parseFile(File file)
Parse a Java input file and build an AST representing it |
static FileAST |
parseFile(String name)
Parse a Java input file and build an AST representing it |
boolean |
superClassOf(Type type)
Determine whether this type is a superclass of another type |
boolean |
superInterfaceOf(Type type)
Determine whether this type is a superinterface of another type |
abstract Type |
varType(String varName)
Determine the type of a (static or instance) variable |
static Type |
varType(String className,
String varName)
Determine the type of a variable in some class |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final CompiledType booleanType
public static final CompiledType byteType
public static final CompiledType charType
public static final CompiledType doubleType
public static final CompiledType floatType
public static final CompiledType intType
public static final CompiledType longType
public static final CompiledType shortType
public static final CompiledType voidType
public static final CompiledType objectType
public static final CompiledType stringType
protected static final HashMap map
Type
objects
protected static final HashMap pkgMap
File
objects
private static final HashMap parsedMap
File
objects to FileAST
objects
private static final String[] classPath
Constructor Detail |
public Type()
Method Detail |
private static void explodeString(String s, char c, ArrayList list)
s
- the string to break upc
- the delimiting characterlist
- the list to add the parts toprivate static File findFile(String name, boolean source)
null
if the file cannot be
found.
name
- the fully qualified name of the class to findsource
- true
to find a source file,
false
to find a class file
File
object representing the class, or
null
if it could not be foundpublic static FileAST parseFile(String name) throws IOException
name
- the full pathname of the file
IOException
- if anything goes wrong with reading the filepublic static FileAST parseFile(File file) throws IOException
file
- the file to parse
IOException
- if anything goes wrong with reading the filepublic static Type forName(String className) throws ClassNotFoundException
Type
object for it.
className
- the name of the class to look up
Type
object representing the class, if it was
found
ClassNotFoundException
- if the given class cannot be foundpublic static Type forClass(Class theClass)
Type
object for it.
theClass
- the class to look up
Type
object representing the classprotected static String demangle(String name)
name
- the internal JVM name
protected static String mangle(String name)
name
- the JVM source name
public static boolean exists(String className)
className
- the name of the class to test
true
if the class existspublic static Type varType(String className, String varName)
className
- the name of the class to look upvarName
- the name of the variable to look up
public static Type arithType(Type t1, Type t2)
t1
- the first type involved in the arithmetict2
- the second type involved in the arithmetic
public static final Type[] mergeTypeLists(Type[] list1, Type[] list2)
list1
- the first list of typeslist2
- the second list of types
public abstract boolean isAssignableFrom(Type type)
java.lang.Class
when type is null
. It throws a
NullPointerException
, but this
checks whether this type is not primitive (i.e., is able to hold a
value of null
).
type
- the type to check against this type
true
if type can be the type of an
actual parameter passed into a method declared as taking this
type as a formal parameter; false
otherwisepublic abstract boolean isInterface()
true
if this type is an interfacepublic abstract boolean isArray()
true
if this type is an array typepublic abstract boolean isPrimitive()
true
if this type is a Java primitive typepublic abstract boolean isInner()
true
if this type is an inner classpublic abstract String getName()
public abstract Type getSuperclass() throws ClassNotFoundException
Type
object
Type
object
ClassNotFoundException
- if the superclass definition cannot
be foundpublic abstract String getPackage()
public abstract Type[] getInterfaces()
public abstract Type getComponentType()
null
if this
type does not represent an array
public abstract int getModifiers()
Modifier
public abstract Type getDeclaringClass()
null
null
if nonepublic abstract Type[] getClasses()
Type
objects representing all
the classes and interfaces that are members of this type. This
includes class and interface members inherited from superclasses and
class and interface members declared by the class. This method returns
an array of length 0 if this type has no member classes or interfaces.
This method also returns an array of length 0 if this is a primitive
type, an array class, or void
.
public abstract Method[] getMethods()
Method
objects representing
all the methods that are members of this type. This includes methods
inherited from superclasses, abstract methods defined by interfaces
(for abstract types only), and methods declared by this class. This
method returns an array of length 0 if this is a primitive type, an
array class, or void
.
public abstract Method getMethod(String methName, Type[] paramTypes, Type caller)
methName
- the name of the method to look upparamTypes
- the types of the parameterscaller
- the type in which the method call is contained (used to
check visibility)
Method
object representing the best-matching
method with those parameter types, or null
if there is
nonepublic abstract Constructor getConstructor(Type[] params, Type caller)
params
- the types of the parameterscaller
- the type creating an instance of this object with
new
(used to check visibility)
Constructor
object representing the constructor
with those parameter types, or null
if there is nonepublic abstract Type getInner(String name)
name
- the name of the inner class to lookup
null
otherwisepublic abstract Type getArrayType()
public abstract Type varType(String varName)
varName
- the name of the variable to look up
public abstract Method[] getMeths(String name, Type[] params, Type caller)
name
- the name of the method to matchparams
- the types of the parameters to the methodcaller
- the type of the caller
public abstract void dump()
public final boolean superClassOf(Type type)
type
- the potential subclass of this type
true
if this is a superclass of typepublic final boolean superInterfaceOf(Type type)
type
- the potential subinterface of this type
true
if this is a superinterface of typepublic final boolean implementsInterface(Type type)
type
- the potential interface for this type
true
if this type implements type
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |