public abstract class TypeOracle extends Object
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);
Modifier and Type | Field and Description |
---|---|
static String |
TAG_TYPEARGS
Deprecated.
gwt.typeArgs is not longer supported
|
Constructor and Description |
---|
TypeOracle() |
Modifier and Type | Method and Description |
---|---|
abstract JPackage |
findPackage(String pkgName)
Attempts to find a package by name.
|
abstract JClassType |
findType(String name)
Finds a class or interface given its fully-qualified name.
|
abstract JClassType |
findType(String pkgName,
String typeName)
Finds a type given its package-relative name.
|
abstract JArrayType |
getArrayType(JType componentType)
Gets the type object that represents an array of the specified type.
|
abstract JClassType |
getJavaLangObject()
Gets a reference to the type object representing
java.lang.Object . |
abstract JPackage |
getOrCreatePackage(String name)
Ensure that a package with the specified name exists as well as its parent
packages.
|
abstract JPackage |
getPackage(String pkgName)
Gets a package by name.
|
abstract JPackage[] |
getPackages()
Gets an array of all packages known to this type oracle.
|
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.
|
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.
|
abstract 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.
|
abstract JClassType |
getSingleJsoImpl(JClassType intf)
Returns the single implementation type for an interface returned via
getSingleJsoImplInterfaces() or null if no JSO
implementation is defined. |
abstract Set<? extends JClassType> |
getSingleJsoImplInterfaces()
Returns an unmodifiable, live view of all interface types that are
implemented by exactly one JSO subtype.
|
abstract JClassType |
getType(String name)
Finds a type given its fully qualified name.
|
abstract JClassType |
getType(String pkgName,
String topLevelTypeSimpleName)
Finds a type given its package-relative name.
|
abstract JClassType[] |
getTypes()
Gets all types, both top-level and nested.
|
abstract JWildcardType |
getWildcardType(JWildcardType.BoundType boundType,
JClassType typeBound) |
abstract 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.
|
@Deprecated public static final String TAG_TYPEARGS
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 abstract JPackage findPackage(String pkgName)
null
if the package could not be foundpublic abstract JClassType findType(String name)
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 abstract JClassType findType(String pkgName, String typeName)
null
if the type is not foundpublic abstract JArrayType getArrayType(JType componentType)
componentType
- the component type of the array, which can itself be
an array typepublic abstract JClassType getJavaLangObject()
java.lang.Object
.public abstract JPackage getOrCreatePackage(String name)
public abstract JPackage getPackage(String pkgName) throws NotFoundException
NotFoundException
- if getOrCreatePackage
hasn't
been called for this package or any child packagespublic abstract JPackage[] getPackages()
public abstract JParameterizedType getParameterizedType(JGenericType genericType, JClassType enclosingType, JClassType[] typeArgs)
genericType
- a generic base classenclosingType
- typeArgs
- 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 abstract JParameterizedType getParameterizedType(JGenericType genericType, JClassType[] typeArgs)
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 abstract long getReloadCount()
public abstract JClassType getSingleJsoImpl(JClassType intf)
getSingleJsoImplInterfaces()
or null
if no JSO
implementation is defined.public abstract Set<? extends JClassType> getSingleJsoImplInterfaces()
public abstract JClassType getType(String name) throws NotFoundException
NotFoundException
public abstract JClassType getType(String pkgName, String topLevelTypeSimpleName) throws NotFoundException
NotFoundException
public abstract JClassType[] getTypes()
public abstract JWildcardType getWildcardType(JWildcardType.BoundType boundType, JClassType typeBound)
public abstract 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>>
type
- a type signature to be parsedTypeOracleException
Copyright © 2018. All rights reserved.