jparse
Class SourceType

java.lang.Object
  extended byjparse.Type
      extended byjparse.SourceType

public final class SourceType
extends Type

Information on a Java type defined in a Java source file.

Author:
Jerry James

Field Summary
(package private)  boolean anonymous
          true if this is an anonymous class
private  ConstrAST[] constrs
          The constructors for this class
private  int dim
          The dimension of the array represented by this type.
(package private)  FileAST file
          The AST representing the file containing this parsed type
private  Type[] inner
          The inner classes and interfaces of this type
private  Type[] interfaces
          The interfaces this class implements, or this interface extends
private  int modifiers
          The modifiers for this class
private  SourceType outer
          For inner classes, a pointer to the enclosing class.
private  Type parent
          The parent type
private  TypeAST theType
          The AST representing this parsed type
 
Fields inherited from class jparse.Type
booleanType, byteType, charType, doubleType, floatType, intType, longType, map, objectType, pkgMap, shortType, stringType, voidType
 
Constructor Summary
(package private) SourceType(SourceType original, int dims)
          Create a new SourceType object by modifying the dimension of another SourceType object
(package private) SourceType(TypeAST root)
          Create a new SourceType object
 
Method Summary
 void anonCheckSuper()
          Check whether this anonymous class is really extending a superclass, or if it is implementing an interface
 void dump()
          Dump information about this type to standard error
 Type getArrayType()
          Get the type that corresponds to an array of this type
 Type[] getClasses()
          Returns an array containing Type objects representing all the classes and interfaces that are members of this type.
 Type getComponentType()
          Get the component type of an array, or return null if this type does not represent an array
 Constructor getConstructor(Type[] params, Type caller)
          Get an object representing the constructor for this class with the specified parameter types
 Type getDeclaringClass()
          If this is an inner class, return the outer class.
 Type getInner(String name)
          Get an inner class with a specified name.
 Type[] getInterfaces()
          Get the interfaces implemented by this type (if it is a class) or extended by this type (if it is an interface)
 Method getMethod(String methName, Type[] paramTypes, Type caller)
          Get an object representing a method in this class with the specified parameter types
 Method[] getMethods()
          Returns an array containing Method objects representing all the methods that are members of this type.
 Method[] getMeths(String name, Type[] params, Type caller)
          Retrieve matching methods
 int getModifiers()
          Get the modifiers for this class, encoded as per The Java Virtual Machine Specification, table 4.1.
 String getName()
          Get the fully qualified name of a type
 String getPackage()
          Get the package in which the type definition resides
 Type getSuperclass()
          Get the supertype of this Type object
 boolean isArray()
          Determine whether this type represents an array type
 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.
 boolean isInner()
          Determine whether this type is an inner class
 boolean isInterface()
          Determine whether this type represents an interface
 boolean isPrimitive()
          Determine whether this type represents a Java primitive type
 String toString()
          Return a string representation of the type
 Type varType(String varName)
          Determine the type of a (static or instance) variable
 
Methods inherited from class jparse.Type
arithType, demangle, exists, forClass, forName, implementsInterface, mangle, mergeTypeLists, parseFile, parseFile, superClassOf, superInterfaceOf, varType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

file

final FileAST file
The AST representing the file containing this parsed type


anonymous

boolean anonymous
true if this is an anonymous class


theType

private final TypeAST theType
The AST representing this parsed type


dim

private final int dim
The dimension of the array represented by this type. A dimension of zero indicates that the type is not an array.


parent

private Type parent
The parent type


interfaces

private Type[] interfaces
The interfaces this class implements, or this interface extends


inner

private Type[] inner
The inner classes and interfaces of this type


outer

private SourceType outer
For inner classes, a pointer to the enclosing class. For outer classes, this variable is null.


modifiers

private final int modifiers
The modifiers for this class


constrs

private ConstrAST[] constrs
The constructors for this class

Constructor Detail

SourceType

SourceType(TypeAST root)
Create a new SourceType object

Parameters:
root - the root of the AST for this source file

SourceType

SourceType(SourceType original,
           int dims)
Create a new SourceType object by modifying the dimension of another SourceType object

Parameters:
original - the original SourceType object
dims - the dimension of the array type
Method Detail

anonCheckSuper

public void anonCheckSuper()
Check whether this anonymous class is really extending a superclass, or if it is implementing an interface


isAssignableFrom

public boolean isAssignableFrom(Type type)
Description copied from class: Type
Determine whether this type, as a formal parameter, can have a value of type type assigned to it as an actual parameter. Note that this differs from the version in 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).

Specified by:
isAssignableFrom in class Type
Parameters:
type - the type to check against this type
Returns:
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 otherwise

