public abstract class AnnotatedTypeMirror extends Object
void
.
Types should be compared using the utility methods in AnnotatedTypes
. There is no
guarantee that any particular type will always be represented by the same object.
To implement operations based on the class of an AnnotatedTypeMirror
object, either
use a visitor or use the result of the getKind()
method.
TypeMirror
Modifier and Type | Class and Description |
---|---|
static class |
AnnotatedTypeMirror.AnnotatedArrayType
Represents Array types in java.
|
static class |
AnnotatedTypeMirror.AnnotatedDeclaredType
Represents a declared type (whether class or interface).
|
static class |
AnnotatedTypeMirror.AnnotatedExecutableType
Represents a type of an executable.
|
static class |
AnnotatedTypeMirror.AnnotatedIntersectionType |
static class |
AnnotatedTypeMirror.AnnotatedNoType
A pseudo-type used where no actual type is appropriate.
|
static class |
AnnotatedTypeMirror.AnnotatedNullType
Represents the null type.
|
static class |
AnnotatedTypeMirror.AnnotatedPrimitiveType
Represents a primitive type.
|
static class |
AnnotatedTypeMirror.AnnotatedTypeVariable
Represents a type variable.
|
static class |
AnnotatedTypeMirror.AnnotatedUnionType |
static class |
AnnotatedTypeMirror.AnnotatedWildcardType
Represents a wildcard type argument.
|
Modifier and Type | Field and Description |
---|---|
protected TypeMirror |
actualType
Actual type wrapped with this AnnotatedTypeMirror.
|
protected Set<AnnotationMirror> |
annotations
The annotations on this type.
|
protected AnnotatedTypeFactory |
atypeFactory
The factory to use for lazily creating annotated types.
|
protected static EqualityAtmComparer |
EQUALITY_COMPARER |
protected static HashcodeAtmVisitor |
HASHCODE_VISITOR |
Modifier and Type | Method and Description |
---|---|
abstract <R,P> R |
accept(AnnotatedTypeVisitor<R,P> v,
P p)
Applies a visitor to this type.
|
void |
addAnnotation(AnnotationMirror a)
Adds an annotation to this type.
|
void |
addAnnotation(Class<? extends Annotation> a)
Adds an annotation to this type.
|
void |
addAnnotations(Iterable<? extends AnnotationMirror> annotations)
Adds multiple annotations to this type.
|
void |
addMissingAnnotations(Iterable<? extends AnnotationMirror> annotations)
Adds those annotations to the current type, for which no annotation from the same qualifier
hierarchy is present.
|
AnnotatedTypeMirror |
asUse() |
void |
clearAnnotations()
Removes all primary annotations on this type.
|
boolean |
containsUninferredTypeArguments()
Returns whether this type or any component type is a wildcard type for which Java 7 type
inference is insufficient.
|
static AnnotatedTypeMirror |
createType(TypeMirror type,
AnnotatedTypeFactory atypeFactory,
boolean isDeclaration)
Creates the appropriate AnnotatedTypeMirror specific wrapper for the provided type.
|
protected static AnnotatedTypeMirror.AnnotatedDeclaredType |
createTypeOfObject(AnnotatedTypeFactory atypeFactory)
Create an
AnnotatedTypeMirror.AnnotatedDeclaredType with the underlying type of Object . |
abstract AnnotatedTypeMirror |
deepCopy()
Returns a deep copy of this type with annotations.
|
abstract AnnotatedTypeMirror |
deepCopy(boolean copyAnnotations)
Returns a deep copy of this type.
|
List<? extends AnnotatedTypeMirror> |
directSuperTypes()
This method returns a list of AnnotatedTypeMirrors where the Java type of each ATM is an
immediate supertype (class or interface) of the Java type of this.
|
boolean |
equals(Object o) |
@Nullable AnnotationMirror |
getAnnotation()
Returns the single annotation on this type.
|
AnnotationMirror |
getAnnotation(Class<? extends Annotation> annoClass)
Returns the actual annotation mirror used to annotate this type, whose Class equals the
passed annoClass if one exists, null otherwise.
|
AnnotationMirror |
getAnnotationInHierarchy(AnnotationMirror p)
Returns an annotation from the given sub-hierarchy, if such an annotation targets this type;
otherwise returns null.
|
Set<AnnotationMirror> |
getAnnotations()
Returns the annotations on this type.
|
protected Set<AnnotationMirror> |
getAnnotationsField()
Returns the annotations on this type.
|
AnnotationMirror |
getEffectiveAnnotation(Class<? extends Annotation> annoClass)
Returns the actual effective annotation mirror used to annotate this type, whose Class equals
the passed annoClass if one exists, null otherwise.
|
AnnotationMirror |
getEffectiveAnnotationInHierarchy(AnnotationMirror p)
Returns an annotation from the given sub-hierarchy, if such an annotation is present on this
type or on its extends bounds; otherwise returns null.
|
Set<AnnotationMirror> |
getEffectiveAnnotations()
Returns the "effective" annotations on this type, i.e.
|
AnnotatedTypeMirror |
getErased()
Returns the erasure type of the this type, according to JLS specifications.
|
Set<AnnotationMirror> |
getExplicitAnnotations()
Returns the set of explicitly written annotations on this type that are supported by this
checker.
|
TypeKind |
getKind()
Returns the
kind of this type. |
TypeKind |
getPrimitiveKind()
Given a primitive type, return its kind.
|
TypeMirror |
getUnderlyingType()
Returns the underlying unannotated Java type, which this wraps.
|
boolean |
hasAnnotation(AnnotationMirror a)
Determines whether this type contains the given annotation.
|
boolean |
hasAnnotation(Class<? extends Annotation> a)
Determines whether this type contains an annotation with the same annotation type as a
particular annotation.
|
boolean |
hasAnnotationRelaxed(AnnotationMirror a)
Determines whether this type contains an annotation with the same annotation type as a
particular annotation.
|
boolean |
hasEffectiveAnnotation(AnnotationMirror a)
A version of hasAnnotation that considers annotations on the upper bound of wildcards and
type variables.
|
boolean |
hasEffectiveAnnotation(Class<? extends Annotation> a)
A version of hasAnnotation that considers annotations on the upper bound of wildcards and
type variables.
|
boolean |
hasEffectiveAnnotationRelaxed(AnnotationMirror a)
A version of hasAnnotationRelaxed that considers annotations on the upper bound of wildcards
and type variables.
|
boolean |
hasExplicitAnnotation(AnnotationMirror a)
Determines whether this type contains the given annotation explicitly written at declaration.
|
boolean |
hasExplicitAnnotation(Class<? extends Annotation> a)
Determines whether this type contains an explicitly written annotation with the same
annotation type as a particular annotation.
|
boolean |
hasExplicitAnnotationRelaxed(AnnotationMirror a)
A version of hasAnnotationRelaxed that only considers annotations that are explicitly written
on the type.
|
int |
hashCode() |
boolean |
isAnnotatedInHierarchy(AnnotationMirror p)
Returns true if an annotation from the given sub-hierarchy targets this type.
|
boolean |
isDeclaration()
Returns true if this type mirror represents a declaration, rather than a use, of a type.
|
boolean |
removeAnnotation(AnnotationMirror a)
Removes an annotation from the type.
|
boolean |
removeAnnotation(Class<? extends Annotation> a)
Removes an annotation of the given class from the type.
|
boolean |
removeAnnotationInHierarchy(AnnotationMirror a)
Remove any annotation that is in the same qualifier hierarchy as the parameter.
|
boolean |
removeAnnotations(Iterable<? extends AnnotationMirror> annotations)
Removes multiple annotations from the type.
|
boolean |
removeNonTopAnnotationInHierarchy(AnnotationMirror a)
Remove an annotation that is in the same qualifier hierarchy as the parameter, unless it's
the top annotation.
|
void |
replaceAnnotation(AnnotationMirror a)
Adds an annotation to this type, removing any existing annotation from the same qualifier
hierarchy first.
|
void |
replaceAnnotations(Iterable<? extends AnnotationMirror> replAnnos)
Adds multiple annotations to this type, removing any existing annotations from the same
qualifier hierarchy first.
|
abstract AnnotatedTypeMirror |
shallowCopy()
Returns a shallow copy of this type with annotations.
|
abstract AnnotatedTypeMirror |
shallowCopy(boolean copyAnnotations)
Returns a shallow copy of this type.
|
String |
toString() |
String |
toString(boolean verbose) |
protected static final EqualityAtmComparer EQUALITY_COMPARER
protected static final HashcodeAtmVisitor HASHCODE_VISITOR
protected final AnnotatedTypeFactory atypeFactory
protected final TypeMirror actualType
protected final Set<AnnotationMirror> annotations
public static AnnotatedTypeMirror createType(TypeMirror type, AnnotatedTypeFactory atypeFactory, boolean isDeclaration)
type
- the underlying type for the resulting AnnotatedTypeMirroratypeFactory
- the type factory that will build the resultisDeclaration
- true if the result should represent a declaration, rather than a use, of
a typetype
public abstract <R,P> R accept(AnnotatedTypeVisitor<R,P> v, P p)
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 visitorpublic TypeKind getKind()
kind
of this type.public TypeKind getPrimitiveKind()
public TypeMirror getUnderlyingType()
public boolean isDeclaration()
For example, class List<T> { ... }
declares a new type List<T>
, while
List<Integer>
is a use of the type.
public AnnotatedTypeMirror asUse()
public boolean isAnnotatedInHierarchy(AnnotationMirror p)
It doesn't account for annotations in deep types (type arguments, array components, etc).
p
- the qualifier hierarchy to check forpublic AnnotationMirror getAnnotationInHierarchy(AnnotationMirror p)
It doesn't account for annotations in deep types (type arguments, array components, etc).
If there is only one hierarchy, you can use getAnnotation()
instead.
p
- the qualifier hierarchy to check forpublic AnnotationMirror getEffectiveAnnotationInHierarchy(AnnotationMirror p)
It doesn't account for annotations in deep types (type arguments, array components, etc).
p
- the qualifier hierarchy to check forpublic final Set<AnnotationMirror> getAnnotations()
To get the single annotation in a particular hierarchy, use getAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror)
. If there is only one hierarchy, you can use getAnnotation()
.
public final @Nullable AnnotationMirror getAnnotation()
This method requires that there is only a single hierarchy. In that case, it is equivalent
to getAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror)
.
this
is a
type variable or wildcard)getAnnotations()
protected final Set<AnnotationMirror> getAnnotationsField()
It does not include annotations in deep types (type arguments, array components, etc).
The returned set should not be modified, but for efficiency reasons modification is not prevented. Modifications might break invariants.
public Set<AnnotationMirror> getEffectiveAnnotations()
public AnnotationMirror getAnnotation(Class<? extends Annotation> annoClass)
annoClass
- annotation classpublic Set<AnnotationMirror> getExplicitAnnotations()
@MyExplicitAnno class MyClass {}; MyClass myClassInstance;
the result of calling atypeFactory.getAnnotatedType(variableTreeForMyClassInstance).getExplicitAnnotations()
will not contain @MyExplicitAnno
.
public boolean hasAnnotation(AnnotationMirror a)
In contrast to hasAnnotationRelaxed(AnnotationMirror)
this method also compares
annotation values.
a
- the annotation to check fora
hasAnnotationRelaxed(AnnotationMirror)
public boolean hasAnnotation(Class<? extends Annotation> a)
a
- the class of annotation to check fora
public AnnotationMirror getEffectiveAnnotation(Class<? extends Annotation> annoClass)
annoClass
- annotation classpublic boolean hasEffectiveAnnotation(Class<? extends Annotation> a)
hasAnnotation(Class)
public boolean hasEffectiveAnnotation(AnnotationMirror a)
hasAnnotation(AnnotationMirror)
public boolean hasExplicitAnnotation(AnnotationMirror a)
@A("s") @B(3)
Object
, a call with @A("t")
or @A
will return false, whereas a call with
@B(3)
will return true.
In contrast to hasExplicitAnnotationRelaxed(AnnotationMirror)
this method also
compares annotation values.
See the documentation for getExplicitAnnotations()
for details on which explicit
annotations are not included.
a
- the annotation to check fora
is explicitly written on the typehasExplicitAnnotationRelaxed(AnnotationMirror)
,
getExplicitAnnotations()
public boolean hasAnnotationRelaxed(AnnotationMirror a)
a
- the annotation to check fora
hasAnnotation(AnnotationMirror)
public boolean hasEffectiveAnnotationRelaxed(AnnotationMirror a)
hasAnnotationRelaxed(AnnotationMirror)
public boolean hasExplicitAnnotationRelaxed(AnnotationMirror a)
See the documentation for getExplicitAnnotations()
for details on which explicit
annotations are not included.
public boolean hasExplicitAnnotation(Class<? extends Annotation> a)
See the documentation for getExplicitAnnotations()
for details on which explicit
annotations are not included.
a
- the class of annotation to check fora
getExplicitAnnotations()
public void addAnnotation(AnnotationMirror a)
a
- the annotation to addpublic void replaceAnnotation(AnnotationMirror a)
a
- the annotation to addpublic void addAnnotation(Class<? extends Annotation> a)
a
- the class of the annotation to addpublic void addAnnotations(Iterable<? extends AnnotationMirror> annotations)
annotations
- the annotations to addpublic void addMissingAnnotations(Iterable<? extends AnnotationMirror> annotations)
annotations
- the annotations to addpublic void replaceAnnotations(Iterable<? extends AnnotationMirror> replAnnos)
replAnnos
- the annotations to replacepublic boolean removeAnnotation(AnnotationMirror a)
a
- the annotation to removepublic boolean removeAnnotation(Class<? extends Annotation> a)
a
- the class of the annotation to removepublic boolean removeAnnotationInHierarchy(AnnotationMirror a)
a
- an annotation from the same qualifier hierarchypublic boolean removeNonTopAnnotationInHierarchy(AnnotationMirror a)
a
- an annotation from the same qualifier hierarchypublic boolean removeAnnotations(Iterable<? extends AnnotationMirror> annotations)
annotations
- the annotations to removepublic void clearAnnotations()
This method should only be used in very specific situations. For individual type systems,
it is generally better to use removeAnnotation(AnnotationMirror)
and similar
methods.
@SideEffectFree public final String toString()
@SideEffectFree public final String toString(boolean verbose)
public AnnotatedTypeMirror getErased()
public abstract AnnotatedTypeMirror deepCopy(boolean copyAnnotations)
Note: deepCopy provides two important properties in the returned copy:
public abstract AnnotatedTypeMirror deepCopy()
Each subclass implements this method with the subclass return type. The method body must always be a call to deepCopy(true).
deepCopy(boolean)
public abstract AnnotatedTypeMirror shallowCopy(boolean copyAnnotations)
copyAnnotations
- whether copy should have annotations, i.e. whether field annotations
should be copied.public abstract AnnotatedTypeMirror shallowCopy()
Each subclass implements this method with the subclass return type. The method body must always be a call to shallowCopy(true).
shallowCopy(boolean)
public boolean containsUninferredTypeArguments()
protected static AnnotatedTypeMirror.AnnotatedDeclaredType createTypeOfObject(AnnotatedTypeFactory atypeFactory)
AnnotatedTypeMirror.AnnotatedDeclaredType
with the underlying type of Object
. It
includes any annotations placed by AnnotatedTypeFactory.fromElement(Element)
.atypeFactory
- type factory to usepublic List<? extends AnnotatedTypeMirror> directSuperTypes()
For example,
The direct supertype of the ATMclass B<T> { ... }
class A extends B<@NonNull String> { ... }
@Nullable A a;
@Nullable A
is @Nullable B<@NonNull String>
.
An example with more complex type arguments:
The direct supertype of the ATMclass D<Q,R> { ... }
class A<T,S> extends D<S,T> { ... }
@Nullable A<@NonNull String, @NonNull Object> a;
@Nullable A<@NonNull String, @NonNull Object>
is
@Nullable B<@NonNull Object, @NonNull String>
.
An example with more than one direct supertype:
The direct supertypes of the ATMclass B<T> implements List<Integer> { ... }
class A extends B<@NonNull String> implements List<Integer> { ... }
@Nullable A a;
@Nullable A
are @Nullable B <@NonNull
String>
and @Nullable List<@NonNull Integer>
.Types.directSupertypes(TypeMirror)