com.google.gwt.core.ext.typeinfo
Class TypeOracle

java.lang.Object
  extended bycom.google.gwt.core.ext.typeinfo.TypeOracle

public class TypeOracle
extends Object

Provides type-related information about a set of source files, including doc comment metadata.

All type objects exposed, such as JClassType and others, have a stable identity relative to this type oracle instance. Consequently, you can reliably compare object identity of any objects this type oracle produces. For example, the following code relies on this stable identity guarantee:

 JClassType o = typeOracle.getJavaLangObject();
 JClassType s1 = typeOraclbe.getType("java.lang.String");
 JClassType s2 = typeOraclbe.getType("java.lang.String");
 assert(s1 == s2);
 assert(o = s1.getSuperclass());
 JParameterizedType ls = typeOracle.parse("java.util.List<java.lang.String>");
 assert(ls.getTypeArgs()[0] == s1);
 


Field Summary
static String TAG_TYPEARGS
          A reserved metadata tag to indicates that a field type, method return type or method parameter type is intended to be parameterized.
 
Fields inherited from class java.lang.Object
typeId, typeName
 
Constructor Summary
TypeOracle()
           
 
Method Summary
 JPackage findPackage(String pkgName)
          Attempts to find a package by name.
 JClassType findType(String name)
          Finds a class or interface given its fully-qualified name.
 JClassType findType(String pkgName, String typeName)
          Finds a type given its package-relative name.
 JArrayType getArrayType(JType componentType)
          Gets the type object that represents an array of the specified type.
 JClassType getJavaLangObject()
          Gets a reference to the type object representing java.lang.Object.
 JPackage getOrCreatePackage(String name)
          Ensure that a package with the specified name exists as well as its parent packages.
 JPackage getPackage(String pkgName)
          Gets a package by name.
 JPackage[] getPackages()
          Gets an array of all packages known to this type oracle.
 JType getParameterizedType(JClassType rawType, JType[] typeArgs)
          Gets the parameterized type object that represents the combination of a specified raw type and a set of type arguments.
 JClassType getType(String name)
          Finds a type given its fully qualified name.
 JClassType getType(String pkgName, String topLevelTypeSimpleName)
          Finds a type given its package-relative name.
 JClassType[] getTypes()
          Gets all types, both top-level and nested.
 JClassType[] getTypesInCompilationUnit(CompilationUnitProvider cup)
           
 JType parse(String type)
          Parses the string form of a type to produce the corresponding type object.
 void refresh(TreeLogger logger)
          Updates relationships within this type oracle.
 void sort(JClassType[] types)
          Convenience method to sort class types in a consistent way.
 void sort(JConstructor[] ctors)
          Convenience method to sort constructors in a consistent way.
 void sort(JField[] fields)
          Convenience method to sort fields in a consistent way.
 void sort(JMethod[] methods)
          Convenience method to sort methods in a consistent way.
 
Methods inherited from class java.lang.Object
equals, finalize, hashCode, toString
 

Field Detail

TAG_TYPEARGS

public static final String TAG_TYPEARGS
A reserved metadata tag to indicates that a field type, method return type or method parameter type is intended to be parameterized. Note that constructor type parameters are not supported at present.

See Also:
Constant Field Values
Constructor Detail

TypeOracle

public TypeOracle()
Method Detail

findPackage

public JPackage findPackage(String pkgName)
Attempts to find a package by name. All requests for the same package return the same package object.

Returns:
null if the package could not be found

findType

public JClassType findType(String name)
Finds a class or interface given its fully-qualified name. For nested classes, use its source name rather than its binary name (that is, use a "." rather than a "$").

Returns:
null if the type is not found

findType

public JClassType findType(String pkgName,
                           String typeName)
Finds a type given its package-relative name. For nested classes, use its source name rather than its binary name (that is, use a "." rather than a "$").

Returns:
null if the type is not found

getArrayType

