public abstract class Type extends AnnoConstruct implements TypeMirror
base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN), type `void' (tag: VOID), the bottom type (tag: BOT), the missing type (tag: NONE).
The behavior of the following types is defined in subclasses, which are all static inner classes of this class:
class types (tag: CLASS, class: ClassType), array types (tag: ARRAY, class: ArrayType), method types (tag: METHOD, class: MethodType), package types (tag: PACKAGE, class: PackageType), type variables (tag: TYPEVAR, class: TypeVar), type arguments (tag: WILDCARD, class: WildcardType), generic method types (tag: FORALL, class: ForAll), the error type (tag: ERROR, class: ErrorType).
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
TypeTag
Modifier and Type | Class and Description |
---|---|
static class |
Type.AnnotatedType |
static class |
Type.ArrayType |
static class |
Type.CapturedType
A captured type variable comes from wildcards which can have
both upper and lower bound.
|
static class |
Type.CapturedUndetVar
This class is used to represent synthetic captured inference variables
that can be generated during nested generic method calls.
|
static class |
Type.ClassType |
static class |
Type.DelegatedType |
static class |
Type.ErasedClassType |
static class |
Type.ErrorType |
static class |
Type.ForAll
The type of a generic method type.
|
static class |
Type.IntersectionClassType |
static class |
Type.JCNoType
Represents NONE.
|
static class |
Type.JCPrimitiveType |
static class |
Type.JCVoidType
Represents VOID.
|
static class |
Type.Mapping
An abstract class for mappings from types to types
|
static class |
Type.MethodType |
static class |
Type.PackageType |
static class |
Type.TypeVar |
static class |
Type.UndetVar
A class for inference variables, for use during method/diamond type
inference.
|
static class |
Type.UnionClassType |
static class |
Type.UnknownType |
static interface |
Type.Visitor<R,S>
A visitor for types.
|
static class |
Type.WildcardType |
Modifier and Type | Field and Description |
---|---|
static boolean |
moreInfo
If this switch is turned on, the names of type variables
and anonymous classes are printed with hashcodes appended.
|
static Type.JCNoType |
noType
Constant type: no type at all.
|
static Type.JCNoType |
recoveryType
Constant type: special type to be used during recovery of deferred expressions.
|
static Type.JCNoType |
stuckType
Constant type: special type to be used for marking stuck trees.
|
Symbol.TypeSymbol |
tsym
The defining class / interface / package / type variable.
|
Constructor and Description |
---|
Type(Symbol.TypeSymbol tsym)
Define a type given its tag and type symbol
|
Modifier and Type | Method and Description |
---|---|
<R,S> R |
accept(Type.Visitor<R,S> v,
S s) |
<R,P> R |
accept(TypeVisitor<R,P> v,
P p)
Applies a visitor to this type.
|
List<Type> |
allparams()
Return all parameters of this type and all its outer types in order
outer (first) to inner (last).
|
Type |
annotatedType(List<Attribute.TypeCompound> annos) |
String |
argtypes(boolean varargs) |
Symbol.TypeSymbol |
asElement() |
Type.MethodType |
asMethodType()
The underlying method type of this type.
|
Type |
baseType()
If this is a constant type, return its underlying type.
|
static List<Type> |
baseTypes(List<Type> ts)
Return the base types of a list of types.
|
void |
complete()
Complete loading all classes in this type.
|
Type |
constType(Object constValue)
Define a constant type, of the same kind as this type
and with given constant value
|
Object |
constValue()
The constant value of this type, null if this type does not
have a constant value attribute.
|
static boolean |
contains(List<Type> ts,
Type t) |
boolean |
contains(Type t)
Does this type contain occurrences of type t?
|
boolean |
containsAny(List<Type> ts)
Does this type contain an occurrence of some type in 'ts'?
|
static boolean |
containsAny(List<Type> ts1,
List<Type> ts2) |
boolean |
equals(Object t)
This method is analogous to isSameType, but weaker, since we
never complete classes.
|
static List<Type> |
filter(List<Type> ts,
Filter<Type> tf) |
<A extends Annotation> |
getAnnotation(Class<A> annotationType)
Returns this construct's annotation of the specified type if
such an annotation is present, else
null . |
List<Attribute.TypeCompound> |
getAnnotationMirrors()
Returns the annotations that are directly present on
this construct.
|
<A extends Annotation> |
getAnnotationsByType(Class<A> annotationType)
Returns annotations that are associated with this construct.
|
Type |
getEnclosingType() |
TypeKind |
getKind()
Returns the
kind of this type. |
Type |
getLowerBound() |
Type |
getModelType()
Get the representation of this type used for modelling purposes.
|
static List<Type> |
getModelTypes(List<Type> ts) |
Type |
getOriginalType()
For ErrorType, returns the original type, otherwise returns the type itself.
|
List<Type> |
getParameterTypes() |
Type |
getReceiverType() |
Type |
getReturnType() |
abstract TypeTag |
getTag()
Returns the current type tag.
|
List<Type> |
getThrownTypes() |
List<Type> |
getTypeArguments()
Access methods.
|
Type |
getUpperBound() |
int |
hashCode()
Obeys the general contract of
Object.hashCode . |
boolean |
hasTag(TypeTag tag)
Checks if the current type tag is equal to the given tag.
|
boolean |
isAnnotated() |
boolean |
isCompound() |
boolean |
isErroneous()
Does this type contain "error" elements?
|
static boolean |
isErroneous(List<Type> ts) |
boolean |
isExtendsBound() |
boolean |
isFalse()
Is this a constant type whose value is false?
|
boolean |
isFinal() |
boolean |
isInterface() |
boolean |
isNullOrReference() |
boolean |
isNumeric() |
boolean |
isParameterized()
Is this type parameterized?
A class type is parameterized if it has some parameters.
|
boolean |
isPartial() |
boolean |
isPrimitive() |
boolean |
isPrimitiveOrVoid() |
boolean |
isRaw()
Is this type a raw type?
A class type is a raw type if it misses some of its parameters.
|
boolean |
isReference() |
boolean |
isSuperBound() |
boolean |
isTrue()
Is this a constant type whose value is true?
|
boolean |
isUnbound() |
static List<Type> |
map(List<Type> ts,
Type.Mapping f)
map a type function over a list of types
|
Type |
map(Type.Mapping f)
map a type function over all immediate descendants of this type
|
String |
stringValue()
The constant value of this type, converted to String
|
String |
toString()
The Java source which this type represents.
|
static String |
toString(List<Type> ts)
The Java source which this type list represents.
|
Type |
unannotatedType()
If this is an annotated type, return the underlying type.
|
Type |
withTypeVar(Type t) |
getAttribute, getInheritedAnnotations
public static final Type.JCNoType noType
public static final Type.JCNoType recoveryType
public static final Type.JCNoType stuckType
public static boolean moreInfo
public Symbol.TypeSymbol tsym
public Type(Symbol.TypeSymbol tsym)
public boolean hasTag(TypeTag tag)
public abstract TypeTag getTag()
public boolean isNumeric()
public boolean isPrimitive()
public boolean isPrimitiveOrVoid()
public boolean isReference()
public boolean isNullOrReference()
public boolean isPartial()
public Object constValue()
public boolean isFalse()
public boolean isTrue()
public Type getModelType()
public Type getOriginalType()
public <R,S> R accept(Type.Visitor<R,S> v, S s)
public Type map(Type.Mapping f)
public static List<Type> map(List<Type> ts, Type.Mapping f)
public Type constType(Object constValue)
public Type baseType()
public Type annotatedType(List<Attribute.TypeCompound> annos)
public boolean isAnnotated()
public Type unannotatedType()
public List<Attribute.TypeCompound> getAnnotationMirrors()
AnnotatedConstruct
getAnnotationMirrors
in interface AnnotatedConstruct
getAnnotationMirrors
in class AnnoConstruct
public <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedConstruct
null
.
The annotation returned by this method could contain an element
whose value is of type Class
.
This value cannot be returned directly: information necessary to
locate and load a class (such as the class loader to use) is
not available, and the class might not be loadable at all.
Attempting to read a Class
object by invoking the relevant
method on the returned annotation
will result in a MirroredTypeException
,
from which the corresponding TypeMirror
may be extracted.
Similarly, attempting to read a Class[]
-valued element
will result in a MirroredTypesException
.
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation types currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation types.
getAnnotation
in interface AnnotatedConstruct
getAnnotation
in class AnnoConstruct
A
- the annotation typeannotationType
- the Class
object corresponding to
the annotation typenull
AnnotatedConstruct.getAnnotationMirrors()
,
AnnotatedElement.getAnnotation(java.lang.Class<T>)
,
EnumConstantNotPresentException
,
AnnotationTypeMismatchException
,
IncompleteAnnotationException
,
MirroredTypeException
,
MirroredTypesException
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType)
AnnotatedConstruct
AnnotatedConstruct.getAnnotation(Class)
is that this method detects if its argument is a repeatable
annotation type, and if so, attempts to find one or more
annotations of that type by "looking through" a container annotation.
The annotations returned by this method could contain an element
whose value is of type Class
.
This value cannot be returned directly: information necessary to
locate and load a class (such as the class loader to use) is
not available, and the class might not be loadable at all.
Attempting to read a Class
object by invoking the relevant
method on the returned annotation
will result in a MirroredTypeException
,
from which the corresponding TypeMirror
may be extracted.
Similarly, attempting to read a Class[]
-valued element
will result in a MirroredTypesException
.
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation types currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation types.
getAnnotationsByType
in interface AnnotatedConstruct
getAnnotationsByType
in class AnnoConstruct
A
- the annotation typeannotationType
- the Class
object corresponding to
the annotation typeAnnotatedConstruct.getAnnotationMirrors()
,
AnnotatedConstruct.getAnnotation(Class)
,
AnnotatedElement.getAnnotationsByType(Class)
,
EnumConstantNotPresentException
,
AnnotationTypeMismatchException
,
IncompleteAnnotationException
,
MirroredTypeException
,
MirroredTypesException
public static List<Type> baseTypes(List<Type> ts)
public String toString()
toString
in interface TypeMirror
toString
in class Object
public static String toString(List<Type> ts)
public String stringValue()
public boolean equals(Object t)
equals
in interface TypeMirror
equals
in class Object
t
- the object to be compared with this typetrue
if the specified object is equal to this onepublic int hashCode()
TypeMirror
Object.hashCode
.hashCode
in interface TypeMirror
hashCode
in class Object
TypeMirror.equals(java.lang.Object)
public String argtypes(boolean varargs)
public Type getEnclosingType()
public Type getReturnType()
public Type getReceiverType()
public Type getUpperBound()
public Type getLowerBound()
public List<Type> allparams()
public boolean isErroneous()
public boolean isParameterized()
public boolean isRaw()
public boolean isCompound()
public boolean isInterface()
public boolean isFinal()
public boolean contains(Type t)
public boolean containsAny(List<Type> ts)
public boolean isSuperBound()
public boolean isExtendsBound()
public boolean isUnbound()
public Type.MethodType asMethodType()
public void complete()
public Symbol.TypeSymbol asElement()
public TypeKind getKind()
TypeMirror
kind
of this type.getKind
in interface TypeMirror
public <R,P> R accept(TypeVisitor<R,P> v, P p)
TypeMirror
accept
in interface TypeMirror
R
- the return type of the visitor's methodsP
- the type of the additional parameter to the visitor's methodsv
- the visitor operating on this typep
- additional parameter to the visitorCopyright © 2015. All rights reserved.