public abstract class AnnotatedTypeMirror
extends java.lang.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 javax.lang.model.type.TypeMirror |
actualType
Actual type wrapped with this AnnotatedTypeMirror
|
protected java.util.Set<javax.lang.model.element.AnnotationMirror> |
annotations
The annotations on this type.
|
protected AnnotatedTypeFactory |
atypeFactory
The factory to use for lazily creating annotated types.
|
protected static EqualityAtmComparer |
equalityComparer |
protected static HashcodeAtmVisitor |
hashcodeVisitor |
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(javax.lang.model.element.AnnotationMirror a)
Adds an annotation to this type.
|
void |
addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
Adds an annotation to this type.
|
void |
addAnnotations(java.lang.Iterable<? extends javax.lang.model.element.AnnotationMirror> annotations)
Adds multiple annotations to this type.
|
void |
addMissingAnnotations(java.lang.Iterable<? extends javax.lang.model.element.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.
|
static AnnotatedTypeMirror |
createType(javax.lang.model.type.TypeMirror type,
AnnotatedTypeFactory atypeFactory,
boolean isDeclaration)
Creates the appropriate AnnotatedTypeMirror specific wrapper for the provided type
|
protected static AnnotatedTypeMirror.AnnotatedDeclaredType |
createTypeOfObject(AnnotatedTypeFactory atypeFactory) |
abstract AnnotatedTypeMirror |
deepCopy() |
abstract AnnotatedTypeMirror |
deepCopy(boolean copyAnnotations)
Returns a deep copy of this type.
|
java.util.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(java.lang.Object o) |
javax.lang.model.element.AnnotationMirror |
getAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annoClass)
Returns the actual annotation mirror used to annotate this type, whose Class equals the
passed annoClass if one exists, null otherwise.
|
javax.lang.model.element.AnnotationMirror |
getAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror p)
Returns an annotation from the given sub-hierarchy, if such an annotation targets this type;
otherwise returns null.
|
java.util.Set<javax.lang.model.element.AnnotationMirror> |
getAnnotations()
Returns the annotations on this type.
|
protected java.util.Set<javax.lang.model.element.AnnotationMirror> |
getAnnotationsField()
Returns the annotations on this type.
|
javax.lang.model.element.AnnotationMirror |
getEffectiveAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annoClass)
Returns the actual effective annotation mirror used to annotate this type, whose Class equals
the passed annoClass if one exists, null otherwise.
|
javax.lang.model.element.AnnotationMirror |
getEffectiveAnnotationInHierarchy(javax.lang.model.element.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.
|
java.util.Set<javax.lang.model.element.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.
|
java.util.Set<javax.lang.model.element.AnnotationMirror> |
getExplicitAnnotations()
Returns the set of explicitly written annotations on this type that are supported by this
checker.
|
javax.lang.model.type.TypeKind |
getKind()
Returns the
kind of this type |
javax.lang.model.type.TypeMirror |
getUnderlyingType()
Returns the underlying unannotated Java type, which this wraps
|
boolean |
hasAnnotation(javax.lang.model.element.AnnotationMirror a)
Determines whether this type contains the given annotation.
|
boolean |
hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
Determines whether this type contains an annotation with the same annotation type as a
particular annotation.
|
boolean |
hasAnnotationRelaxed(javax.lang.model.element.AnnotationMirror a)
Determines whether this type contains an annotation with the same annotation type as a
particular annotation.
|
boolean |
hasEffectiveAnnotation(javax.lang.model.element.AnnotationMirror a)
A version of hasAnnotation that considers annotations on the upper bound of wildcards and
type variables.
|
boolean |
hasEffectiveAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
A version of hasAnnotation that considers annotations on the upper bound of wildcards and
type variables.
|
boolean |
hasEffectiveAnnotationRelaxed(javax.lang.model.element.AnnotationMirror a)
A version of hasAnnotationRelaxed that considers annotations on the upper bound of wildcards
and type variables.
|
boolean |
hasExplicitAnnotation(javax.lang.model.element.AnnotationMirror a)
Determines whether this type contains the given annotation explicitly written at declaration.
|
boolean |
hasExplicitAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
Determines whether this type contains an explicitly written annotation with the same
annotation type as a particular annotation.
|
boolean |
hasExplicitAnnotationRelaxed(javax.lang.model.element.AnnotationMirror a)
A version of hasAnnotationRelaxed that only considers annotations that are explicitly written
on the type.
|
int |
hashCode() |
boolean |
isAnnotatedInHierarchy(javax.lang.model.element.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(javax.lang.model.element.AnnotationMirror a)
Removes an annotation from the type.
|
boolean |
removeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a) |
boolean |
removeAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror a)
Remove any annotation that is in the same qualifier hierarchy as the parameter.
|
boolean |
removeAnnotations(java.lang.Iterable<? extends javax.lang.model.element.AnnotationMirror> annotations)
Removes multiple annotations from the type.
|
boolean |
removeNonTopAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror a)
Remove an annotation that is in the same qualifier hierarchy as the parameter, unless it's
the top annotation.
|
void |
replaceAnnotation(javax.lang.model.element.AnnotationMirror a)
Adds an annotation to this type, removing any existing annotation from the same qualifier
hierarchy first.
|
void |
replaceAnnotations(java.lang.Iterable<? extends javax.lang.model.element.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.
|
java.lang.String |
toString() |
java.lang.String |
toString(boolean verbose) |
protected static final EqualityAtmComparer equalityComparer
protected static final HashcodeAtmVisitor hashcodeVisitor
protected final AnnotatedTypeFactory atypeFactory
protected final javax.lang.model.type.TypeMirror actualType
protected final java.util.Set<javax.lang.model.element.AnnotationMirror> annotations
public static AnnotatedTypeMirror createType(javax.lang.model.type.TypeMirror type, AnnotatedTypeFactory atypeFactory, boolean isDeclaration)
isDeclaration
- true if the result should is a type declarationpublic final boolean equals(java.lang.Object o)
equals
in class java.lang.Object
@Pure public final int hashCode()
hashCode
in class java.lang.Object
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 javax.lang.model.type.TypeKind getKind()
kind
of this typepublic javax.lang.model.type.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(javax.lang.model.element.AnnotationMirror p)
It doesn't account for annotations in deep types (type arguments, array components, etc).
p
- the qualifier hierarchy to check forpublic javax.lang.model.element.AnnotationMirror getAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror p)
It doesn't account for annotations in deep types (type arguments, array components, etc).
p
- the qualifier hierarchy to check forpublic javax.lang.model.element.AnnotationMirror getEffectiveAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror p)
It doesn't account for annotations in deep types (type arguments, array components, etc).
p
- the qualifier hierarchy to check forpublic final java.util.Set<javax.lang.model.element.AnnotationMirror> getAnnotations()
It does not include annotations in deep types (type arguments, array components, etc).
protected final java.util.Set<javax.lang.model.element.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 java.util.Set<javax.lang.model.element.AnnotationMirror> getEffectiveAnnotations()
public javax.lang.model.element.AnnotationMirror getAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annoClass)
annoClass
- annotation classpublic java.util.Set<javax.lang.model.element.AnnotationMirror> getExplicitAnnotations()
@MyExplicitAnno class MyClass { }; MyClass myClassInstance;
the result of calling atypeFactory.getAnnotatedType(variableTreeForMyClassInstance).getExplicitAnnotations()
will not contain @MyExplicitAnno
.
public boolean hasAnnotation(javax.lang.model.element.AnnotationMirror a)
In contrast to hasAnnotationRelaxed(AnnotationMirror)
this method also compares
annotation values.
a
- the annotation to check fora
hasAnnotationRelaxed(AnnotationMirror)
public boolean hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
a
- the class of annotation to check fora
public javax.lang.model.element.AnnotationMirror getEffectiveAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annoClass)
annoClass
- annotation classpublic boolean hasEffectiveAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
hasAnnotation(Class)
public boolean hasEffectiveAnnotation(javax.lang.model.element.AnnotationMirror a)
hasAnnotation(AnnotationMirror)
public boolean hasExplicitAnnotation(javax.lang.model.element.AnnotationMirror a)
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(javax.lang.model.element.AnnotationMirror a)
a
- the annotation to check fora
hasAnnotation(AnnotationMirror)
public boolean hasEffectiveAnnotationRelaxed(javax.lang.model.element.AnnotationMirror a)
hasAnnotationRelaxed(AnnotationMirror)
public boolean hasExplicitAnnotationRelaxed(javax.lang.model.element.AnnotationMirror a)
See the documentation for getExplicitAnnotations()
for details on which explicit
annotations are not included.
public boolean hasExplicitAnnotation(java.lang.Class<? extends java.lang.annotation.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(javax.lang.model.element.AnnotationMirror a)
a
- the annotation to addpublic void replaceAnnotation(javax.lang.model.element.AnnotationMirror a)
a
- the annotation to addpublic void addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
a
- the class of the annotation to addpublic void addAnnotations(java.lang.Iterable<? extends javax.lang.model.element.AnnotationMirror> annotations)
annotations
- the annotations to addpublic void addMissingAnnotations(java.lang.Iterable<? extends javax.lang.model.element.AnnotationMirror> annotations)
annotations
- the annotations to addpublic void replaceAnnotations(java.lang.Iterable<? extends javax.lang.model.element.AnnotationMirror> replAnnos)
replAnnos
- the annotations to replacepublic boolean removeAnnotation(javax.lang.model.element.AnnotationMirror a)
a
- the annotation to removepublic boolean removeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> a)
public boolean removeAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror a)
a
- an annotation from the same qualifier hierarchypublic boolean removeNonTopAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror a)
a
- an annotation from the same qualifier hierarchypublic boolean removeAnnotations(java.lang.Iterable<? extends javax.lang.model.element.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 java.lang.String toString()
toString
in class java.lang.Object
@SideEffectFree public final java.lang.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()
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()
shallowCopy(boolean)
protected static AnnotatedTypeMirror.AnnotatedDeclaredType createTypeOfObject(AnnotatedTypeFactory atypeFactory)
public java.util.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)