Class AnnotatedTypeMirror.AnnotatedIntersectionType
- All Implemented Interfaces:
DeepCopyable<AnnotatedTypeMirror>
- Enclosing class:
AnnotatedTypeMirror
For example: MyObject & Serializable & Comparable<MyObject>
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.framework.type.AnnotatedTypeMirror
AnnotatedTypeMirror.AnnotatedArrayType, AnnotatedTypeMirror.AnnotatedDeclaredType, AnnotatedTypeMirror.AnnotatedExecutableType, AnnotatedTypeMirror.AnnotatedIntersectionType, AnnotatedTypeMirror.AnnotatedNoType, AnnotatedTypeMirror.AnnotatedNullType, AnnotatedTypeMirror.AnnotatedPrimitiveType, AnnotatedTypeMirror.AnnotatedTypeVariable, AnnotatedTypeMirror.AnnotatedUnionType, AnnotatedTypeMirror.AnnotatedWildcardType, AnnotatedTypeMirror.ErrorTypeKindException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<AnnotatedTypeMirror> A list of the bounds of this which are also its direct super types.Fields inherited from class org.checkerframework.framework.type.AnnotatedTypeMirror
atypeFactory, EQUALITY_COMPARER, HASHCODE_VISITOR, primaryAnnotations, underlyingType -
Method Summary
Modifier and TypeMethodDescription<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.voidRemoves all primary annotations on this type and, in the case ofAnnotatedTypeMirror.AnnotatedTypeVariables,AnnotatedTypeMirror.AnnotatedWildcardTypes, andAnnotatedTypeMirror.AnnotatedIntersectionTypes, clears all bounds too, matchingAnnotatedTypeMirror.addAnnotation(javax.lang.model.element.AnnotationMirror)andAnnotatedTypeMirror.removeAnnotation(javax.lang.model.element.AnnotationMirror), which already propagate to bounds for those three kinds.deepCopy()Returns a deep copy of this type with annotations.deepCopy(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.This returns the bounds of the intersection type.getKind()Returns thekindof this type.Returns the underlying unannotated Java type, which this wraps.booleanRemoves a primary annotation from the type.voidsetBounds(List<AnnotatedTypeMirror> bounds) Sets the bounds.Returns a shallow copy of this type with annotations.shallowCopy(boolean copyAnnotations) Returns a shallow copy of this type.voidSummarizes this intersection's bounds into its own primary annotation, one hierarchy at a time: the first bound's qualifier there, or, if a later bound's qualifier conflicts, whateverAnnotatedTypeFactory.combineIntersectionBoundAnnotationsInHierarchy(AnnotationMirror, AnnotationMirror, QualifierHierarchy)returns.Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeMirror
addAnnotations, addAnnotations, addMissingAnnotation, addMissingAnnotations, addMissingAnnotations, asUse, checkMutable, containsCapturedTypes, createType, createTypeOfObject, createTypeOfRecord, equals, freeze, getAnnotation, getAnnotation, getAnnotationInHierarchy, getAnnotations, getAnnotationsField, getEffectiveAnnotation, getEffectiveAnnotationInHierarchy, getEffectiveAnnotations, getErased, getExplicitAnnotations, getPrimitiveKind, getUnderlyingTypeHashCode, hasAnnotation, hasAnnotation, hasAnnotationInHierarchy, hasAnnotationRelaxed, hasEffectiveAnnotation, hasEffectiveAnnotation, hasEffectiveAnnotationRelaxed, hasExplicitAnnotation, hasExplicitAnnotation, hasExplicitAnnotationRelaxed, hashCode, isDeclaration, isFrozen, removeAnnotationByClass, removeAnnotationInHierarchy, removeAnnotations, replaceAnnotation, replaceAnnotations, replaceAnnotations, toString, toString
-
Field Details
-
bounds
A list of the bounds of this which are also its direct super types.Is set by
shallowCopy(boolean).
-
-
Method Details
-
getKind
Description copied from class:AnnotatedTypeMirrorReturns 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.- Overrides:
getKindin classAnnotatedTypeMirror- Returns:
- the kind of this type
-
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.Also, copies
ato all the bounds.- Overrides:
addAnnotationin classAnnotatedTypeMirror- Parameters:
annotation- the annotation to add
-
removeAnnotation
Description copied from class:AnnotatedTypeMirrorRemoves a primary annotation from the type.- Overrides:
removeAnnotationin classAnnotatedTypeMirror- Parameters:
a- the annotation to remove- Returns:
- true if the 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, matchingAnnotatedTypeMirror.addAnnotation(javax.lang.model.element.AnnotationMirror)andAnnotatedTypeMirror.removeAnnotation(javax.lang.model.element.AnnotationMirror), which already propagate to bounds for those three kinds.Also clears every bound's annotations, for the same reason
removeAnnotation(AnnotationMirror)does: leaving a bound's annotations in place while clearing only the intersection's own primary annotation would let a bound keep a stale qualifier that a caller clearing this type is trying to discard, with no local signal that the two had gone out of sync.- Overrides:
clearAnnotationsin classAnnotatedTypeMirror
-
accept
Description copied from class:AnnotatedTypeMirrorApplies a visitor to this type.- Specified by:
acceptin classAnnotatedTypeMirror- 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
-
getUnderlyingType
Description copied from class:AnnotatedTypeMirrorReturns the underlying unannotated Java type, which this wraps.- Overrides:
getUnderlyingTypein classAnnotatedTypeMirror- Returns:
- the underlying type
-
deepCopy
Description copied from class:AnnotatedTypeMirrorReturns 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.
- Specified by:
deepCopyin classAnnotatedTypeMirror- Returns:
- a deep copy
-
deepCopy
Description copied from class:AnnotatedTypeMirrorReturns 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>- Specified by:
deepCopyin classAnnotatedTypeMirror- Returns:
- a deep copy of this type with annotations
- See Also:
-
shallowCopy
Description copied from class:AnnotatedTypeMirrorReturns 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.- Specified by:
shallowCopyin classAnnotatedTypeMirror- Parameters:
copyAnnotations- true if copy should have annotations, i.e., fieldannotationsshould be copied- Returns:
- a shallow copy of this type
-
shallowCopy
Description copied from class:AnnotatedTypeMirrorReturns 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).
- Specified by:
shallowCopyin classAnnotatedTypeMirror- Returns:
- a shallow copy of this type with annotations
- See Also:
-
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>.This returns the same types as
getBounds().- Overrides:
directSupertypesin classAnnotatedTypeMirror- Returns:
- the direct super types of this
- See Also:
-
getBounds
This returns the bounds of the intersection type. Although only declared types can appear in an explicitly written intersections, during capture conversion, intersections with other kinds of types are created.This returns the same types as
directSupertypes().The returned bounds are homogenized:
summarizeBounds()summarized the bounds' qualifiers into one qualifier per hierarchy and wrote that summary onto every bound (seeaddAnnotation(javax.lang.model.element.AnnotationMirror)), so a bound's own qualifier is not recoverable from this method, only from the summary. This is not just a precision optimization:DefaultTypeHierarchy's intersection subtyping methods (for examplevisitIntersection_Type) read only this method, never this intersection's own primary annotation directly, so a hierarchy left un-homogenized on a bound would not be seen by ordinary subtype checks at all. Homogenizing can also be strictly more precise than keeping each bound's own qualifier: a hierarchy that only one bound constrains is propagated to the others rather than defaulted away. For example, in@Odd Number & Cloneablethe@Oddsummary is written onto theCloneablebound, so a value of the intersection is@Oddwhen viewed asCloneable; per-bound qualifiers would instead default that view to top.- Returns:
- the bounds of this, which are also the direct super types of this
-
summarizeBounds
public void summarizeBounds()Summarizes this intersection's bounds into its own primary annotation, one hierarchy at a time: the first bound's qualifier there, or, if a later bound's qualifier conflicts, whateverAnnotatedTypeFactory.combineIntersectionBoundAnnotationsInHierarchy(AnnotationMirror, AnnotationMirror, QualifierHierarchy)returns. Adding the result as this intersection's own primary annotation homogenizes it onto every bound (seeaddAnnotation(javax.lang.model.element.AnnotationMirror)); a bound whose own annotation differs from the summary does not keep it, soBaseTypeVisitor.checkExplicitAnnotationsOnIntersectionBoundswarns when that annotation was explicit. Seeframework/tests/lubglb/IntersectionBoundOrderA.java.This reads each bound's qualifier via
AnnotatedTypeMirror.getAnnotationInHierarchy(javax.lang.model.element.AnnotationMirror), so it reflects whatever is on a bound when this method runs, uniformly whether that came from an explicit annotation or from defaulting — there is no separate explicit-only variant of this method. Which of those two a given caller sees depends only on when in the pipeline it calls this method:QualifierDefaultscalls it, for a type variable's own intersection upper bound, only after each bound has already been independently defaulted, so the combining hook sees every bound's real qualifier; calling it any earlier for that position would see only bounds' explicit annotations, since defaulting has not run yet. A type variable's own intersection upper bound is summarized only when the enclosingAnnotatedTypeFactoryrunsQualifierDefaults; one that does not (there is one in this repository, used only for debugging output) leaves it unsummarized.For an intersection cast target,
PropagationTreeAnnotator#visitTypeCastcalls this method, after it gave each bound the cast operand's qualifier in every hierarchy in which that bound has no written qualifier, as for the target of a cast to a non-intersection type. Seeframework/tests/lubglb/IntersectionCastBounds.java. -
setBounds
Sets the bounds.- Parameters:
bounds- a list of bounds to be captured by this method
-