Class AnnotatedTypeMirror.AnnotatedUnionType

java.lang.Object
org.checkerframework.framework.type.AnnotatedTypeMirror
org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedUnionType
All Implemented Interfaces:
DeepCopyable<AnnotatedTypeMirror>
Enclosing class:
AnnotatedTypeMirror

public static class AnnotatedTypeMirror.AnnotatedUnionType extends AnnotatedTypeMirror
Represents a union type, the type of a multi-catch parameter (for example, 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.