Class AnnotatedTypeMirror.AnnotatedUnionType
- All Implemented Interfaces:
DeepCopyable<AnnotatedTypeMirror>
- Enclosing class:
AnnotatedTypeMirror
catch
(IOException | SQLException e)).
Unlike AnnotatedTypeMirror.AnnotatedIntersectionType, AnnotatedTypeMirror.AnnotatedTypeVariable, and AnnotatedTypeMirror.AnnotatedWildcardType, this class does not override addAnnotation,
removeAnnotation, or clearAnnotations to propagate to its components (getAlternatives()), and must not: those three types' bounds are meant to be homogenized
(every bound shares the same qualifier per hierarchy, since the type IS-A each of its bounds
simultaneously), but a union's alternatives are meant to stay heterogeneous -- the example
above can legitimately have a different qualifier on IOException than on
SQLException. BaseTypeVisitor.checkExceptionParameter(com.sun.source.tree.CatchTree) and BaseTypeVisitor.checkThrownExpression(com.sun.source.tree.ThrowTree) both validate
this type's own primary annotation and each alternative independently rather than assuming
they agree. Propagating like the other three types would forcibly overwrite (on
addAnnotation) or erase (on removeAnnotation/clearAnnotations) that
per-alternative information instead of preserving it.
This type's own primary annotation is instead a derived summary of the
alternatives -- the least upper bound of their qualifiers, not a value that gets pushed down
onto them -- computed by AsSuperVisitor.ensurePrimaryIsCorrectForUnions, since every
alternative must be assignable to a catch parameter of this union type. A caller that does
need to push one qualifier onto every alternative -- for example, applying the same default
to an entirely unannotated catch parameter -- does so with
addMissingAnnotation(s), which only fills a hierarchy an alternative doesn't already have an
opinion on, rather than addAnnotation, which would overwrite one it does. See
AsSuperVisitor#copyPrimaryAnnos's union case and QualifierDefaults's
EXCEPTION_PARAMETER case.
-
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 TypeFieldDescriptionThe types that are unioned to form this AnnotatedUnionType.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.deepCopy()Returns a deep copy of this type with annotations.deepCopy(boolean copyAnnotations) Returns a deep copy of this type.Returns the types that are unioned to form this AnnotatedUnionType.getKind()Returns thekindof this type.Returns a shallow copy of this type with annotations.shallowCopy(boolean copyAnnotations) Returns a shallow copy of this type.Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeMirror
addAnnotation, addAnnotations, addAnnotations, addMissingAnnotation, addMissingAnnotations, addMissingAnnotations, asUse, checkMutable, clearAnnotations, containsCapturedTypes, createType, createTypeOfObject, createTypeOfRecord, directSupertypes, equals, freeze, getAnnotation, getAnnotation, getAnnotationInHierarchy, getAnnotations, getAnnotationsField, getEffectiveAnnotation, getEffectiveAnnotationInHierarchy, getEffectiveAnnotations, getErased, getExplicitAnnotations, getPrimitiveKind, getUnderlyingType, getUnderlyingTypeHashCode, hasAnnotation, hasAnnotation, hasAnnotationInHierarchy, hasAnnotationRelaxed, hasEffectiveAnnotation, hasEffectiveAnnotation, hasEffectiveAnnotationRelaxed, hasExplicitAnnotation, hasExplicitAnnotation, hasExplicitAnnotationRelaxed, hashCode, isDeclaration, isFrozen, removeAnnotation, removeAnnotationByClass, removeAnnotationInHierarchy, removeAnnotations, replaceAnnotation, replaceAnnotations, replaceAnnotations, toString, toString
-
Field Details
-
alternatives
The types that are unioned to form this AnnotatedUnionType.Is set by
getAlternatives()andshallowCopy(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
-
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
-
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:
-
getAlternatives
Returns the types that are unioned to form this AnnotatedUnionType.- Returns:
- the types that are unioned to form this AnnotatedUnionType
-