public class TypeOracle extends TypeOracle
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 = 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);
TAG_TYPEARGS
Constructor and Description |
---|
TypeOracle() |
Modifier and Type | Method and Description |
---|---|
void |
addNewType(JRealClassType newType) |
void |
ensureAllLoaded()
Make sure that all possible Types have been read and made available for querying.
|
JPackage |
findPackage(String pkgName)
Attempts to find a package by name.
|
JClassType |
findType(String name)
Finds a type (even nested ones) given its fully-qualified name.
|
JClassType |
findType(String pkgName,
String typeName)
Finds a type (even nested ones) given its package-relative name.
|
JArrayType |
getArrayType(JType componentType)
Gets the type object that represents an array of the specified type.
|
Set<? extends JClassType> |
getDualJsoImplInterfaces()
Returns an unmodifiable, live view of all interface types that are
implemented by both a JSO subtype and at least one Object subtype.
|
JClassType |
getJavaLangObject()
Gets a reference to the type object representing
java.lang.Object . |
JClassType |
getJavaScriptObject()
Gets a reference to the type object representing
com.google.gwt.core.client.JavaScriptObject . |
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.
|
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.
|
JParameterizedType |
getParameterizedType(JGenericType extGenericType,
JClassType extEnclosingType,
JClassType[] extTypeArgs)
Gets the parameterized type object that represents the combination of a
specified raw type and a set of type arguments.
|
long |
getReloadCount()
Deprecated.
This method will always return 0 because a TypeOracle never
gets reloaded anymore. Callers should not rely on this value to
manage static state.
|
JClassType |
getSingleJsoImpl(JClassType intf)
Returns the single implementation type for an interface returned via
getSingleJsoImplInterfaces() or null if no JSO
implementation is defined. |
Set<? extends JClassType> |
getSingleJsoImplInterfaces()
Returns an unmodifiable, live view of all interface types that are
implemented by exactly one JSO subtype.
|
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.
|
JWildcardType |
getWildcardType(JWildcardType.BoundType boundType,
JClassType extTypeBound) |
JType |
parse(String type)
Parses the string form of a type to produce the corresponding type object.
|
static void |
sort(JClassType[] types)
Convenience method to sort class types in a consistent way.
|
static void |
sort(JConstructor[] ctors)
Convenience method to sort constructors in a consistent way.
|
static void |
sort(JField[] fields)
Convenience method to sort fields in a consistent way.
|
static void |
sort(JMethod[] methods)
Convenience method to sort methods in a consistent way.
|
sort, sort, sort, sort
public static void sort(JClassType[] types)
public static void sort(JConstructor[] ctors)
public static void sort(JField[] fields)
public static void sort(JMethod[] methods)
public void ensureAllLoaded()
public JPackage findPackage(String pkgName)
findPackage
in class TypeOracle
null
if the package could not be foundpublic JClassType findType(String name)
findType
in class TypeOracle
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 "$")null
if the type is not foundpublic JClassType findType(String pkgName, String typeName)
findType
in class TypeOracle
null
if the type is not foundpublic JArrayType getArrayType(JType componentType)
getArrayType
in class TypeOracle
componentType
- the component type of the array, which can itself be
an array typepublic JClassType getJavaLangObject()
java.lang.Object
.getJavaLangObject
in class TypeOracle
public JClassType getJavaScriptObject()
com.google.gwt.core.client.JavaScriptObject
.public JPackage getOrCreatePackage(String name)
getOrCreatePackage
in class TypeOracle
public JPackage getPackage(String pkgName) throws NotFoundException
getPackage
in class TypeOracle
NotFoundException
- if getOrCreatePackage
hasn't
been called for this package or any child packagespublic JPackage[] getPackages()
getPackages
in class TypeOracle
public JParameterizedType getParameterizedType(JGenericType extGenericType, JClassType extEnclosingType, JClassType[] extTypeArgs)
getParameterizedType
in class TypeOracle
extGenericType
- a generic base classextEnclosingType
- extTypeArgs
- the type arguments bound to the specified generic typeIllegalArgumentException
- 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 typeNullPointerException
- if genericType is null
public JParameterizedType getParameterizedType(JGenericType genericType, JClassType[] typeArgs)
getParameterizedType
in class TypeOracle
genericType
- a generic base classtypeArgs
- the type arguments bound to the specified generic typeIllegalArgumentException
- if the generic type is a non-static member
type or if not enough arguments were specified to parameterize
the generic typeNullPointerException
- if genericType is null
@Deprecated public long getReloadCount()
getReloadCount
in class TypeOracle
public JClassType getSingleJsoImpl(JClassType intf)
getSingleJsoImplInterfaces()
or null
if no JSO
implementation is defined.getSingleJsoImpl
in class TypeOracle
public Set<? extends JClassType> getSingleJsoImplInterfaces()
getSingleJsoImplInterfaces
in class TypeOracle
public Set<? extends JClassType> getDualJsoImplInterfaces()
public JClassType getType(String name) throws NotFoundException
getType
in class TypeOracle
NotFoundException
public JClassType getType(String pkgName, String topLevelTypeSimpleName) throws NotFoundException
getType
in class TypeOracle
NotFoundException
public JClassType[] getTypes()
getTypes
in class TypeOracle
public JWildcardType getWildcardType(JWildcardType.BoundType boundType, JClassType extTypeBound)
getWildcardType
in class TypeOracle
public JType parse(String type) throws TypeOracleException
Examples of types that can be parsed by this method.
int
java.lang.Object
java.lang.String[]
char[][]
void
List<Shape>
List<List<Shape>>
parse
in class TypeOracle
type
- a type signature to be parsedTypeOracleException
public void addNewType(JRealClassType newType)
Copyright © 2016. All rights reserved.