public JArrayType getArrayType(JType componentType)
Gets the type object that represents an array of the specified type. The returned type always has a stable identity so as to guarantee that all calls to this method with the same argument return the same object.

Parameters:
componentType - the component type of the array, which can itself be an array type
Returns:
a type object representing an array of the component type

getJavaLangObject

public JClassType getJavaLangObject()
Gets a reference to the type object representing java.lang.Object.


getPackage

public JPackage getPackage(String pkgName)
                    throws NotFoundException
Gets a package by name. All requests for the same package return the same package object.

Returns:
the package object associated with the specified name
Throws:
NotFoundException - if the specified package name is not available

getPackages

public JPackage[] getPackages()
Gets an array of all packages known to this type oracle.

Returns:
an array of packages, possibly of zero-length

getParameterizedType

public JType getParameterizedType(JClassType rawType,
                                  JType[] typeArgs)
Gets the parameterized type object that represents the combination of a specified raw type and a set of type arguments. The returned type always has a stable identity so as to guarantee that all calls to this method with the same arguments return the same object.

Parameters:
rawType - the raw type of the array, which must be a class or interface type and cannot be a primitive, array, or another parameterized type
typeArgs - the type arguments bound to the specified raw type
Returns:
a type object representing this particular binding of type arguments to the specified raw type

getType

public JClassType getType(String name)
                   throws NotFoundException
Finds a type given its fully qualified name. For nested classes, use its source name rather than its binary name (that is, use a "." rather than a "$").

Returns:
the specified type
Throws:
NotFoundException - thrown if the specified pakage or type could not be found

getType

public JClassType getType(String pkgName,
                          String topLevelTypeSimpleName)
                   throws NotFoundException
Finds a type given its package-relative name. For nested classes, use its source name rather than its binary name (that is, use a "." rather than a "$").

Returns:
the specified type
Throws:
NotFoundException - thrown if the specified pakage or type could not be found

getTypes

public JClassType[] getTypes()
Gets all types, both top-level and nested.

Returns:
an array of types, possibly of zero length

parse

public JType parse(String type)
            throws TypeOracleException
Parses the string form of a type to produce the corresponding type object. The types that can be parsed include primitives, class and interface names, simple parameterized types (those without wildcards or bounds), and arrays of the preceding.

Examples of types that can be parsed by this method.

Parameters:
type - a type signature to be parsed
Returns:
the type object corresponding to the parse type
Throws:
ParseException - thrown when a syntax error is encountered
BadTypeArgsException - thrown when a semantic error is encountered
NotFoundException - thrown when a referenced type could not be found in the type oracle
TypeOracleException

sort

public void sort(JClassType[] types)
Convenience method to sort class types in a consistent way. Note that the order is subject to change and is intended to generate an "aesthetically pleasing" order rather than a computationally reliable order.


sort

public void sort(JConstructor[] ctors)
Convenience method to sort constructors in a consistent way. Note that the order is subject to change and is intended to generate an "aesthetically pleasing" order rather than a computationally reliable order.


sort

public void sort(JField[] fields)
Convenience method to sort fields in a consistent way. Note that the order is subject to change and is intended to generate an "aesthetically pleasing" order rather than a computationally reliable order.


sort

public void sort(JMethod[] methods)
Convenience method to sort methods in a consistent way. Note that the order is subject to change and is intended to generate an "aesthetically pleasing" order rather than a computationally reliable order.


refresh

public void refresh(TreeLogger logger)
             throws NotFoundException
Updates relationships within this type oracle. Should be called after any changes are made.

Throws:
TypeOracleException - thrown if fundamental baseline correctness criteria are violated, most notably the absence of "java.lang.Object"
NotFoundException

getOrCreatePackage

public JPackage getOrCreatePackage(String name)
Ensure that a package with the specified name exists as well as its parent packages.


getTypesInCompilationUnit

public JClassType[] getTypesInCompilationUnit(CompilationUnitProvider cup)


This javadoc distribution was not produced by Google. The official documentation is here.