Package com.google.gwt.core.ext.typeinfo
Class TypeOracle
- java.lang.Object
-
- com.google.gwt.core.ext.typeinfo.TypeOracle
-
public abstract class TypeOracle extends java.lang.ObjectProvides type-related information about a set of source files.All type objects exposed, such as
JClassTypeand 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 = typeOracle.getType("java.lang.String"); JClassType s2 = typeOracle.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);
-
-
Constructor Summary
Constructors Constructor Description TypeOracle()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract JPackagefindPackage(java.lang.String pkgName)Attempts to find a package by name.abstract JClassTypefindType(java.lang.String name)Finds a class or interface given its fully-qualified name.abstract JClassTypefindType(java.lang.String pkgName, java.lang.String typeName)Finds a type given its package-relative name.abstract JArrayTypegetArrayType(JType componentType)Gets the type object that represents an array of the specified type.abstract JClassTypegetJavaLangObject()Gets a reference to the type object representingjava.lang.Object.abstract JPackagegetOrCreatePackage(java.lang.String name)Ensure that a package with the specified name exists as well as its parent packages.abstract JPackagegetPackage(java.lang.String pkgName)Gets a package by name.abstract JPackage[]getPackages()Gets an array of all packages known to this type oracle.abstract JParameterizedTypegetParameterizedType(JGenericType genericType, JClassType[] typeArgs)Gets the parameterized type object that represents the combination of a specified raw type and a set of type arguments.abstract JParameterizedTypegetParameterizedType(JGenericType genericType, JClassType enclosingType, JClassType[] typeArgs)Gets the parameterized type object that represents the combination of a specified raw type and a set of type arguments.abstract JClassTypegetSingleJsoImpl(JClassType intf)Returns the single implementation type for an interface returned viagetSingleJsoImplInterfaces()ornullif no JSO implementation is defined.abstract java.util.Set<? extends JClassType>getSingleJsoImplInterfaces()Returns an unmodifiable, live view of all interface types that are implemented by exactly one JSO subtype.abstract JClassTypegetType(java.lang.String name)Finds a type given its fully qualified name.abstract JClassTypegetType(java.lang.String pkgName, java.lang.String topLevelTypeSimpleName)Finds a type given its package-relative name.abstract JClassType[]getTypes()Gets all types, both top-level and nested.abstract JWildcardTypegetWildcardType(JWildcardType.BoundType boundType, JClassType typeBound)abstract JTypeparse(java.lang.String type)Parses the string form of a type to produce the corresponding type object.static voidsort(JClassType[] types)Convenience method to sort class types in a consistent way.static voidsort(JConstructor[] ctors)Convenience method to sort constructors in a consistent way.static voidsort(JField[] fields)Convenience method to sort fields in a consistent way.static voidsort(JMethod[] methods)Convenience method to sort methods in a consistent way.
-
-
-
Method Detail
-
sort
public static 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 static 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 static 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 static 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.
-
findPackage
public abstract JPackage findPackage(java.lang.String pkgName)
Attempts to find a package by name. All requests for the same package return the same package object.- Returns:
nullif the package could not be found
-
findType
public abstract JClassType findType(java.lang.String name)
Finds a class or interface given its fully-qualified name.- Parameters:
name- fully-qualified class/interface name - for nested classes, use its source name rather than its binary name (that is, use a "." rather than a "$")- Returns:
nullif the type is not found
-
findType
public abstract JClassType findType(java.lang.String pkgName, java.lang.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:
nullif the type is not found
-
getArrayType
public abstract 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 abstract JClassType getJavaLangObject()
Gets a reference to the type object representingjava.lang.Object.
-
getOrCreatePackage
public abstract JPackage getOrCreatePackage(java.lang.String name)
Ensure that a package with the specified name exists as well as its parent packages.
-
getPackage
public abstract JPackage getPackage(java.lang.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- ifgetOrCreatePackagehasn't been called for this package or any child packages
-
getPackages
public abstract JPackage[] getPackages()
Gets an array of all packages known to this type oracle.- Returns:
- an array of packages, possibly of zero-length
-
getParameterizedType
public abstract JParameterizedType getParameterizedType(JGenericType genericType, JClassType enclosingType, JClassType[] 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:
genericType- a generic base classenclosingType-typeArgs- the type arguments bound to the specified generic type- Returns:
- a type object representing this particular binding of type arguments to the specified generic
- Throws:
java.lang.IllegalArgumentException- if the parameterization of a non-static member type does not specify an enclosing type or if not enough arguments were specified to parameterize the generic typejava.lang.NullPointerException- if genericType isnull
-
getParameterizedType
public abstract JParameterizedType getParameterizedType(JGenericType genericType, JClassType[] 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:
genericType- a generic base classtypeArgs- the type arguments bound to the specified generic type- Returns:
- a type object representing this particular binding of type arguments to the specified generic
- Throws:
java.lang.IllegalArgumentException- if the generic type is a non-static member type or if not enough arguments were specified to parameterize the generic typejava.lang.NullPointerException- if genericType isnull
-
getSingleJsoImpl
public abstract JClassType getSingleJsoImpl(JClassType intf)
Returns the single implementation type for an interface returned viagetSingleJsoImplInterfaces()ornullif no JSO implementation is defined.
-
getSingleJsoImplInterfaces
public abstract java.util.Set<? extends JClassType> getSingleJsoImplInterfaces()
Returns an unmodifiable, live view of all interface types that are implemented by exactly one JSO subtype.
-
getType
public abstract JClassType getType(java.lang.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
-
getType
public abstract JClassType getType(java.lang.String pkgName, java.lang.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
-
getTypes
public abstract JClassType[] getTypes()
Gets all types, both top-level and nested.- Returns:
- an array of types, possibly of zero length
-
getWildcardType
public abstract JWildcardType getWildcardType(JWildcardType.BoundType boundType, JClassType typeBound)
-
parse
public abstract JType parse(java.lang.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.
intjava.lang.Objectjava.lang.String[]char[][]voidList<Shape>List<List<Shape>>
- Parameters:
type- a type signature to be parsed- Returns:
- the type object corresponding to the parse type
- Throws:
TypeOracleException
-
-