oracle.javatools.parser.java.v2.model
Interface JavaType
- All Superinterfaces:
- Element, JavaElement, JavaHasAnnotations, JavaHasName, JavaHasType, JavaIsGeneric, JavaMember
- All Known Subinterfaces:
- JavaClass, JavaTypeVariable, JavaWildcardType, SourceClass, SourceTypeParameter
- All Known Implementing Classes:
- AbstractClass, AbstractType, BaseFileProvider.BaseClass, oracle.javatools.parser.java.v2.classfile.ClClass, PrimitiveType, WrapperClass
public interface JavaType
- extends JavaMember, JavaIsGeneric
JavaType is the common base interface for JavaClass,
JavaTypeVariable, and JavaWildcardType. All types may be asked for
their superclass, array of interfaces, inheritance hierarchy, and
array of members. Type variables and wildcard types (obviously)
declare no members.
Method Summary |
boolean |
equals(java.lang.Object o)
|
int |
getArrayDimensions()
|
JavaType |
getBaseComponentType()
|
JavaClass |
getClass(java.lang.String name)
Iteratively retrieves all member classes declared in this class
or its hierarchy. |
java.util.Collection |
getClasses()
Iteratively retrieves all member classes declared in this class
or its hierarchy. |
JavaMethod |
getClinitMethod()
|
JavaClass |
getClosestClass()
Deprecated. Please use getTypeErasure() . |
JavaType |
getComponentType()
|
JavaClass |
getDeclaredClass(java.lang.String name)
|
java.util.Collection |
getDeclaredClasses()
In order to get all inner classes, clients must recurse through
direct inner classes. |
JavaMethod |
getDeclaredConstructor(JavaType[] parameters)
|
java.util.Collection |
getDeclaredConstructors()
|
JavaField |
getDeclaredField(java.lang.String name)
|
java.util.Collection |
getDeclaredFields()
|
JavaMethod |
getDeclaredMethod(java.lang.String name,
JavaType[] parameters)
|
java.util.Collection |
getDeclaredMethods()
|
java.util.Collection |
getDeclaredMethods(java.lang.String name)
|
java.lang.String |
getDescriptor()
Gets the descriptor for this type, as defined by the JVMS2. |
JavaField |
getField(java.lang.String name)
Iteratively searches for a field declared in this class or its
hierarchy. |
java.util.Collection |
getFields()
Iteratively retrieves all fields declared in this class and its
hierarchy. |
java.util.Set |
getHierarchy()
Recursively gets the full list of all resolved superclasses and
super-interfaces. |
java.util.Collection |
getInterfaces()
The name "getInterfaces" was chosen to be consistent with
java/lang/Class. |
JavaMethod |
getMethod(java.lang.String name,
JavaType[] parameters)
Iteratively searches for a method declared in this class or its
hierarchy. |
java.util.Collection |
getMethods()
Iteratively retrieves all methods declared in this class or its
hierarchy. |
java.util.Collection |
getMethods(java.lang.String name)
Iteratively retrieves all methods declared in this class or its
hierarchy. |
java.lang.String |
getName()
Gets the simplest name of this type with "[]"s if present. |
JavaPackage |
getPackage()
Gets the owning package, null if N/A. |
java.lang.String |
getPackageName()
Gets the qualified name of the owning package. |
java.lang.String |
getQualifiedName()
Gets the fully qualified name of this type in source format. |
java.lang.String |
getRawName()
Gets the raw name of this type. |
java.lang.String |
getSignature()
Gets the "Signature" attribute of this type, as defined by the
JVMS3. |
JavaType |
getSuperclass()
The name "getSuperclass" was chosen to be consistent with
java/lang/Class. |
CompiledTmpVariable |
getThisValue()
In the interest of minimizing the number of tmp variables
floating around in the heap, each type may create a value object
(when needed) and store it (with a weak reference) for later use. |
JavaClass |
getTypeErasure()
Gets the type erasure of this type, as defined by the JLS3. |
java.lang.String |
getTypeSignature()
Gets the type signature for this type, as defined by the
JVMS3. |
java.lang.String |
getUniqueIdentifier()
Gets a unique identifier for this type. |
java.lang.String |
getUnqualifiedName()
Gets the name of this type in its unqualified form. |
java.util.Collection<UnresolvedType> |
getUnresolvedInterfaces()
When reverse engineering byecode, some types cannot be resolved
if the correct owning project is not associated to the JavaProvider. |
java.net.URL |
getURL()
If the input for this type is a *.class file, the returned URL
will be for the *.class file. |
java.lang.String |
getVMName()
Gets the VM name for this type. |
boolean |
isAnnotation()
|
boolean |
isArray()
|
boolean |
isAssignableFrom(JavaType subject)
Consider the following expression where S (subject) represents
another type and T (this) represents this type. |
boolean |
isEnum()
|
boolean |
isExported()
|
boolean |
isInterface()
|
boolean |
isMemberClass()
True if this is a member type. |
boolean |
isPrimitive()
|
boolean |
isSubtypeOf(JavaType supertype)
True if this is a subtype of the indicated argument. |
Methods inherited from interface oracle.javatools.parser.java.v2.model.JavaElement |
getElementKind, getFile, getModifiers, getOwner, getSourceElement, isDeprecated, isFinal, isHidden, isSourceElement, isSynthetic, printCompiledInfo |
EMPTY_ARRAY
static final JavaType[] EMPTY_ARRAY
getClosestClass
@Deprecated
JavaClass getClosestClass()
- Deprecated. Please use
getTypeErasure()
.
- Synonymous with
getTypeErasure()
. If this type is a ...
... JavaClass, then it is returned.
... JavaTypeVariable, then the first bound is returned. There is
always at least one bound.
... JavaWildcardType, then the lower bound is returned. There is
always at least one lower bound.
- Returns:
- The JavaClass most closely approximating the type of this
compiled object.
getTypeErasure
JavaClass getTypeErasure()
- Gets the type erasure of this type, as defined by the JLS3. A
simple way of thinking of a type erasure is that it's the
"closest non-generic class" to this type. You can also think of
it as the 1.4-compatible class for this type.
- Returns:
- The JavaClass for this type's erasure.
getThisValue
CompiledTmpVariable getThisValue()
- In the interest of minimizing the number of tmp variables
floating around in the heap, each type may create a value object
(when needed) and store it (with a weak reference) for later use.
EXPERIMENTAL.
- Returns:
- A value object which has this as its type. May return a
different instance each call.
isPrimitive
boolean isPrimitive()
- Returns:
- True if this type is a primitive type.
isArray
boolean isArray()
- Returns:
- True if this type is an array type.
getComponentType
JavaType getComponentType()
- Returns:
- The component type of this array. For example, if this
type is "int[]", this will return the type for "int". If this is
not an array type, this returns null (to match the behavior of
java/lang/Class).
getArrayDimensions
int getArrayDimensions()
- Returns:
- The array dimensions, zero if this is not an array type.
getBaseComponentType
JavaType getBaseComponentType()
- Returns:
- The base component type of this array, that is, the type
we get when all array dimensions have been removed. For example,
if this type is "int[][]", this will return the type for "int".
If this is not an array type, this returns null (to match the
behavior of java/lang/Class).
isInterface
boolean isInterface()
- Returns:
- True if this is an interface type or an annotation type.
False otherwise.
isEnum
boolean isEnum()
- Returns:
- True if this an enumeration type. False otherwise.
isAnnotation
boolean isAnnotation()
- Returns:
- True if this is an annotation type. False otherwise.
isExported
boolean isExported()
- Returns:
- True if this is a top-level class or a member inner class.
False otherwise (local classes and anonymous classes).
isMemberClass
boolean isMemberClass()
- True if this is a member type.
getName
java.lang.String getName()
- Gets the simplest name of this type with "[]"s if present.
The name of a non-parametrized top-level type of the form
"pkg.Cls" is "Cls".
The name of a non-parametrized member type of the form
"pkg.Cls.InnerClass" is "InnerClass".
The name of an array type T[] is the name of T suffixed by
the appropriate number of "[]"s.
The name of a parametrized type is the same as the name of its
raw type. That is, the name of "pkg.Cls<String>" is simply
"Cls".
The name of a wildcard type is always "?".
The name of a type parameter should be pretty obvious.
The name of a primitive type should be pretty obvious.
The name of a local inner class is just its name.
An anonymous inner classes does not have a name and will return
the empty string.
- Specified by:
getName
in interface JavaHasName
- Returns:
- The simple name of this type with "[]"s if present.
getUnqualifiedName
java.lang.String getUnqualifiedName()
- Gets the name of this type in its unqualified form.
Unlike getName(), this will contain type parameters in their
unqualified form. In other words, for types containing no type
parameterization, the behavior is the same as getName().
getQualifiedName
java.lang.String getQualifiedName()
- Gets the fully qualified name of this type in source format.
Here, "source format" means the format of a type reference in a
source compilation unit. A type's source name uniquely identifies
a type in a specific scope but not in the global scope.
The source name of a non-parametrized top-level type of the form
"pkg.Cls" is "pkg.Cls".
The source name of a non-parametrized member type of the form
T.InnerClass (that is, a member type InnerClass that is a member
of type T) is the source name of T suffixed with by
".InnerClass", e.g. "java.util.Map.Entry",
"pkg.Cls<?>.InnerClass".
The source name of a parametrized type starts with the source
name of the raw type and lists the source name of all of its
actual type argumenths, e.g.
"java.util.List<java.lang.String>".
The source name of an array type T[] is the source name of T
suffixed by the appropriate number of "[]"s.
The source name of a wildcard type is the string with which it
would appear in a source file. The three possible forms this can
take are: "?", "? extends T", "? super T".
The source name of a type parameter is just its name.
The source name of a primitive type should be pretty obvious.
The source name of a local inner class is just its name because a
local inner class is referenced, in a source file, by its
name.
An anonymous inner classes does not have a source name. It will
return the empty string for its source name.
Open for discussion: What should be returned by an anonymous
class? Technically, the concept of a source name is irrelevant
because anonymous classes may not be referred to in a source
compilation unit.
- Returns:
- The fully qualified source name for this type, empty for
anonymous classes. Example values:
java.lang.Object
java.util.Map<String,String>
java.lang.String[][]
getRawName
java.lang.String getRawName()
- Gets the raw name of this type. Here, we define the raw name to
be the fully qualified source name of the raw type.
The raw name of a parametrized top-level or member or local inner
type is the source name of its type erasure, as defined by the
JLS3. Think of the raw name as the source name with all
parametrization stripped out.
The raw name of an array type T[] is the raw name of T suffixed
by the appropriate number of "[]"s.
The raw name for any other type is the same as its source name.
- Returns:
- The source name of the raw type. If "the raw type" does
not apply to this type, then the source type is returned.
getVMName
java.lang.String getVMName()
- Gets the VM name for this type. The JVMS3 defines an internal
name format for raw classes. We call this the VM name of a type.
It's useful for loading known types such as "java/lang/Object"
and "java/lang/Throwable". Here is how we define the "VM name"
for all types:
The VM name of a non-parametrized top-level type of the form
"pkg.Cls" is "pkg/Cls".
The VM name of a non-parametrized member-level type of the form
"pkg.Cls.InnerClass" is "pkg/Cls$InnerClass".
The VM name of a parametrized type is the VM name of the raw
type. Because parametrization is stripped at run-time, we will
omit it from the VM name.
The VM name of an array type T[] is the VM name of T suffixed by
the appropriate number of "[]"s.
The VM name of a local inner class or anonymous inner class is a
string that uniquely identifies it from all other types and is
usually prefixed with the VM name of its directly enclosing
class. For example, an anonymous inner class belonging to the
type "pkg.Cls" may return "pkg/Cls$1".
The VM name of any other type is the same as its source name.
- Returns:
- The raw name, also known as the VM name, of this type.
e.g. "java/lang/Object", "java/util/Map$Entry"
getDescriptor
java.lang.String getDescriptor()
- Gets the descriptor for this type, as defined by the JVMS2.
Note: The descriptor is equivalent to the type signature of this
type's erasure.
For jdk < 1.5, the "FieldDescriptor" is returned (JVMS2). For jdk
< 1.5, descriptors and signatures are the same thing.
For jdk >= 1.5, a type signature of the type erasure is
returned.
Note: Do not confuse a type's descriptor with a method's
descriptor. The descriptor of the type of a method is the field
descriptor describing its return type. The descriptor of a method
describes parameter types.
- Returns:
- The descriptor as defined in the JVMS2. Always non-null.
Example values: "I", "Ljava/lang/Object;"
getTypeSignature
java.lang.String getTypeSignature()
- Gets the type signature for this type, as defined by the
JVMS3.
A JavaClass returns its "ClassTypeSignature" (JVMS3). A JavaClass
is uniquely identified by its type signature. Example value:
Ljava/util/List;
A JavaTypeVariable returns its "TypeVariableSignature" (JVMS3). A
type variable is uniquely identified by the combination of its
owning declaration AND its type signature. Example value:
TE;
A WildcardType returns its "TypeArgument" value (JVMS3). A
wildcard type is uniquely identified by its type
signature. Example values: *
+Ljava/lang/Object;
.
- Returns:
- The type signature as defined in the JVMS3. Always
non-null.
getSignature
java.lang.String getSignature()
- Gets the "Signature" attribute of this type, as defined by the
JVMS3.
The "Signature" attribute for a field is the "ClassTypeSignature"
for its type.
The "Signature" attribute for a method involves the
"ClassSignature"s for its type parameters and the
"ClassTypeSignature"s of its remaining constituent types.
A JavaClass returns its "ClassSignature" (JVMS3).
A JavaTypeVariable does not have a class signature, but will
return a string for use in a class signature or a method
signature.
A WildcardType does not have a class signature and may not part
of a class signature. Its return value is undefined.
- Returns:
- The class signature as defined in the JVMS3. "A signature
is a string representing the generic type of a field or method,
or generic type information for a class declaration." Always
non-null.
getUniqueIdentifier
java.lang.String getUniqueIdentifier()
- Gets a unique identifier for this type. Two types are equal iff
their unique identifiers are equal.
- Specified by:
getUniqueIdentifier
in interface JavaMember
- Returns:
- The unique identifier for this type.
getPackage
JavaPackage getPackage()
- Gets the owning package, null if N/A.
- Returns:
- The owning compile-model package, null if this is a
primitive or an array type. Type parameters and wildcard types
return the owning package of the enclosing class.
getPackageName
java.lang.String getPackageName()
- Gets the qualified name of the owning package. Provided for
convenience.
- Returns:
- The qualified name of the owning package. Empty if none.
getSuperclass
JavaType getSuperclass()
- The name "getSuperclass" was chosen to be consistent with
java/lang/Class.
- Returns:
- The resolved superclass.
If this is a JavaClass: Null for java/lang/Object and
primitive types, non-null otherwise. Where no base class was
declared, java/lang/Object is returned, even for interfaces.
If this is a JavaType: Null if no superclass was declared AND an
interface was declared.
If this is a JavaWildcardType: Always null.
getInterfaces
java.util.Collection getInterfaces()
- The name "getInterfaces" was chosen to be consistent with
java/lang/Class.
- Returns:
- The array of resolved super-interfaces. May be
zero-length. Will include all implicit base interfaces, e.g. all
array types implement java/lang/Cloneable. Returns a collection
of JavaType's.
getUnresolvedInterfaces
java.util.Collection<UnresolvedType> getUnresolvedInterfaces()
- When reverse engineering byecode, some types cannot be resolved
if the correct owning project is not associated to the JavaProvider.
This method returns the set of interfaces this type implements
in the form of UnresolvedType's.
- Returns:
- The collection of UnresolvedType's.
getHierarchy
java.util.Set getHierarchy()
- Recursively gets the full list of all resolved superclasses and
super-interfaces. Order is depth-first, classes before
interfaces, left-to-right.
The full list of base classes and base interfaces does not have
duplicates.
Here, the definition of "hierarchy" is the set of types that this
type inherits members from. That is, "hierarchy" is defined by
the "inherits from" relationship rather than from the "is a
subtype of" relationship.
- Returns:
- The array of ALL base classes and base interfaces (including
java.lang.Object). Returns a collection of JavaType's.
isAssignableFrom
boolean isAssignableFrom(JavaType subject)
- Consider the following expression where S (subject) represents
another type and T (this) represents this type.
void method( S subject )
{
T variable = subject;
}
Notice that because the parameter subject is not a
constant-value, the assignment conversion will not perform the
implicit narrowing conversion.
NOTE: At the current writing, isAssignableFrom does not perform
auto-boxing.
- Returns:
- True if the above assignment is allowed. False if the
answer is not known or if the answer is no (i.e. a compile error
would be generated).
isSubtypeOf
boolean isSubtypeOf(JavaType supertype)
- True if this is a subtype of the indicated argument. Defined by
JLS 4.10.
getDeclaredFields
java.util.Collection getDeclaredFields()
- Returns:
- The array of all compile-model fields, synthetic or not,
including enum constants. Returns a collection of JavaField's.
getDeclaredField
JavaField getDeclaredField(java.lang.String name)
- Parameters:
name
- Require non-null.
- Returns:
- The first matching compile-model declared field. Null if none.
getDeclaredConstructors
java.util.Collection getDeclaredConstructors()
- Returns:
- The array of all compiled-model constructors, synthetic
or not. Returns a collection of JavaMethod's.
getDeclaredConstructor
JavaMethod getDeclaredConstructor(JavaType[] parameters)
- Parameters:
parameters
- Null indicates an empty parameter list.
- Returns:
- The first matching compile-model declared constructor.
Null if none.
getDeclaredMethods
java.util.Collection getDeclaredMethods()
- Returns:
- The array of all compile-model methods that are not
constructors. (What about the synthetic method? Returns
a collection of JavaMethod's.
getDeclaredMethods
java.util.Collection getDeclaredMethods(java.lang.String name)
- Returns:
- TThe array of matching compile-model declared methods.
getDeclaredMethod
JavaMethod getDeclaredMethod(java.lang.String name,
JavaType[] parameters)
- Parameters:
parameters
- Null indicates an empty parameter list.
- Returns:
- The first matching compile-model declared method. Null
if none.
getDeclaredClasses
java.util.Collection getDeclaredClasses()
- In order to get all inner classes, clients must recurse through
direct inner classes.
- Returns:
- The array of all direct compile-model inner classes,
including local and anonymous classes, synthetic or not. Note
that inner classes, including local and anonymous classes, are
direct inner classes of the most enclosing class. Hence, inner
classes declared within an inner class of the current class are
not direct inner classes of the current class. Returns a
collection of JavaClass's.
getDeclaredClass
JavaClass getDeclaredClass(java.lang.String name)
- Returns:
- The matching compile-model declared member class. Null if
none.
getClinitMethod
JavaMethod getClinitMethod()
- Returns:
- The method belonging to this JavaType. Null if none.
getFields
java.util.Collection getFields()
- Iteratively retrieves all fields declared in this class and its
hierarchy. The hierarchy dictates search order. This list, unlike
reflection, includes: private fields, package-private fields, and
hidden fields.
The implicit length field for array types is not reflected by
this method.
- Returns:
- A collection of JavaField's.
getField
JavaField getField(java.lang.String name)
- Iteratively searches for a field declared in this class or its
hierarchy. The hierarchy dictates search order.
The implicit length field for array types is not reflected by
this method.
- Parameters:
name
- Require non-null.
- Returns:
- The first matching field. Null if none.
getMethods
java.util.Collection getMethods()
- Iteratively retrieves all methods declared in this class or its
hierarchy. The hierarchy dictates search order. This list, unlike
reflection, includes: private methods and package-private methods.
This list does not include constructors
- Returns:
- A collection of JavaMethod's.
getMethods
java.util.Collection getMethods(java.lang.String name)
- Iteratively retrieves all methods declared in this class or its
hierarchy. The hierarchy dictates search order.
- Parameters:
name
- Require non-null.
- Returns:
- A collection of JavaMethod's with the matching name.
getMethod
JavaMethod getMethod(java.lang.String name,
JavaType[] parameters)
- Iteratively searches for a method declared in this class or its
hierarchy. The hierarchy dictates search order.
- Parameters:
name
- Require non-null.parameters
- Null indicates an empty parameter list.
- Returns:
- The first matching method. Null if none.
getClasses
java.util.Collection getClasses()
- Iteratively retrieves all member classes declared in this class
or its hierarchy. The hierarchy dictates search order. This list,
unlike reflection, includes: private member classes and
package-private member classes.
- Returns:
- A collection of JavaClass's.
getClass
JavaClass getClass(java.lang.String name)
- Iteratively retrieves all member classes declared in this class
or its hierarchy. The hierarchy dictates search order.
Note: Be careful not to get this confused with
JavaProvider.getClass( String ).
- Returns:
- The first matching member class. Null if none.
getURL
java.net.URL getURL()
- If the input for this type is a *.class file, the returned URL
will be for the *.class file. If the client wants a *.java URL,
the client should get the source element and then ask it what
it's URL is.
- Returns:
- The URL for this JavaType. Null if none.
equals
boolean equals(java.lang.Object o)
- Overrides:
equals
in class java.lang.Object
- Returns:
- True if o is a JavaType and has the same signature as
this class.
Copyright © 1997, 2011, Oracle. All rights reserved.