isInterface

public boolean isInterface()
Description copied from class: Type
Determine whether this type represents an interface

Specified by:
isInterface in class Type
Returns:
true if this type is an interface

isArray

public boolean isArray()
Description copied from class: Type
Determine whether this type represents an array type

Specified by:
isArray in class Type
Returns:
true if this type is an array type

isPrimitive

public boolean isPrimitive()
Description copied from class: Type
Determine whether this type represents a Java primitive type

Specified by:
isPrimitive in class Type
Returns:
true if this type is a Java primitive type

isInner

public boolean isInner()
Description copied from class: Type
Determine whether this type is an inner class

Specified by:
isInner in class Type
Returns:
true if this type is an inner class

getName

public String getName()
Description copied from class: Type
Get the fully qualified name of a type

Specified by:
getName in class Type
Returns:
the fully qualified name of this type

getSuperclass

public Type getSuperclass()
                   throws ClassNotFoundException
Description copied from class: Type
Get the supertype of this Type object

Specified by:
getSuperclass in class Type
Returns:
the supertype of this Type object
Throws:
ClassNotFoundException - if the superclass definition cannot be found

getPackage

public String getPackage()
Description copied from class: Type
Get the package in which the type definition resides

Specified by:
getPackage in class Type
Returns:
the package name of this type

getInterfaces

public Type[] getInterfaces()
Description copied from class: Type
Get the interfaces implemented by this type (if it is a class) or extended by this type (if it is an interface)

Specified by:
getInterfaces in class Type
Returns:
an array holding the interfaces

getComponentType

public Type getComponentType()
Description copied from class: Type
Get the component type of an array, or return null if this type does not represent an array

Specified by:
getComponentType in class Type
Returns:
the component type of an array

getModifiers

public int getModifiers()
Description copied from class: Type
Get the modifiers for this class, encoded as per The Java Virtual Machine Specification, table 4.1.

Specified by:
getModifiers in class Type
Returns:
the modifiers for this class
See Also:
Modifier

getDeclaringClass

public Type getDeclaringClass()
Description copied from class: Type
If this is an inner class, return the outer class. Otherwise, return null

Specified by:
getDeclaringClass in class Type
Returns:
the outer class, or null if none

getClasses

public Type[] getClasses()
Description copied from class: Type
Returns an array containing 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.

Specified by:
getClasses in class Type
Returns:
an array of member classes and interfaces

getMethods

public Method[] getMethods()
Description copied from class: Type
Returns an array containing 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.

Specified by:
getMethods in class Type
Returns:
an array of member methods

getMethod

public Method getMethod(String methName,
                        Type[] paramTypes,
                        Type caller)
Description copied from class: Type
Get an object representing a method in this class with the specified parameter types

Specified by:
getMethod in class Type
Parameters:
methName - the name of the method to look up
paramTypes - the types of the parameters
caller - the type in which the method call is contained (used to check visibility)
Returns:
a Method object representing the best-matching method with those parameter types, or null if there is none

getConstructor

public Constructor getConstructor(Type[] params,
                                  Type caller)
Description copied from class: Type
Get an object representing the constructor for this class with the specified parameter types

Specified by:
getConstructor in class Type
Parameters:
params - the types of the parameters
caller - the type creating an instance of this object with new (used to check visibility)
Returns:
a Constructor object representing the constructor with those parameter types, or null if there is none

getInner

public Type getInner(String name)
Description copied from class: Type
Get an inner class with a specified name. This name must begin with a dollar sign ($) for this method to work properly.

Specified by:
getInner in class Type
Parameters:
name - the name of the inner class to lookup
Returns:
a type corresponding to the requested inner class, if it exists, or null otherwise

getArrayType

public Type getArrayType()
Description copied from class: Type
Get the type that corresponds to an array of this type

Specified by:
getArrayType in class Type
Returns:
an array type for this type

varType

public Type varType(String varName)
Description copied from class: Type
Determine the type of a (static or instance) variable

Specified by:
varType in class Type
Parameters:
varName - the name of the variable to look up
Returns:
the type of the variable

getMeths

public Method[] getMeths(String name,
                         Type[] params,
                         Type caller)
Description copied from class: Type
Retrieve matching methods

Specified by:
getMeths in class Type
Parameters:
name - the name of the method to match
params - the types of the parameters to the method
caller - the type of the caller
Returns:
an array of matching methods. If there are no matching methods, an array of length 0 will be returned.

toString

public String toString()
Return a string representation of the type

Returns:
a string representation of the type

dump

public void dump()
Description copied from class: Type
Dump information about this type to standard error

Specified by:
dump in class Type