Class 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 = 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);
Fields
TAG_TYPEARGS | A reserved metadata tag to indicates that a field type, method return type
or method parameter type is intended to be parameterized. |
Constructors
Methods
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.
Constructor Detail
TypeOracle
public TypeOracle()
Method Detail
findPackage
Attempts to find a package by name. All requests for the same package
return the same package object.
Parameters
- pkgName
-
Return Value
null
if the package could not be found
findType
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 "$").
Parameters
- name
-
Return Value
null
if the type is not found
findType
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
"$").
Parameters
- pkgName
-
- typeName
-
Return Value
null
if the type is not found
getArrayType
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
Return Value
a type object representing an array of the component type
getJavaLangObject
Gets a reference to the type object representing
java.lang.Object
.
getOrCreatePackage
Ensure that a package with the specified name exists as well as its parent
packages.
Parameters
- name
-
getPackage
Gets a package by name. All requests for the same package return the same
package object.
Parameters
- pkgName
-
Return Value
the package object associated with the specified name
getPackages
Gets an array of all packages known to this type oracle.
Return Value
an array of packages, possibly of zero-length
getParameterizedType
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
Return Value
a type object representing this particular binding of type
arguments to the specified raw type
getReloadCount
public long getReloadCount()
getType
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
"$").
Parameters
- name
-
Return Value
the specified type
getType
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
"$").
Parameters
- pkgName
-
- topLevelTypeSimpleName
-
Return Value
the specified type
getTypes
Gets all types, both top-level and nested.
Return Value
an array of types, possibly of zero length
getTypesInCompilationUnit
Parameters
- cup
-
parse
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.
-
int
-
java.lang.Object
-
java.lang.String[]
-
char[][]
-
void
-
List<Shape>
-
List<List<Shape>>
Parameters
- type
- a type signature to be parsed
Return Value
the type object corresponding to the parse type
sort
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.
Parameters
- types
-
sort
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.
Parameters
- ctors
-
sort
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.
Parameters
- fields
-
sort
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.
Parameters
- methods
-