Class AnnotatedTypeMirror
- All Implemented Interfaces:
DeepCopyable<AnnotatedTypeMirror>
- Direct Known Subclasses:
AnnotatedTypeMirror.AnnotatedArrayType,AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedExecutableType,AnnotatedTypeMirror.AnnotatedIntersectionType,AnnotatedTypeMirror.AnnotatedNoType,AnnotatedTypeMirror.AnnotatedNullType,AnnotatedTypeMirror.AnnotatedPrimitiveType,AnnotatedTypeMirror.AnnotatedTypeVariable,AnnotatedTypeMirror.AnnotatedUnionType,AnnotatedTypeMirror.AnnotatedWildcardType
primitive types,declared types(class and interface types),array types,type variables,wildcard type arguments,executable types(their signature and return types),intersection types,union types,the null type, andpseudo-typescorresponding to packages and to the keywordvoid.
To implement operations based on the class of an AnnotatedTypeMirror object, either
use a visitor or use the result of the getKind() method.
This class is mutable. Use methods shallowCopy(), deepCopy(), shallowCopy(boolean), or deepCopy(boolean) to get a shallow or deep copy of an
annotated type.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents Array types in java.static classRepresents a declared type (whether class or interface).static classRepresents a type of an executable.static classRepresents an intersection type.static classA pseudo-type used where no actual type is appropriate.static classRepresents the null type.static classRepresents a primitive type.static classRepresents a type variable.static classRepresents a union type, the type of a multi-catch parameter (for example,catch (IOException | SQLException e)).static classRepresents a wildcard type argument.static classAn ERROR TypeKind was found. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AnnotatedTypeFactoryThe factory to use for lazily creating annotated types.protected static final EqualityAtmComparerAn EqualityAtmComparer.protected static final HashcodeAtmVisitorA HashcodeAtmVisitor.protected final AnnotationMirrorSetThe annotations on this type.protected final TypeMirrorThe actual type wrapped by this AnnotatedTypeMirror. -
Method Summary
Modifier and TypeMethodDescriptionabstract <R,P> R accept(AnnotatedTypeVisitor<R, P> v, P p) Applies a visitor to this type.voidaddAnnotation(AnnotationMirror annotation) Adds the canonical version ofannotationas a primary annotation of this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, adds it to all bounds.voidaddAnnotations(Iterable<? extends AnnotationMirror> annotations) Adds the canonical version of allannotationsas primary annotations of this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, adds them to all bounds.voidaddAnnotations(AnnotationMirrorSet annotations) Adds multiple annotations to this type.voidaddMissingAnnotation(AnnotationMirror annotation) Addannotationif the type does not already have a primary annotation in the same hierarchy.voidaddMissingAnnotations(Iterable<? extends AnnotationMirror> annotations) Adds only the annotations inannotationsthat the type does not already have a primary annotation in the same hierarchy.voidaddMissingAnnotations(AnnotationMirrorSet annotations) Adds only the annotations inannotationsfor which the type does not already have a primary annotation in the same hierarchy.asUse()protected final voidvoidRemoves all primary annotations on this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, clears all bounds too, matchingaddAnnotation(javax.lang.model.element.AnnotationMirror)andremoveAnnotation(javax.lang.model.element.AnnotationMirror), which already propagate to bounds for those three kinds.booleanWhether this type contains any captured type variables.static AnnotatedTypeMirrorcreateType(TypeMirror type, AnnotatedTypeFactory atypeFactory, boolean isDeclaration) Creates an empty AnnotatedTypeMirror for the provided type.protected static AnnotatedTypeMirror.AnnotatedDeclaredTypecreateTypeOfObject(AnnotatedTypeFactory atypeFactory) Create anAnnotatedTypeMirror.AnnotatedDeclaredTypewith the underlying type ofObject.protected static AnnotatedTypeMirror.AnnotatedDeclaredTypecreateTypeOfRecord(AnnotatedTypeFactory atypeFactory) Create anAnnotatedTypeMirror.AnnotatedDeclaredTypewith the underlying type ofjava.lang.Record.abstract AnnotatedTypeMirrordeepCopy()Returns a deep copy of this type with annotations.abstract AnnotatedTypeMirrordeepCopy(boolean copyAnnotations) Returns a deep copy of this type.List<? extends AnnotatedTypeMirror> 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.final booleanfinal voidfreeze()Freezes this type and every type reachable from it that has already been initialized, making them effectively immutable: subsequent attempts to change their primary annotations throwBugInCF.getAnnotation(Class<? extends Annotation> annoClass) Returns the primary annotation on this type whose class isannoClass.getAnnotation(String annoName) Returns the primary annotations on this type whose annotation class nameannoName.getAnnotationInHierarchy(AnnotationMirror annotation) Returns the primary annotation on this type that is in the same hierarchy asannotation.final AnnotationMirrorSetReturns the primary annotations on this type.protected final AnnotationMirrorSetReturns the annotations on this type; mutations affect this object, because the return type is an alias of theannotationsfield.getEffectiveAnnotation(Class<? extends Annotation> annoClass) Returns the "effective" annotation on this type with the classannoClassornullif this type does not have one.getEffectiveAnnotationInHierarchy(AnnotationMirror annotation) Returns the "effective" annotation from the same hierarchy asannotation, otherwise returnsnull.Returns the "effective" annotations on this type, i.e.Returns the erasure type of this type, according to JLS specifications.Returns the set of explicitly written annotations on this type that this checker recognizes -- directly, or via an alias.getKind()Returns thekindof this type.Given a primitive type, return its kind.Returns the underlying unannotated Java type, which this wraps.protected intReturns a hash for theunderlyingType.booleanhasAnnotation(Class<? extends Annotation> a) Returns true if this type has a primary annotation that has the same annotation type asa.booleanReturns true if this type has a primary annotation that is the same asa.booleanhasAnnotationInHierarchy(AnnotationMirror annotation) Returns true if this type has a primary annotation in the same hierarchy asannotation.booleanReturns true if this type has a primary annotation that has the same annotation class asa.booleanhasEffectiveAnnotation(Class<? extends Annotation> a) A version ofhasAnnotation(Class)that considers annotations on the upper bound of wildcards and type variables.booleanA version ofhasAnnotation(AnnotationMirror)that considers annotations on the upper bound of wildcards and type variables.booleanA version ofhasAnnotationRelaxed(AnnotationMirror)that considers annotations on the upper bound of wildcards and type variables.booleanhasExplicitAnnotation(Class<? extends Annotation> a) Returns true if this type contains an explicitly written annotation with the same annotation type as a particular annotation.booleanReturns true if this type contains the given annotation explicitly written at declaration.booleanA version ofhasAnnotationRelaxed(AnnotationMirror)that only considers annotations that are explicitly written on the type.final inthashCode()booleanReturns true if this type mirror represents a declaration, rather than a use, of a type.final booleanisFrozen()Returns true if this type has been frozen.booleanRemoves a primary annotation from the type.booleanremoveAnnotationByClass(Class<? extends Annotation> a) Removes a primary annotation of the given class from the type.booleanRemove any primary annotation that is in the same qualifier hierarchy as the parameter.booleanremoveAnnotations(Iterable<? extends AnnotationMirror> annotations) Removes multiple primary annotations from the type.voidAdds an annotation to this type, removing any existing primary annotations from the same qualifier hierarchy first.voidreplaceAnnotations(Iterable<? extends AnnotationMirror> replAnnos) Adds multiple annotations to this type, removing any existing primary annotations from the same qualifier hierarchy first.voidreplaceAnnotations(AnnotationMirrorSet replAnnos) Adds multiple annotations to this type, removing any existing primary annotations from the same qualifier hierarchy first.abstract AnnotatedTypeMirrorReturns a shallow copy of this type with annotations.abstract AnnotatedTypeMirrorshallowCopy(boolean copyAnnotations) Returns a shallow copy of this type.final StringtoString()Returns a string representation of this type, using the type factory'sAnnotatedTypeFormatter.final StringtoString(boolean verbose) Returns a possibly-verbose string representation of this type.
-
Field Details
-
EQUALITY_COMPARER
An EqualityAtmComparer. -
HASHCODE_VISITOR
A HashcodeAtmVisitor. -
atypeFactory
The factory to use for lazily creating annotated types. -
underlyingType
The actual type wrapped by this AnnotatedTypeMirror. -
The annotations on this type.
-
-
Method Details
-
createType
public static AnnotatedTypeMirror createType(TypeMirror type, AnnotatedTypeFactory atypeFactory, boolean isDeclaration) Creates an empty AnnotatedTypeMirror for the provided type. The result contains no annotations.- Parameters:
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 type- Returns:
- an AnnotatedTypeMirror whose underlying type is
type
-
equals
-
hashCode
-
accept
Applies a visitor to this type.- Type Parameters:
R- the return type of the visitor's methodsP- the type of the additional parameter to the visitor's methods- Parameters:
v- the visitor operating on this typep- additional parameter to the visitor- Returns:
- a visitor-specified result
-
getKind
Returns thekindof this type.Subclasses whose kind is constant (e.g.
AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedArrayType) override this to return the constant directly; this is meaningful for performance because the underlying javacType#getKind()on declared types runsSymbol#apiComplete. OnlyAnnotatedTypeMirror.AnnotatedPrimitiveTypeandAnnotatedTypeMirror.AnnotatedNoTypefall through to this base implementation; for both, the underlying type'sgetKind()is cheap and does not force symbol completion.- Returns:
- the kind of this type
-
getPrimitiveKind
Given a primitive type, return its kind. Given a boxed primitive type, return the corresponding primitive type kind. Otherwise, return null.- Returns:
- a primitive type kind if this is a primitive type or boxed primitive type; otherwise null
-
getUnderlyingType
Returns the underlying unannotated Java type, which this wraps.- Returns:
- the underlying type
-
isDeclaration
public boolean isDeclaration()Returns true if this type mirror represents a declaration, rather than a use, of a type.For example,
class List<T> { ... }declares a new typeList<T>, whileList<Integer>is a use of the type.- Returns:
- true if this represents a declaration
-
asUse
-
hasAnnotationInHierarchy
Returns true if this type has a primary annotation in the same hierarchy asannotation.This method does not account for annotations in deep types (type arguments, array components, etc).
- Parameters:
annotation- the qualifier hierarchy to check for- Returns:
- true iff this type has a primary annotation in the same hierarchy as
annotation
-
getAnnotationInHierarchy
Returns the primary annotation on this type that is in the same hierarchy asannotation. ForAnnotatedTypeMirror.AnnotatedTypeVariables andAnnotatedTypeMirror.AnnotatedWildcardTypes,nullmay be returned when the upper bound may have an annotation with that class, sogetEffectiveAnnotationInHierarchy(AnnotationMirror)should be called instead.This method does not account for annotations in deep types (type arguments, array components, etc).
May return null if the receiver is a type variable or a wildcard without a primary annotation, or if the receiver is not yet fully annotated.
- Parameters:
annotation- an annotation in the qualifier hierarchy to check for, or an alias for one- Returns:
- the annotation mirror whose class is named
annoNAmeor null
-
getEffectiveAnnotationInHierarchy
Returns the "effective" annotation from the same hierarchy asannotation, otherwise returnsnull.An effective annotation is the annotation on the type itself, or on the upper/extends bound of a type variable/wildcard (recursively, until a class type is reached).
- Parameters:
annotation- an annotation in the qualifier hierarchy to check for, or an alias for one- Returns:
- an annotation from the same hierarchy as
annotationif present
-
getAnnotations
Returns the primary annotations on this type. ForAnnotatedTypeMirror.AnnotatedTypeVariables andAnnotatedTypeMirror.AnnotatedWildcardTypes, the returned annotations may be empty or missing annotations in hierarchies, sogetEffectiveAnnotations()should be called instead.It does not include annotations in deep types (type arguments, array components, etc).
To get the single primary annotation in a particular hierarchy, use
getAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror).- Returns:
- an unmodifiable set of the annotations on this
-
getAnnotationsField
Returns the annotations on this type; mutations affect this object, because the return type is an alias of theannotationsfield. 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.
- Returns:
- the set of the annotations on this; mutations affect this object
-
getEffectiveAnnotations
Returns the "effective" annotations on this type, i.e. the annotations on the type itself, or on the upper/extends bound of a type variable/wildcard (recursively, until a class type is reached). If this is fully-annotated, the returned set will contain one annotation per hierarchy.- Returns:
- a set of the annotations on this
-
getAnnotation
Returns the primary annotation on this type whose class isannoClass. ForAnnotatedTypeMirror.AnnotatedTypeVariables andAnnotatedTypeMirror.AnnotatedWildcardTypes,nullmay be returned when the upper bound may have an annotation with that class, sogetEffectiveAnnotation(Class)should be called instead.- Parameters:
annoClass- annotation class- Returns:
- the annotation mirror whose class is
annoClassor null
-
getAnnotation
Returns the primary annotations on this type whose annotation class nameannoName. ForAnnotatedTypeMirror.AnnotatedTypeVariables andAnnotatedTypeMirror.AnnotatedWildcardTypes,nullmay be returned when the upper bound may have an annotation with that class, sogetEffectiveAnnotation(Class)should be called instead.- Parameters:
annoName- annotation class name- Returns:
- the annotation mirror whose class is named
annoNameor null
-
getExplicitAnnotations
Returns the set of explicitly written annotations on this type that this checker recognizes -- directly, or via an alias. An alias is replaced by its canonical form, since every caller of this method has needed the canonical form to compare against, and none has needed to recover which literal alias was written. This is useful to check the validity of annotations explicitly present on a type, as flow inference might add annotations that were not previously present. Note that since AnnotatedTypeMirror instances are created for type uses, this method will return explicit annotations in type use locations but will not return explicit annotations that had an impact on defaulting, such as an explicit annotation on a class declaration. For example, given:@MyExplicitAnno class MyClass {}; MyClass myClassInstance;the result of calling
atypeFactory.getAnnotatedType(variableTreeForMyClassInstance).getExplicitAnnotations()will not contain
@MyExplicitAnno.- Returns:
- the set of explicitly written annotations on this type that this checker recognizes, directly or via an alias; each in canonical form
-
hasAnnotation
Returns true if this type has a primary annotation that is the same asa.This method considers the annotation's values. If the type is
@A("s") @B(3) Object, then a call with@A("t")or@Awill return false, whereas a call with@B(3)will return true.In contrast to
hasAnnotationRelaxed(AnnotationMirror)this method also compares annotation values.- Parameters:
a- the annotation to check for- Returns:
- true iff this type has a primary annotation that is the same as
a - See Also:
-
hasAnnotation
Returns true if this type has a primary annotation that has the same annotation type asa. This method does not consider an annotation's values.- Parameters:
a- the class of annotation to check for- Returns:
- true iff the type contains an annotation with the same type as the annotation given
by
a
-
getEffectiveAnnotation
Returns the "effective" annotation on this type with the classannoClassornullif this type does not have one.An effective annotation is the annotation on the type itself, or on the upper/extends bound of a type variable/wildcard (recursively, until a class type is reached).
- Parameters:
annoClass- annotation class- Returns:
- the effective annotation with the same class as
annoClass
-
hasEffectiveAnnotation
A version ofhasAnnotation(Class)that considers annotations on the upper bound of wildcards and type variables. -
hasEffectiveAnnotation
A version ofhasAnnotation(AnnotationMirror)that considers annotations on the upper bound of wildcards and type variables. -
hasExplicitAnnotation
Returns true if this type contains the given annotation explicitly written at declaration. This method considers the annotation's values. If the type is@A("s") @B(3) Object, a call with@A("t")or@Awill 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.- Parameters:
a- the annotation to check for- Returns:
- true iff the annotation
ais explicitly written on the type - See Also:
-
hasAnnotationRelaxed
Returns true if this type has a primary annotation that has the same annotation class asa.This method does not consider an annotation's values. If the type is
@A("s") @B(3) Object, then a call with@A("t"),@A, or@Bwill return true.- Parameters:
a- the annotation to check for- Returns:
- true iff the type has a primary annotation with the same type as
a - See Also:
-
hasEffectiveAnnotationRelaxed
A version ofhasAnnotationRelaxed(AnnotationMirror)that considers annotations on the upper bound of wildcards and type variables. -
hasExplicitAnnotationRelaxed
A version ofhasAnnotationRelaxed(AnnotationMirror)that only considers annotations that are explicitly written on the type.See the documentation for
getExplicitAnnotations()for details on which explicit annotations are not included. -
hasExplicitAnnotation
Returns true if this type contains an explicitly written annotation with the same annotation type as a particular annotation. This method does not consider an annotation's values.See the documentation for
getExplicitAnnotations()for details on which explicit annotations are not included.- Parameters:
a- the class of annotation to check for- Returns:
- true iff the type contains an explicitly written annotation with the same type as the
annotation given by
a - See Also:
-
addAnnotation
Adds the canonical version ofannotationas a primary annotation of this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, adds it to all bounds. (The canonical version is found viaAnnotatedTypeFactory.asSupportedQualifier(javax.lang.model.element.AnnotationMirror).) If the canonical version ofannotationis not a supported qualifier, then no annotation is added. If this type already has annotation in the same hierarchy asannotation, the behavior of this method is undefined.- Parameters:
annotation- the annotation to add
-
replaceAnnotation
Adds an annotation to this type, removing any existing primary annotations from the same qualifier hierarchy first.- Parameters:
a- the annotation to add
-
addAnnotations
Adds the canonical version of allannotationsas primary annotations of this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, adds them to all bounds. (The canonical version is found viaAnnotatedTypeFactory.canonicalAnnotation(javax.lang.model.element.AnnotationMirror).) If the canonical version of anannotationis not a supported qualifier, then that annotation is not add added. If this type already has annotation in the same hierarchy as any of theannotations, the behavior of this method is undefined.- Parameters:
annotations- the annotations to add
-
addAnnotations
Adds multiple annotations to this type. AnAnnotationMirrorSet-typed overload ofaddAnnotations(Iterable): overload resolution prefers it for the many callers that passgetAnnotationsField()orgetAnnotations(), letting them iterate by index rather than allocating anIterator. Iterating anAnnotationMirrorSetwas the single largest source ofArrayList$Itrallocations in nullness-checking JFR traces, and this method was its largest caller.- Parameters:
annotations- the annotations to add
-
addMissingAnnotations
Adds only the annotations inannotationsthat the type does not already have a primary annotation in the same hierarchy.The canonical version of the
annotationsare added as primary annotations of this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, adds them to all bounds. (The canonical version is found viaAnnotatedTypeFactory.canonicalAnnotation(javax.lang.model.element.AnnotationMirror).) If the canonical version of an annotation is not a supported qualifier, then that annotation is not add added.- Parameters:
annotations- the annotations to add
-
addMissingAnnotations
Adds only the annotations inannotationsfor which the type does not already have a primary annotation in the same hierarchy. AnAnnotationMirrorSet-typed overload ofaddMissingAnnotations(Iterable)that iterates by index instead of allocating anIterator.- Parameters:
annotations- the annotations to add
-
addMissingAnnotation
Addannotationif the type does not already have a primary annotation in the same hierarchy.The canonical version of the
annotationis added as a primary annotation of this type and (in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes) added to all bounds. (The canonical version is found viaAnnotatedTypeFactory.canonicalAnnotation(javax.lang.model.element.AnnotationMirror).) If the canonical version of anannotationis not a supported qualifier, then that annotation is not add added.- Parameters:
annotation- the annotations to add
-
replaceAnnotations
Adds multiple annotations to this type, removing any existing primary annotations from the same qualifier hierarchy first.- Parameters:
replAnnos- the annotations to replace
-
replaceAnnotations
Adds multiple annotations to this type, removing any existing primary annotations from the same qualifier hierarchy first. AnAnnotationMirrorSet-typed overload ofreplaceAnnotations(Iterable)that iterates by index instead of allocating anIterator.- Parameters:
replAnnos- the annotations to replace
-
removeAnnotation
Removes a primary annotation from the type.- Parameters:
a- the annotation to remove- Returns:
- true if the annotation was removed, false if the type's annotations were unchanged
-
removeAnnotationByClass
Removes a primary annotation of the given class from the type.- Parameters:
a- the class of the annotation to remove- Returns:
- true if the annotation was removed, false if the type's annotations were unchanged
-
removeAnnotationInHierarchy
Remove any primary annotation that is in the same qualifier hierarchy as the parameter.- Parameters:
a- an annotation from the same qualifier hierarchy- Returns:
- if an annotation was removed
-
removeAnnotations
Removes multiple primary annotations from the type.- Parameters:
annotations- the annotations to remove- Returns:
- true if at least one annotation was removed, false if the type's annotations were unchanged
-
clearAnnotations
public void clearAnnotations()Removes all primary annotations on this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, clears all bounds too, matchingaddAnnotation(javax.lang.model.element.AnnotationMirror)andremoveAnnotation(javax.lang.model.element.AnnotationMirror), which already propagate to bounds for those three kinds. -
checkMutable
protected final void checkMutable()ThrowsBugInCFif this type is frozen. Called by the primary annotation mutators before they change anything, so that a frozen (shared) type cannot be corrupted in place. Callers that need to change a frozen type mustdeepCopy()it first and mutate the copy. -
isFrozen
public final boolean isFrozen()Returns true if this type has been frozen.- Returns:
- true if this type is frozen
-
freeze
public final void freeze()Freezes this type and every type reachable from it that has already been initialized, making them effectively immutable: subsequent attempts to change their primary annotations throwBugInCF. Idempotent.This does not force lazy initialization of uninitialized components (type-variable and wildcard bounds, type arguments, etc.); doing so would be expensive and is unnecessary. Instead, the lazy getters freeze any component they create while this type is frozen, so the reachable graph stays fully frozen without eagerly materializing it.
Cycles (for example a recursive type variable whose bound refers back to itself) terminate because
frozenis set beforefreezeComponents()recurses: a re-entry on a type already being frozen returns immediately. -
toString
Returns a string representation of this type, using the type factory'sAnnotatedTypeFormatter. Whether details such as invisible qualifiers appear depends on that formatter's configuration. -
toString
Returns a possibly-verbose string representation of this type. Verbose printing shows details thattoString()might omit, such as invisible qualifiers and the bounds of type variables and wildcards; it never omits a detail thattoString()shows. Therefore,toString(false)returns the same string astoString():verboseasks for optional extra detail on top oftoString()'s output, not for a specific level of detail in its own right, so there is no argument that requests less detail thantoString()already provides.- Parameters:
verbose- if true, print details thattoString()might omit- Returns:
- a possibly-verbose string representation of this type
-
getErased
Returns the erasure type of this type, according to JLS specifications.- Returns:
- the erasure of this AnnotatedTypeMirror, this is always a copy even if the erasure and the original type are equivalent
- See Also:
-
deepCopy
Returns a deep copy of this type. A deep copy implies that each component type is copied recursively and the returned type refers to those copies in its component locations.Note: deepCopy provides two important properties in the returned copy:
- Structure preservation -- The exact structure of the original AnnotatedTypeMirror is preserved in the copy including all component types.
- Annotation preservation -- All of the annotations from the original AnnotatedTypeMirror and its components have been copied to the new type.
- Returns:
- a deep copy
-
deepCopy
Returns a deep copy of this type with annotations.Each subclass implements this method with the subclass return type. The method body must always be a call to deepCopy(true).
- Specified by:
deepCopyin interfaceDeepCopyable<AnnotatedTypeMirror>- Returns:
- a deep copy of this type with annotations
- See Also:
-
shallowCopy
Returns a shallow copy of this type. A shallow copy implies that each component type in the output copy refers to the same object as the object being copied.- Parameters:
copyAnnotations- true if copy should have annotations, i.e., fieldannotationsshould be copied- Returns:
- a shallow copy of this type
-
shallowCopy
Returns a shallow copy of this type with annotations.Each subclass implements this method with the subclass return type. The method body must always be a call to shallowCopy(true).
- Returns:
- a shallow copy of this type with annotations
- See Also:
-
containsCapturedTypes
public boolean containsCapturedTypes()Whether this type contains any captured type variables.- Returns:
- whether this type contains any captured type variables
-
createTypeOfObject
protected static AnnotatedTypeMirror.AnnotatedDeclaredType createTypeOfObject(AnnotatedTypeFactory atypeFactory) Create anAnnotatedTypeMirror.AnnotatedDeclaredTypewith the underlying type ofObject. It includes any annotations placed byAnnotatedTypeFactory.fromElement(Element).- Parameters:
atypeFactory- type factory to use- Returns:
- AnnotatedDeclaredType for Object
-
createTypeOfRecord
protected static AnnotatedTypeMirror.AnnotatedDeclaredType createTypeOfRecord(AnnotatedTypeFactory atypeFactory) Create anAnnotatedTypeMirror.AnnotatedDeclaredTypewith the underlying type ofjava.lang.Record. It includes any annotations placed byAnnotatedTypeFactory.fromElement(Element).- Parameters:
atypeFactory- type factory to use- Returns:
- AnnotatedDeclaredType for Record
-
getUnderlyingTypeHashCode
protected int getUnderlyingTypeHashCode()Returns a hash for theunderlyingType. This method saves the result in a field so that it is not recomputed each time.For
TypeKinds whoseTypeMirror.equals(java.lang.Object)contract is effectively identity (primitives, void, none, null, package), this method avoids the toString-based hash entirely and uses the kind's ordinal. This is safe because types of those kinds are canonicalized by javac and cannot be structurally equal without being reference-equal.- Returns:
- a hash for the underlying type that is consistent with
TypeMirror.equals(java.lang.Object)
-
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. The interface types, if any, appear at the end of the list. If the directSuperType has type arguments, then the annotations on those type arguments are taken with proper translation from the declaration of the Java type of this.For example,
The direct supertype of the ATMclass B<T> { ... }class A extends B<@NonNull String> { ... }@Nullable A a;@Nullable Ais@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 Aare@Nullable B <@NonNull String>and@Nullable List<@NonNull Integer>.- Returns:
- the immediate supertypes of this
- See Also:
-