Class AnnotatedTypeFactory
- All Implemented Interfaces:
AnnotationProvider
- Direct Known Subclasses:
GenericAnnotatedTypeFactory,TypeOutputtingChecker.GeneralAnnotatedTypeFactory
AnnotatedTypeMirror. The methods are:
getAnnotatedType(ClassTree)getAnnotatedType(MethodTree)getAnnotatedType(Tree)getAnnotatedTypeFromTypeTree(Tree)getAnnotatedType(TypeElement)getAnnotatedType(ExecutableElement)getAnnotatedType(Element)
addComputedTypeAnnotations(com.sun.source.tree.Tree, org.checkerframework.framework.type.AnnotatedTypeMirror) to add defaults, flow-sensitive refinement, and
type-system-specific rules.
Unless otherwise indicated, each public method in this class returns a "fully annotated" type, which is one that has an annotation in all positions.
Type system checker writers may need to subclass this class, to add default qualifiers
according to the type system semantics. Subclasses should especially override addComputedTypeAnnotations(Element, AnnotatedTypeMirror) and addComputedTypeAnnotations(Tree, AnnotatedTypeMirror) to handle default annotations. (Also,
addDefaultAnnotations(AnnotatedTypeMirror) adds annotations, but that method is a
workaround for Issue
979.)
- See the Checker Framework Manual:
- How to write a checker plug-in
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSubstitutes references to captured types intypeusingcapturedTypeVarToAnnotatedTypeVar.static classThe type for an instantiated generic method or constructor. -
Field Summary
FieldsModifier and TypeFieldDescriptionParses ajava files and stores annotations on public elements from ajava files.protected final @Nullable ExecutableElementThe AnnotatedFor.applyToSubpackages() field/element.protected final @Nullable ExecutableElementThe AnnotatedFor.List.value() field/element, for a location with two or more written@AnnotatedFor(which javac collapses into one@AnnotatedFor.List).protected final ExecutableElementThe AnnotatedFor.value argument/element.Substitutes references to captured type variables.protected final BaseTypeCheckerThe checker to use for option handling and resource management.protected @Nullable AnnotationFileElementTypesIf type checking a Java file, stores annotations read from an ajava file for that class if one exists.protected final ExecutableElementThe DefaultQualifier.List.value() field/element, for a location with two or more written@DefaultQualifier(which javac collapses into one@DefaultQualifier.List).protected final ElementsUtility class for working withElements.protected final ExecutableElementThe EnsuresQualifier.expression field/element.protected final ExecutableElementThe EnsuresQualifierIf.expression field/element.protected final TypeMirrorThe EnsuresQualifierIf.List type.protected final ExecutableElementThe EnsuresQualifierIf.List.value field/element.protected final ExecutableElementThe EnsuresQualifierIf.result argument/element.protected final TypeMirrorThe EnsuresQualifierIf type.protected final TypeMirrorThe EnsuresQualifier.List type.protected final ExecutableElementThe EnsuresQualifier.List.value field/element.protected final TypeMirrorThe EnsuresQualifier type.protected final ExecutableElementThe FieldInvariant.field argument/element.protected final ExecutableElementThe FieldInvariant.qualifier argument/element.protected IdentityHashMap<Tree, AnnotatedTypeMirror> Mapping from an expression tree to its annotated type; before defaults are applied, just what the programmer wrote.protected IdentityHashMap<Tree, AnnotatedTypeMirror> Mapping from a member tree to its annotated type; before defaults are applied, just what the programmer wrote.protected IdentityHashMap<Tree, AnnotatedTypeMirror> Mapping from a type tree to its annotated type; before defaults are applied, just what the programmer wrote.protected final @Nullable ExecutableElementThe HasQualifierParameter.applyToSubpackages() field/element.protected final ExecutableElementThe HasQualifierParameter.value field/element.final booleanWhether to ignore type arguments from raw types.Mapping from a tree that needs type argument inference to the method or constructor whose type arguments were inferred and the result ofinferTypeArguments(com.sun.source.tree.ExpressionTree, org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType).protected AnnotationClassLoaderThis loads type annotation classes via reflective lookup.final ExecutableElementThe MethodVal.className argument/element.final ExecutableElementThe MethodVal.methodName argument/element.final ExecutableElementThe MethodVal.params argument/element.LikeinferenceResultCache, but for the results inferred while a dataflow analysis computes the value of one node (seeisComputingNodeValue()).protected final ExecutableElementThe NoQualifierParameter.value field/element.protected final ExecutableElementThe Object.getClass method.protected final ProcessingEnvironmentThe processing environment to use for accessing compiler internals.protected QualifierHierarchyRepresent the annotation relations.protected QualifierUpperBoundsHolds the qualifier upper bounds for type uses.protected ReflectionResolverObject that is used to resolve reflective method calls, if reflection resolution is turned on.protected final ExecutableElementThe RequiresQualifier.expression field/element.protected final TypeMirrorThe RequiresQualifier.List type.protected final ExecutableElementThe RequiresQualifier.List.value field/element.protected final TypeMirrorThe RequiresQualifier type.booleanShould results be cached? This means that ATM.deepCopy() will be called.Parses stub files and stores annotations on public elements from stub files.protected final TreesTheTreesinstance to use for tree node path finding.protected TypeArgumentInferenceProvides utility method to infer type arguments.protected final AnnotatedTypeFormatterThis formatter is used for converting AnnotatedTypeMirrors to Strings.protected TypeHierarchyRepresent the type relations.protected final TypeInformationPresenterIf the option "lspTypeInfo" is defined, this presenter will report the type information of every type-checked class.final TypesUtility class for working withTypeMirrors.protected TypeVariableSubstitutorProvides utility method to substitute arguments for their type variables.final intUnique ID of the current object; for debugging purposes.protected static final @FullyQualifiedName StringThe fully-qualified name ofUnannotatedFor.protected final @Nullable ExecutableElementThe UnannotatedFor.applyToSubpackages() field/element.protected final @Nullable ExecutableElementThe UnannotatedFor.List.value() field/element, the@UnannotatedForcounterpart ofannotatedForListValueElement.protected final @Nullable ExecutableElementThe UnannotatedFor.value argument/element.protected @Nullable ViewpointAdapterViewpoint adapter used to perform viewpoint adaptation or null -
Constructor Summary
ConstructorsConstructorDescriptionAnnotatedTypeFactory(BaseTypeChecker checker) Constructs a factory from the given checker. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, ExpressionTree tree) Java special-cases the return type ofgetClass().protected voidaddAliasedDeclAnnotation(@FullyQualifiedName String alias, @FullyQualifiedName String annotationClassName, AnnotationMirror annotationToUse) Add the annotationaliasas an alias for the declaration annotationannotation, where the annotation mirrorannotationToUsewill be used instead.protected voidaddAliasedDeclAnnotation(Class<? extends Annotation> alias, Class<? extends Annotation> annotationClass, AnnotationMirror annotationToUse) Add the annotationaliasas an alias for the declaration annotationannotation, where the annotation mirrorannotationToUsewill be used instead.protected voidaddAliasedTypeAnnotation(@FullyQualifiedName String aliasName, Class<?> canonicalAnno, boolean copyElements, String... ignorableElements) Adds the annotation, whose fully-qualified name is given byaliasName, as an alias for the canonical annotationcanonicalAnnothat will be used by the Checker Framework in the alias's place.protected voidaddAliasedTypeAnnotation(@FullyQualifiedName String aliasName, AnnotationMirror canonicalAnno) Adds the annotation, whose fully-qualified name is given byaliasName, as an alias for the canonical annotationcanonicalAnnothat will be used by the Checker Framework in the alias's place.protected voidaddAliasedTypeAnnotation(Class<?> aliasClass, Class<?> canonicalClass, boolean copyElements, String... ignorableElements) Adds the annotationaliasClassas an alias for the canonical annotationcanonicalClassthat will be used by the Checker Framework in the alias's place.protected voidaddAliasedTypeAnnotation(Class<?> aliasClass, AnnotationMirror canonicalAnno) Adds the annotationaliasClassas an alias for the canonical annotationcanonicalAnnothat will be used by the Checker Framework in the alias's place.protected voidaddAnnotationFromFieldInvariant(AnnotatedTypeMirror type, AnnotatedTypeMirror accessedVia, VariableElement field) Adds the qualifier specified by a field invariant forfieldtotype.protected voidaddComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type) Changes annotations on a type obtained from aTree.protected voidaddComputedTypeAnnotations(Element elt, AnnotatedTypeMirror type) Changes annotations on a type obtained from anElement.voidAdds default annotations totype.protected voidaddInheritedAnnotation(AnnotationMirror annotation) Adds the annotationannotationin the set of declaration annotations that should be inherited.booleanReturns true if the@AnnotatedForthat applies to this checker oneltis written before the@UnannotatedForthat also applies to it.applyCaptureConversion(AnnotatedTypeMirror typeToCapture) Apply capture conversion totypeToCapture.applyCaptureConversion(AnnotatedTypeMirror type, TypeMirror typeMirror) Apply capture conversion totype.Returns a primitive type: either the argument, or the result of unboxing it (which might affect its annotations).booleanareSameByClass(AnnotationMirror am, Class<? extends Annotation> annoClass) Checks that the annotationamhas the name ofannoClass.asSupportedQualifier(AnnotationMirror writtenAnno) ReturnswrittenAnnoif it is a supported qualifier, or its canonical form if that is a supported qualifier, or null if neither is.binaryTreeArgTypes(BinaryTree tree) Returns the types of the two arguments to the BinaryTree.protected Pair<AnnotatedTypeMirror, AnnotatedTypeMirror> binaryTreeArgTypes(TypeMirror resultType, AnnotatedTypeMirror left, AnnotatedTypeMirror right) Returns the types of the two arguments to a binary operation.protected booleanReturns true if the type of the flow-dependent expressiontree(seeisFlowDependent(ExpressionTree)) can be cached, i.e., it is computed from refined types that remain correct as long ascanUseCachedFlowDependentType(ExpressionTree)holds.Returns the canonical annotation for the passed annotation.protected booleanReturns true if a cached type of the flow-dependent expressiontree(seeisFlowDependent(ExpressionTree)) is still correct, i.e., the refined types of the expressions it was computed from have not changed since it was cached.voidDiscards the results of type argument inference reused while a dataflow analysis computes the value of a node (seenodeValueInferenceResultCache).voidClears any caches used exclusively during the parse phase.protected AnnotationMirrorcombineIntersectionBoundAnnotationsInHierarchy(AnnotationMirror existingAnnotation, AnnotationMirror newAnnotation, QualifierHierarchy qualifierHierarchy) Combines two conflicting bound annotations of an intersection type, in the same qualifier hierarchy, into the single annotation used to summarize that hierarchy.Returns the types of the two arguments to the CompoundAssignmentTree.Determines the type of the invoked constructor based on the passed new class tree.constructorFromUse(NewClassTree tree, boolean inferTypeArgs) The implementation ofconstructorFromUse(NewClassTree)andconstructorFromUseWithoutTypeArgInference(NewClassTree).protected voidconstructorFromUsePreSubstitution(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.The same asconstructorFromUse(NewClassTree), but no type arguments are inferred.booleanReturns true iftypecontains any captured type variables.booleancontainsSameByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> annoClass) Checks that the collection contains the annotation.booleancontainsSameOrAlias(Collection<? extends AnnotationMirror> writtenAnnos, AnnotationMirror target) Returns true if some annotation inwrittenAnnosistarget, or an alias for it.protected AnnotatedTypeFormatterCreates theAnnotatedTypeFormatterused by this type factory and allAnnotatedTypeMirrors it creates.protected AnnotationClassLoaderFactory method to easily change whatAnnotationClassLoaderis created to load type annotation classes.protected AnnotationFormatterCreates theAnnotationFormatterused by this type factory.protected QualifierHierarchyReturns theQualifierHierarchyto be used by this checker.protected QualifierUpperBoundsCreatesQualifierUpperBoundsfor this type factory.protected Set<Class<? extends Annotation>> Returns a mutable set of annotation classes that are supported by a checker.protected TypeArgumentInferenceCreates the object that infers type arguments.protected TypeHierarchyCreates the type hierarchy to be used by this factory.protected @Nullable TypeInformationPresenterCreates theTypeInformationPresenterused inpostProcessClassTree(ClassTree)to output type information about the current class.protected TypeVariableSubstitutorTypeVariableSubstitutor provides a method to replace type parameters with their arguments.protected @Nullable ViewpointAdapterFactory method to create a ViewpointAdapter.Gets the declaration tree for the element, if the source is available.booleandoesAnnotatedForApplyToSubpackages(AnnotationMirror annotatedForAnno) DoesannotatedForAnno, which is anAnnotatedForannotation written on a package, also apply to subpackages of that package?booleandoesAnnotatedForApplyToThisChecker(AnnotationMirror annotatedForAnno) DoesannotatedForAnno, which is anAnnotatedForannotation, apply to this checker?booleandoesUnannotatedForApplyToSubpackages(AnnotationMirror unannotatedForAnno) DoesunannotatedForAnno, which is anUnannotatedForannotation written on a package, also apply to subpackages of that package?booleandoesUnannotatedForApplyToThisChecker(AnnotationMirror unannotatedForAnno) DoesunannotatedForAnno, which is anUnannotatedForannotation, apply to this checker?fromElement(Element elt) Creates an AnnotatedTypeMirror foreltthat includes: annotations explicitly written on the element and annotations from stub files.SeefromElement(Element).fromElement(TypeElement elt) SeefromElement(Element).Returns everyAnnotatedForannotation onelt: each one written on it (there may be more than one, since@AnnotatedForis@Repeatable), together with one for each of its declaration annotations that is an alias forAnnotatedFor.getAnnotatedNullType(Set<? extends AnnotationMirror> annotations) Creates and returns an AnnotatedNullType qualified withannotations.getAnnotatedType(ClassTree tree) getAnnotatedType(MethodTree tree) getAnnotatedType(NewArrayTree tree) getAnnotatedType(NewClassTree tree) getAnnotatedType(Tree tree) Returns an AnnotatedTypeMirror representing the annotated type oftree.getAnnotatedType(Class<?> clazz) Returns an AnnotatedTypeMirror representing the annotated type ofclazz.getAnnotatedType(Element elt) Returns an AnnotatedTypeMirror representing the annotated type ofelt.Returns the currentAnnotatedTypeFormatter.Determines the annotated type from a type in tree form.getAnnotationByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> annoClass) Returns the AnnotationMirror incthat has classannoClass.Returns the currentAnnotationFormatter.getAnnotationMirror(Tree tree, Class<? extends Annotation> target) Returns the annotation ontreethat is in the hierarchy that contains the qualifiertarget.getAnnotationOrTypeDeclarationBound(TypeMirror type, Set<? extends AnnotationMirror> annos) Compare the givenannoswith the declaration bounds oftypeand return the appropriate qualifiers.getAnnotationWithMetaAnnotation(Element element, Class<? extends Annotation> metaAnnotationClass) Returns a list of all annotations used to annotate this element, which have a meta-annotation (i.e., an annotation on that annotation) with classmetaAnnotationClass.Returns the class instance creation expression oftype's class if that is an anonymous class created with a diamond, as innew C<>(args) {...}.Returns the type of the superclass constructor thattree, an anonymous class creation with a diamond such asnew C<>(args) {...}, invokes, as a member of the generic superclassC<T>.Returns the supertype of the anonymous class created bytree, a diamond such asnew C<>(args) {...}, with the type arguments inferred as fornew C<>(args)(JLS 15.9.3).Returns the annotated boxed type of the given primitive type.protected final Set<Class<? extends Annotation>> getBundledTypeQualifiers(Class<? extends Annotation>... explicitlyListedAnnotations) Loads, via reflection, all bundled qualifiers.protected final intReturns the size for LRU caches.Returns the checker associated with this factory.Returns the names of the annotation processors that are being run.Returns the receiver type used to viewpoint-adapt a constructor invocation.getContractExpressions(AnnotationMirror contractAnno) Returns theexpressionfield/element of the given contract annotation.getContractListValues(AnnotationMirror contractListAnno) Returns thevaluefield/element of the given contract list annotation.final AnnotationMirrorgetDeclAnnotation(Element elt, Class<? extends Annotation> annoClass) Returns all of the declaration annotations whose name equals the passed annotation class (or is an alias for it) including annotations: on the element written in stubfiles inherited from overridden methods, (seeInheritedAnnotation) inherited from superclasses or super interfaces (seeInherited)final @Nullable AnnotationMirrorgetDeclAnnotationNoAliases(Element elt, Class<? extends Annotation> annoClass) Returns the annotation mirror used to annotate this element, whose name equals the passed annotation class.Returns all of the declaration annotations on this element including annotations: on the element written in stubfiles inherited from overridden methods, (seeInheritedAnnotation) inherited from superclasses or super interfaces (seeInherited)getDeclAnnotationWithMetaAnnotation(Element element, Class<? extends Annotation> metaAnnotationClass) Returns a list of all declaration annotations used to annotate the element, which have a meta-annotation (i.e., an annotation on that annotation) with classmetaAnnotationClass.protected AnnotationMirrorSetgetDefaultAnnosForUses(Element element) Returns the set of qualifiers that should be applied to unannotated uses of the given element, as specified byDefaultQualifierForUse.Returns everyDefaultQualifierannotation that applies toelt's own declaration, in source order: each one written on it (there may be more than one, since@DefaultQualifieris@Repeatable), plus one for each of its declaration annotations that is an alias for@DefaultQualifieror for@DefaultQualifier.List.protected AnnotationMirrorSetReturns the set of qualifiers that are the upper bound for a type use if no other bound is specified for the type.Returns the direct supertypes oftype: the result ofSupertypeFinder.directSupertypes(AnnotatedDeclaredType), cached.getDummyAssignedTo(ExpressionTree expressionTree) Returnsnullor an annotated type mirror that type argument inference should assumeexpressionTreeis assigned to.Returns the primary annotations on the type thatfromElement(Element)computes forelt, without the defensive deep copy thatfromElementmakes on every cache hit.final ElementsReturns the utility class for working withElements.Returns the innermost enclosing method or class tree oftree.getEnclosingSubType(TypeElement typeElement, Tree tree) Returns theAnnotatedTypeMirrorof the enclosing type at the location oftreethat is a subtype oftypeElement.getEnclosingType(TypeElement typeElement, Tree tree) Returns theAnnotatedTypeMirrorof the enclosing type at the location oftreethat is the same type astypeElement.protected AnnotationMirrorSetReturns the annotations that should be applied to enum constructors.getExplicitNewClassAnnos(NewClassTree newClassTree) Returns the annotations explicitly written on a NewClassTree.protected List<AnnotatedTypeMirror> getExplicitNewClassClassTypeArgs(NewClassTree newClass) Returns the partially-annotated explicit class type arguments of the new class tree.getExpressionAndOffset(String expression) Given an expression, split it into a subexpression and a constant offset.getFieldInvariantAnnotationTree(@Nullable List<? extends AnnotationTree> annoTrees) Returns the element ofannoTreesthat is a use of one of the field invariant annotations (as specified viagetFieldInvariantDeclarationAnnotations().protected Set<Class<? extends Annotation>> Returns the set of classes of field invariant annotations.getFieldInvariants(TypeElement element) Returns the field invariants for the given class, as expressed by the user in@FieldInvariantmethod annotations.getFnInterfaceFromTree(Tree tree) Returns the functional interface and the function type that this lambda or member references targets.Returns the function type that this lambda targets.Returns the function type that this member reference targets.Returns the implicit receiver type of an expression tree.intReturns the Java 8 type-argument-inference bound-incorporation work budget for this checker: the value of-AinferenceWorkBudget=Nif set, otherwiseJava8InferenceContext.MAX_INCORPORATION_WORK.getInitializerTargetType(NewArrayTree newArray) Returns the target type of an initializer ofnewArray: the component type of the array (JLS 10.6), without the lub of the initializers' types thatgetAnnotatedType(Tree)gives the array.getIterableElementType(ExpressionTree expression) Returns the element type ofexpression.protected AnnotatedTypeMirrorgetIterableElementType(ExpressionTree expression, AnnotatedTypeMirror iterableType) Returns the element type ofiterableType.Returns the receiver type used to viewpoint-adapt a method invocation.Returns the return type of the methodm.Returns the return type of the methodmat the return statementr.getNarrowedAnnotations(AnnotationMirrorSet annos, TypeKind typeKind, TypeKind narrowedTypeKind) Returns annotations applicable to typenarrowedTypeKind, that are copied or adapted fromannos.getNarrowedPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type, TypeMirror narrowedTypeMirror) Returns AnnotatedPrimitiveType with underlying typenarrowedTypeMirrorand with annotations copied or adapted fromtype.Gets the path for the givenTreeunder the current root by checking from the visitor's current path, and usingTrees.getPath(CompilationUnitTree, Tree)(which is much slower) only iftreeis not found on the current path.Accessor for the processing environment.Returns theQualifierDefaultsthis factory applies, or null if it applies no defaults.final QualifierHierarchyReturns the type qualifier hierarchy graph to be used by this processor.getQualifierParameterHierarchies(Element element) Returns the set of top annotations representing all the hierarchies for which this element has a qualifier parameter.getQualifierParameterHierarchies(AnnotatedTypeMirror annotatedType) Returns the set of top annotations representing all the hierarchies for which this type has a qualifier parameter.ReturnsQualifierUpperBoundsfor this type factory.final @Nullable AnnotatedTypeMirrorgetReceiverType(ExpressionTree expression) Returns the receiver type of the expression tree, which might be the type of an implicitthis.getResultingTypeOfConstructorMemberReference(MemberReferenceTree memberReferenceTree, AnnotatedTypeMirror.AnnotatedExecutableType constructorType) Gets the type of the resulting constructor call of a MemberReferenceTree.getRoot()Get the current CompilationUnitTree.getSelfType(Tree tree) Returns the type ofthisat the location oftree.getSelfType(TypeElement classElt) Returns the type ofthisinclassElt: the class applied to its own type parameters, with the annotations that the class's defaults give it.Returns AnnotatedDeclaredType with underlying type String and annotations copied from type.final Set<@CanonicalName String> Returns an immutable set of the fully qualified names of the type qualifiers supported by this checker.final Set<Class<? extends Annotation>> Returns an immutable set of the classes corresponding to the type qualifiers supported by this checker.Accessor for the tree utilities.Returns the set of qualifiers that are the upper bounds for a use of the type.Returns the set of qualifiers that are the upper bounds for a use of the type.final TypeHierarchyReturns the type hierarchy.getTypeOfExtendsImplements(Tree clause) Returns the type of the extends or implements clause.Returns everyUnannotatedForannotation onelt: each one written on it (there may be more than one, since@UnannotatedForis@Repeatable), together with one for each of its declaration annotations that is an alias forUnannotatedFor.Returns the annotated primitive type of the given declared type if it is a boxed declared type.getViewpointAdaptedTypeDeclarationBounds(AnnotationMirrorSet viewpointBounds, AnnotatedTypeMirror declarationBoundType) Returns the primary qualifiers ofdeclarationBoundType, viewpoint-adapted from the viewpoint ofviewpointBounds.Returns the path to the tree that an external "visitor" is visiting.getWidenedAnnotations(AnnotationMirrorSet annos, TypeKind typeKind, TypeKind widenedTypeKind) Returns annotations applicable to typewidenedTypeKind, that are copied or adapted fromannos.final AnnotatedTypeMirrorgetWidenedType(AnnotatedTypeMirror exprType, AnnotatedTypeMirror widenedType) Returns a widened type if applicable, otherwise returns its first argument.final AnnotatedTypeMirrorgetWidenedType(AnnotationMirrorSet exprAnnos, TypeMirror exprTypeMirror, AnnotatedTypeMirror widenedType) Applies widening if applicable, otherwise returns its first argument.booleanReturns true if theNoQualifierParameterannotation was explicitly written onelementfor the hierarchy given bytop.booleanhasExplicitQualifierParameterInHierarchy(Element element, AnnotationMirror top) Returns true if theHasQualifierParameterannotation was explicitly written onelementfor the hierarchy given bytop.booleanhasQualifierParameterInHierarchy(@Nullable Element element, AnnotationMirror top) Returns true if theelementhas a qualifier parameter.booleanhasQualifierParameterInHierarchy(AnnotatedTypeMirror annotatedTypeMirror, AnnotationMirror top) Returns true if theannotatedTypeMirrorhas a qualifier parameter.inferTypeArguments(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Infers the type arguments oftree, a method invocation, constructor invocation, or member reference, withgetTypeArgumentInference().voidInitializes all fields oftype.protected voidInitialize reflection resolution.booleanisAliasedTypeAnnotation(Class<?> annoClass) Returns true if the given annotation class is an alias for some other annotation.booleanisAnonymousDiamondSupertypeFinal(NewClassTree creation) Returns true if the supertype inferred for the anonymous class created bycreation, a diamond such asnew C<>(args) {...}, can no longer change.booleanisComputingInitializerTargetType(NewArrayTree newArray) Returns true if the type ofnewArrayis being computed bygetInitializerTargetType(com.sun.source.tree.NewArrayTree), so it must not depend on the types of the initializers.protected booleanReturns true if a dataflow analysis is computing the value of a node, which it does from the type of the node's tree.booleanisDeterministic(ExecutableElement methodElement) Returns true if the given method is deterministic according to this AnnotationProvider — that is, if multiple calls to the given method (with the same arguments) return the same value.booleanisFromByteCode(Element element) Returns true if the element is from bytecode -- that is, it is not being compiled -- and did not appear in a stub file.booleanisFromStubFile(Element element) Returns true if the element appears in a stub file (Currently only works for methods, constructors, and fields).booleanisImmutable(TypeMirror type) Returns true if the type is immutable.protected booleanReturns true if the type arguments of a poly expression are being inferred as if it were not nested in another expression (DefaultTypeArgumentInference.inferStandalone(com.sun.source.tree.ExpressionTree, java.util.function.Supplier<R>)).booleanReturns true if any annotation file (stub or ajava) is currently being parsed.booleanisSideEffectFree(ExecutableElement methodElement) Returns true if the given method is side-effect-free according to this AnnotationProvider — that is, if a call to the given method does not undo flow-sensitive type refinement.booleanisSupportedQualifier(Class<? extends Annotation> clazz) Returns true if the given class is a part of the type system under which this type factory operates.booleanisSupportedQualifier(String className) Returns true if the given class name is a part of the type system under which this type factory operates.booleanReturns true if the given annotation is a part of the type system under which this type factory operates.booleanisSupportedQualifierOrAlias(AnnotationMirror writtenAnno) Returns true ifwrittenAnnois a supported qualifier, or an alias for one.protected final booleanisWithinConstructor(Tree tree) Returns true iftreeis within a constructor.protected AnnotatedTypeMirrormergeAnnotationFileAnnosIntoType(@Nullable AnnotatedTypeMirror type, Element elt, AnnotationFileElementTypes source) Merges types from annotation files foreltintotypeby taking the greatest lower bound of the annotations in both.methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType) Determines the type of the invoked method based on the passed expression tree, executable element, and receiver type.methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType, boolean inferTypeArgs) Determines the type of the invoked method based on the passed method invocation tree.methodFromUse(MethodInvocationTree tree, boolean inferTypeArgs) The implementation ofmethodFromUse(MethodInvocationTree)andmethodFromUseWithoutTypeArgInference(MethodInvocationTree).protected voidmethodFromUsePreSubstitution(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.methodFromUseWithoutTypeArgInference(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType) Returns the same asmethodFromUse(ExpressionTree, ExecutableElement, AnnotatedTypeMirror), but without inferred type arguments.Returns the same asmethodFromUse(MethodInvocationTree), but without inferred type arguments.static StringnegateConstant(String constantExpression) Given an expression string, returns its negation.order(Collection<AnnotatedTypeMirror.AnnotatedTypeVariable> collection) Returns the list of type variables such that a type variable in the list only references type variables at a lower index than itself.overriddenMethodType(AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, ExecutableElement overriddenMethodElt, AnnotatedTypeMirror.AnnotatedDeclaredType overriderType) Returns the type of an overridden method as it should be seen for an override check against the given overriding class.protected voidParses all annotation files in the following order: Stub files, seeAnnotationFileElementTypes.parseStubFiles(); Ajava files, seeAnnotationFileElementTypes.parseAjavaFiles().permissiveOverriddenType(Tree overriderTree, AnnotatedTypeMirror.AnnotatedExecutableType overrider, AnnotatedTypeMirror overriderReturnType, @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType overriderType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType) Returns the type ofoverriddenas it constrains the overriding method, if the overridden method is in unchecked code that gets the permissive defaults (seeQualifierDefaults.applyPermissiveDefaults(javax.lang.model.element.Element)): with the qualifiers of the overriding method at the locations of its signature that have no written qualifier.voidpostAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element) A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf().protected voidpostDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes) A callback method for the AnnotatedTypeFactory subtypes to customize directSupertypes().protected voidpostInit()Actions that logically belong in the constructor, but need to run after the subclass constructor has completed.voidCalled byBaseTypeVisitor.visitClass(ClassTree, Void)after the ClassTree has been type checked.voidpreProcessClassTree(ClassTree classTree) Called byBaseTypeVisitor.visitClass(ClassTree, Void)before the classTree is type checked.voidReplaces or adds all annotations fromfromtoto.voidreplaceAnnotations(AnnotatedTypeMirror from, AnnotatedTypeMirror to, AnnotationMirror top) Replaces or adds annotations intop's hierarchy fromfromtoto.final voidsetPathForArtificialTree(Tree tree, TreePath path) Set the tree path for the given artificial tree.voidsetRoot(@Nullable CompilationUnitTree newRoot) Set the CompilationUnitTree that should be used.voidsetVisitorTreePath(@Nullable TreePath visitorTreePath) Sets the path to the tree that an external "visitor" is visiting.protected booleanWhethergetAnnotatedType(Element)results may be cached inelementTypeCache.protected booleanWhethermethodAsMemberOfCachemay be used.protected booleanReturns whetherpostProcessClassTree(com.sun.source.tree.ClassTree)stores into the class file the qualifiers that do not appear in the source code (defaulted types and inherited declaration annotations).booleanReturns true if redundancy between a stub file and bytecode should be reported.protected final AnnotatedTypeMirrortoAnnotatedType(TypeMirror t, boolean declaration) A convenience method that converts aTypeMirrorto an emptyAnnotatedTypeMirrorusingAnnotatedTypeMirror.createType(javax.lang.model.type.TypeMirror, org.checkerframework.framework.type.AnnotatedTypeFactory, boolean).toString()protected final AnnotatedTypeMirrorDetermines an empty annotated type of the given tree.Adapt the upper bounds of the type variables of a class relative to the type instantiation.
-
Field Details
-
UNANNOTATED_FOR_NAME
The fully-qualified name ofUnannotatedFor. A literal string rather thanUnannotatedFor.class.getCanonicalName(): the type is absent when the classpath resolveschecker-qualfrom upstream typetools, and a class literal would link it.- See Also:
-
trees
TheTreesinstance to use for tree node path finding. -
processingEnv
The processing environment to use for accessing compiler internals. -
elements
Utility class for working withElements. -
types
Utility class for working withTypeMirrors. -
annotatedForValueElement
The AnnotatedFor.value argument/element. -
annotatedForApplyToSubpackagesElement
The AnnotatedFor.applyToSubpackages() field/element. Null if the version of@AnnotatedForon the classpath predates this element, in which case an@AnnotatedForon a package always applies to subpackages. -
annotatedForListValueElement
The AnnotatedFor.List.value() field/element, for a location with two or more written@AnnotatedFor(which javac collapses into one@AnnotatedFor.List). Null if the version of@AnnotatedForon the classpath predates the nestedListtype, in which case@AnnotatedForcould not have been written more than once there. -
unannotatedForValueElement
The UnannotatedFor.value argument/element. Null if@UnannotatedForis not on the classpath, which is the case for the upstream typetoolschecker-qual; no element can then be annotated with it, so it excludes nothing. -
unannotatedForApplyToSubpackagesElement
The UnannotatedFor.applyToSubpackages() field/element. Null under the same condition asunannotatedForValueElement. -
unannotatedForListValueElement
The UnannotatedFor.List.value() field/element, the@UnannotatedForcounterpart ofannotatedForListValueElement. Null under the same condition asunannotatedForValueElement. -
defaultQualifierListValueElement
The DefaultQualifier.List.value() field/element, for a location with two or more written@DefaultQualifier(which javac collapses into one@DefaultQualifier.List). -
ensuresQualifierExpressionElement
The EnsuresQualifier.expression field/element. -
ensuresQualifierListValueElement
The EnsuresQualifier.List.value field/element. -
ensuresQualifierIfExpressionElement
The EnsuresQualifierIf.expression field/element. -
ensuresQualifierIfResultElement
The EnsuresQualifierIf.result argument/element. -
ensuresQualifierIfListValueElement
The EnsuresQualifierIf.List.value field/element. -
fieldInvariantFieldElement
The FieldInvariant.field argument/element. -
fieldInvariantQualifierElement
The FieldInvariant.qualifier argument/element. -
hasQualifierParameterValueElement
The HasQualifierParameter.value field/element. -
hasQualifierParameterApplyToSubpackagesElement
The HasQualifierParameter.applyToSubpackages() field/element. Null if the version of@HasQualifierParameteron the classpath predates this element, in which case a@HasQualifierParameteron a package always applies to subpackages. -
methodValClassNameElement
The MethodVal.className argument/element. -
methodValMethodNameElement
The MethodVal.methodName argument/element. -
methodValParamsElement
The MethodVal.params argument/element. -
noQualifierParameterValueElement
The NoQualifierParameter.value field/element. -
requiresQualifierExpressionElement
The RequiresQualifier.expression field/element. -
requiresQualifierListValueElement
The RequiresQualifier.List.value field/element. -
requiresQualifierTM
The RequiresQualifier type. -
requiresQualifierListTM
The RequiresQualifier.List type. -
ensuresQualifierTM
The EnsuresQualifier type. -
ensuresQualifierListTM
The EnsuresQualifier.List type. -
ensuresQualifierIfTM
The EnsuresQualifierIf type. -
ensuresQualifierIfListTM
The EnsuresQualifierIf.List type. -
qualHierarchy
Represent the annotation relations. -
typeHierarchy
Represent the type relations. -
viewpointAdapter
Viewpoint adapter used to perform viewpoint adaptation or null -
typeFormatter
This formatter is used for converting AnnotatedTypeMirrors to Strings. This formatter will be used by all AnnotatedTypeMirrors created by this factory in their toString methods. -
qualifierUpperBounds
Holds the qualifier upper bounds for type uses. -
typeVarSubstitutor
Provides utility method to substitute arguments for their type variables. Field should be final, but can only be set in postInit, because subtypes might need other state to be initialized first. -
typeArgumentInference
Provides utility method to infer type arguments. -
stubTypes
Parses stub files and stores annotations on public elements from stub files. -
ajavaTypes
Parses ajava files and stores annotations on public elements from ajava files. -
currentFileAjavaTypes
If type checking a Java file, stores annotations read from an ajava file for that class if one exists. UnlikeajavaTypes, which only stores annotations on public elements, this stores annotations on all element locations such as in anonymous class bodies. -
checker
The checker to use for option handling and resource management. -
uid
public final int uidUnique ID of the current object; for debugging purposes. -
reflectionResolver
Object that is used to resolve reflective method calls, if reflection resolution is turned on. -
loader
This loads type annotation classes via reflective lookup. -
shouldCache
public boolean shouldCacheShould results be cached? This means that ATM.deepCopy() will be called. ATM.deepCopy() used to (and perhaps still does) side effect the ATM being copied. So setting this to false is not equivalent to setting shouldReadCache to false. -
fromExpressionTreeCache
Mapping from an expression tree to its annotated type; before defaults are applied, just what the programmer wrote. The type of a flow-dependent expression (seeisFlowDependent(ExpressionTree)) is only cached and used ascanCacheFlowDependentType(ExpressionTree)andcanUseCachedFlowDependentType(ExpressionTree)allow.This field is intentionally not final; it should only be re-assigned by
setRoot(CompilationUnitTree). -
inferenceResultCache
protected @Nullable IdentityHashMap<ExpressionTree,Pair<ExecutableElement, inferenceResultCacheInferenceResult>> Mapping from a tree that needs type argument inference to the method or constructor whose type arguments were inferred and the result ofinferTypeArguments(com.sun.source.tree.ExpressionTree, org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType). It is cleared withfromExpressionTreeCache. Null ifshouldCacheis false.This field is intentionally not final; it should only be re-assigned by
setRoot(CompilationUnitTree). -
nodeValueInferenceResultCache
protected @Nullable IdentityHashMap<ExpressionTree,Pair<ExecutableElement, nodeValueInferenceResultCacheInferenceResult>> LikeinferenceResultCache, but for the results inferred while a dataflow analysis computes the value of one node (seeisComputingNodeValue()). The analysis state that the types of expressions depend on does not change during that computation, so a result inferred during it is reused within it: for example, the value of the array created for the variable arguments of a call is computed from the types of all those arguments, whose inference solves the same problem. The results are not reused after the computation, in which the analysis state can change;clearNodeValueInferenceResults()is called when a computation starts and ends. Null ifshouldCacheis false.This field is intentionally not final; it should only be re-assigned by
setRoot(CompilationUnitTree). -
fromMemberTreeCache
Mapping from a member tree to its annotated type; before defaults are applied, just what the programmer wrote.This field is intentionally not final; it should only be re-assigned by
setRoot(CompilationUnitTree). -
fromTypeTreeCache
Mapping from a type tree to its annotated type; before defaults are applied, just what the programmer wrote.This field is intentionally not final; it should only be re-assigned by
setRoot(CompilationUnitTree). -
ignoreRawTypeArguments
public final boolean ignoreRawTypeArgumentsWhether to ignore type arguments from raw types. -
objectGetClass
The Object.getClass method. -
typeInformationPresenter
If the option "lspTypeInfo" is defined, this presenter will report the type information of every type-checked class. This information can be visualized by an editor/IDE that supports LSP. -
capturedTypeVarSubstitutor
Substitutes references to captured type variables.Unlike
typeVarSubstitutor, this class does not copy the type. Callsubstituteto use.
-
-
Constructor Details
-
AnnotatedTypeFactory
Constructs a factory from the given checker.A subclass must call postInit at the end of its constructor. postInit must be the last call in the constructor or else types from stub files may not be created as expected.
- Parameters:
checker- the checker to which this factory belongs
-
-
Method Details
-
initializeAtm
Initializes all fields oftype.This method is for framework usage only.
- Parameters:
type- annotated type mirror
-
postInit
Actions that logically belong in the constructor, but need to run after the subclass constructor has completed. In particular,AnnotationFileElementTypes.parseStubFiles()may try to do type resolution with this AnnotatedTypeFactory. -
getChecker
Returns the checker associated with this factory.- Returns:
- the checker associated with this factory
-
getCheckerNames
Returns the names of the annotation processors that are being run.- Returns:
- the names of the annotation processors that are being run
-
createQualifierUpperBounds
CreatesQualifierUpperBoundsfor this type factory.- Returns:
- a new
QualifierUpperBoundsfor this type factory
-
getQualifierUpperBounds
ReturnsQualifierUpperBoundsfor this type factory.- Returns:
QualifierUpperBoundsfor this type factory
-
initializeReflectionResolution
protected void initializeReflectionResolution()Initialize reflection resolution. -
getRoot
Get the current CompilationUnitTree. It is null until the first compilation unit is handed tosetRoot(com.sun.source.tree.CompilationUnitTree), which happens after this factory has been fully initialized, so a null result also means that type checking has not begun yet.- Returns:
- the current compilation unit being used, or null
-
setRoot
Set the CompilationUnitTree that should be used.- Parameters:
newRoot- the new compilation unit to use
-
toString
-
createQualifierHierarchy
Returns theQualifierHierarchyto be used by this checker.The implementation builds the type qualifier hierarchy for the
getSupportedTypeQualifiers()using the meta-annotations found in them. The current implementation returns an instance ofNoElementQualifierHierarchy.Subclasses must override this method if their qualifiers have elements; the method must return an implementation of
QualifierHierarchy, such asElementQualifierHierarchy.- Returns:
- a QualifierHierarchy for this type system
-
getQualifierHierarchy
Returns the type qualifier hierarchy graph to be used by this processor.- Returns:
- the
QualifierHierarchyfor this checker - See Also:
-
createTypeHierarchy
Creates the type hierarchy to be used by this factory.Subclasses may override this method to specify new type-checking rules beyond the typical Java subtyping rules.
- Returns:
- the type relations class to check type subtyping
-
getTypeHierarchy
Returns the type hierarchy.- Returns:
- the type hierarchy
-
createViewpointAdapter
Factory method to create a ViewpointAdapter. Subclasses should implement and instantiate a ViewpointAdapter subclass if viewpoint adaptation is needed for a type system.- Returns:
- viewpoint adapter to perform viewpoint adaptation or null
-
overriddenMethodType
public AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethodType(AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, ExecutableElement overriddenMethodElt, AnnotatedTypeMirror.AnnotatedDeclaredType overriderType) Returns the type of an overridden method as it should be seen for an override check against the given overriding class. This computes the overridden method type viaAnnotatedTypes.asMemberOf(javax.lang.model.util.Types, org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.type.AnnotatedTypeMirror, javax.lang.model.element.ExecutableElement)and then viewpoint-adapts it to the overriding class.- Parameters:
overriddenType- the supertype that contains the overridden methodoverriddenMethodElt- the element of the overridden methodoverriderType- the type of the class declaring the overriding method- Returns:
- the overridden method type, with type variables substituted and viewpoint-adapted to the overriding class
-
getQualifierDefaults
Returns theQualifierDefaultsthis factory applies, or null if it applies no defaults.- Returns:
- the
QualifierDefaultsthis factory applies, or null
-
permissiveOverriddenType
public AnnotatedTypeMirror.AnnotatedExecutableType permissiveOverriddenType(Tree overriderTree, AnnotatedTypeMirror.AnnotatedExecutableType overrider, AnnotatedTypeMirror overriderReturnType, @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType overriderType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType) Returns the type ofoverriddenas it constrains the overriding method, if the overridden method is in unchecked code that gets the permissive defaults (seeQualifierDefaults.applyPermissiveDefaults(javax.lang.model.element.Element)): with the qualifiers of the overriding method at the locations of its signature that have no written qualifier. Then a qualifier that only a permissive default would supply, the top qualifier for a parameter or an upper bound and the bottom qualifier for a return type or a lower bound, does not constrain the overrider. A qualifier written at any location, such as@NullableinList<@Nullable Object>, still does. Returnsoverriddenotherwise. For a method reference, the overridden method is the method of the functional interface.The type is computed as
overriddenis, but from the declaration of the method with only its written qualifiers, those of the overrider filled in (seefillUnwrittenLocations(Tree, AnnotatedExecutableType, AnnotatedTypeMirror, AnnotatedExecutableType)): as a member ofoverriddenType, which substitutes the type arguments that the overrider's class gives the type variables of the overridden class, with their qualifiers, and applies the defaults to the locations that are still unwritten. The types of unchecked code are not stored into its elements (seeTypesIntoElements), sofromElement(javax.lang.model.element.Element)gives the written qualifiers whether or not the class of the overridden method has been type-checked already.- Parameters:
overriderTree- the declaration of the overriding method, or a method referenceoverrider- the type of the overriding methodoverriderReturnType- the return type of the overriding method; for a constructor reference, the type of the resultoverriderType- the type of the class that declares the overriding method, or null for a method referenceoverridden- the type of the overridden method, as a member ofoverriddenTypeoverriddenType- the supertype or functional interface that declares the overridden method- Returns:
- the type of the overridden method in which its unwritten locations do not constrain
the overrider, or
overridden
-
createTypeVariableSubstitutor
TypeVariableSubstitutor provides a method to replace type parameters with their arguments. -
getTypeVarSubstitutor
-
createTypeArgumentInference
Creates the object that infers type arguments.- Returns:
- the object that infers type arguments
-
getTypeArgumentInference
-
inferTypeArguments
public InferenceResult inferTypeArguments(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Infers the type arguments oftree, a method invocation, constructor invocation, or member reference, withgetTypeArgumentInference(). The visitor and the computation of the type oftreeinfer the same type arguments, so a result is cached and reused when bothcanCacheFlowDependentType(com.sun.source.tree.ExpressionTree)andcanUseCachedFlowDependentType(com.sun.source.tree.ExpressionTree)hold fortree, which is when no dataflow analysis is running, and no inference problem is being solved, whose partial results are not cached.- Parameters:
tree- a tree that needs type argument inferencemethodType- the type of the method or constructor before type argument substitution- Returns:
- the result of type argument inference
-
isInferringStandalone
protected boolean isInferringStandalone()Returns true if the type arguments of a poly expression are being inferred as if it were not nested in another expression (DefaultTypeArgumentInference.inferStandalone(com.sun.source.tree.ExpressionTree, java.util.function.Supplier<R>)). Such results are not cached.- Returns:
- true if
DefaultTypeArgumentInference.inferStandalone(com.sun.source.tree.ExpressionTree, java.util.function.Supplier<R>)is running
-
isComputingNodeValue
protected boolean isComputingNodeValue()Returns true if a dataflow analysis is computing the value of a node, which it does from the type of the node's tree. The analysis state that the types of expressions depend on does not change during that computation, so the results of type argument inference during it are reused within it (seenodeValueInferenceResultCache). This implementation, which performs no dataflow analysis, returns false.- Returns:
- true if a dataflow analysis is computing the value of a node
-
clearNodeValueInferenceResults
public void clearNodeValueInferenceResults()Discards the results of type argument inference reused while a dataflow analysis computes the value of a node (seenodeValueInferenceResultCache). Called when such a computation starts and ends. -
getInferenceWorkBudget
public int getInferenceWorkBudget()Returns the Java 8 type-argument-inference bound-incorporation work budget for this checker: the value of-AinferenceWorkBudget=Nif set, otherwiseJava8InferenceContext.MAX_INCORPORATION_WORK. Computed once and cached: the option is constant for a compilation, but inference creates aJava8InferenceContextonce per generic invocation, so reading and parsing the option there would repeat this work on a hot path.- Returns:
- the bound-incorporation work budget for type-argument inference
-
createAnnotationClassLoader
Factory method to easily change whatAnnotationClassLoaderis created to load type annotation classes. Subclasses can override this method and return a custom AnnotationClassLoader subclass to customize loading logic. -
createSupportedTypeQualifiers
Returns a mutable set of annotation classes that are supported by a checker.Subclasses may override this method to return a mutable set of their supported type qualifiers through one of the 5 approaches shown below.
Subclasses should not call this method; they should call
getSupportedTypeQualifiers()instead.By default, a checker supports all annotations located in a subdirectory called qual that's located in the same directory as the checker. Note that only annotations defined with the
@Target({ElementType.TYPE_USE})meta-annotation (and optionally with the additional value ofElementType.TYPE_PARAMETER, but no otherElementTypevalues) are automatically considered as supported annotations.To support a different set of annotations than those in the qual subdirectory, or that have other
ElementTypevalues, see examples below.In total, there are 3 ways to indicate annotations that are supported by a checker:
- Only support annotations located in a checker's qual directory:
This is the default behavior. Simply place those annotations within the qual directory.
- Support annotations located in a checker's qual directory and a list of
other annotations:
Place those annotations within the qual directory, and override
createSupportedTypeQualifiers()by callinggetBundledTypeQualifiers(Class...)with a varargs parameter list of the other annotations. Code example:@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() { return getBundledTypeQualifiers( // These annotations are in the Called Methods Checker, not the Resource Leak Checker. CalledMethods.class, CalledMethodsBottom.class, CalledMethodsPredicate.class); } - Support only annotations that are explicitly listed. This is common when a single
directory holds qualifiers for multiple qualifier hierarchies. Override
createSupportedTypeQualifiers()and return a mutable set of the supported annotations. Code example:
The set of qualifiers returned by@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() { return new HashSet<Class<? extends Annotation>>( Arrays.asList(A.class, B.class)); }createSupportedTypeQualifiers()must be a fresh, mutable set. The methodsgetBundledTypeQualifiers(Class...)must return a fresh, mutable set.
- Returns:
- the type qualifiers supported this processor, or an empty set if none
- Only support annotations located in a checker's qual directory:
-
getBundledTypeQualifiers
@SafeVarargs protected final Set<Class<? extends Annotation>> getBundledTypeQualifiers(Class<? extends Annotation>... explicitlyListedAnnotations) Loads, via reflection, all bundled qualifiers. A bundled qualifier is one that is shipped with the Checker Framework, in the qual directory of a checker. Returns the bundled annotations and the annotations passed as arguments.This method can be called in the overridden versions of
createSupportedTypeQualifiers()in each checker.- Parameters:
explicitlyListedAnnotations- a varargs array of explicitly listed annotation classes to be added to the returned set- Returns:
- a mutable set of the loaded and listed annotation classes
-
createAnnotatedTypeFormatter
Creates theAnnotatedTypeFormatterused by this type factory and allAnnotatedTypeMirrors it creates. TheAnnotatedTypeFormatteris used inAnnotatedTypeMirror.toString()and will affect the error messages printed for checkers that use this type factory.Called from the
AnnotatedTypeFactoryconstructor, before any subclass constructor body or field initializer runs, so an override must not depend on subclass state.- Returns:
- the
AnnotatedTypeFormatterto pass to allAnnotatedTypeMirrors
-
getAnnotatedTypeFormatter
Returns the currentAnnotatedTypeFormatter.- Returns:
- the current
AnnotatedTypeFormatter
-
createAnnotationFormatter
Creates theAnnotationFormatterused by this type factory.Called from the
AnnotatedTypeFactoryconstructor, before any subclass constructor body or field initializer runs, so an override must not depend on subclass state.- Returns:
- the
AnnotationFormatterused by this type factory
-
getAnnotationFormatter
Returns the currentAnnotationFormatter.- Returns:
- the current
AnnotationFormatter
-
createTypeInformationPresenter
Creates theTypeInformationPresenterused inpostProcessClassTree(ClassTree)to output type information about the current class.Called from the
AnnotatedTypeFactoryconstructor, before any subclass constructor body or field initializer runs, so an override must not depend on subclass state.- Returns:
- the
TypeInformationPresenterused by this type factory, or null
-
getSupportedTypeQualifiers
Returns an immutable set of the classes corresponding to the type qualifiers supported by this checker.Subclasses cannot override this method; they should override
createSupportedTypeQualifiersinstead.- Returns:
- an immutable set of the supported type qualifiers, or an empty set if no qualifiers are supported
- See Also:
-
getSupportedTypeQualifierNames
Returns an immutable set of the fully qualified names of the type qualifiers supported by this checker.Subclasses cannot override this method; they should override
createSupportedTypeQualifiersinstead.- Returns:
- an immutable set of the supported type qualifiers, or an empty set if no qualifiers are supported
- See Also:
-
getCacheSize
protected final int getCacheSize()Returns the size for LRU caches. It is either the value supplied via the-AatfCacheSizeoption or the default cache size.- Returns:
- cache size passed as argument to checker or DEFAULT_CACHE_SIZE
-
getAnnotatedType
Returns an AnnotatedTypeMirror representing the annotated type ofelt.- Parameters:
elt- the element- Returns:
- the annotated type of
elt
-
shouldCacheElementType
protected boolean shouldCacheElementType()WhethergetAnnotatedType(Element)results may be cached inelementTypeCache. Returns true by default. A checker whoseaddComputedTypeAnnotations(Element, AnnotatedTypeMirror)is not a pure function of the element (i.e., it reads use-site or other mutable state when computing an element's declaration type) must override this to return false.- Returns:
- true if the fully-computed element-type cache is sound for this checker
-
combineIntersectionBoundAnnotationsInHierarchy
protected AnnotationMirror combineIntersectionBoundAnnotationsInHierarchy(AnnotationMirror existingAnnotation, AnnotationMirror newAnnotation, QualifierHierarchy qualifierHierarchy) Combines two conflicting bound annotations of an intersection type, in the same qualifier hierarchy, into the single annotation used to summarize that hierarchy. Called byAnnotatedTypeMirror.AnnotatedIntersectionType.summarizeBounds(): for a type variable's own intersection upper bound, after each bound has been independently defaulted, so a bound's annotation may be explicit or defaulted; for an intersection cast target, after each bound without a written qualifier got the cast operand's qualifier. Either way, this method is called only when two bounds carry different annotations in one hierarchy.By default the annotation of the bound encountered first, in source order, wins (first-bound-wins): the returned summary equals
existingAnnotationandnewAnnotationis ignored. The summary is therefore source-order dependent, but deterministic for a given compilation. It is still a sound upper bound of the intersection, because it equals one of the bounds' own annotations and the intersection is a subtype of each of its bounds.A checker in which every bound constrains the intersection -- for example a JSpecify-style integration -- may override this to return
qualifierHierarchy.greatestLowerBoundQualifiersOnly(existingAnnotation, newAnnotation). Such a checker usually also overridesBaseTypeVisitor#checkExplicitAnnotationsOnIntersectionBounds, whoseexplicit.annotation.ignoredwarning assumes that only the first bound counts: under the greatest lower bound, no written qualifier is ignored. This method decides only how the per-hierarchy summary is computed; that summary is always written back onto every bound (homogenization). Computing it viagreatestLowerBoundQualifiersOnlyadditionally relies onQualifierHierarchy.greatestLowerBoundQualifiers(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)being consistent withQualifierHierarchy.isSubtypeQualifiers(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)for the qualifier hierarchy in use (see that method's documentation): if a qualifier hierarchy's true subtyping relation depends on something a static declarative lattice cannot express, such as a checker option, and its computation of the greatest lower bound was not updated to match, the summary this method returns can be a qualifier the qualifier hierarchy's own subtype check would not itself have derived, producing a spurious type error where none existed before the summary was combined -- not a fault of this method or of homogenization, but of that inconsistency.- Parameters:
existingAnnotation- the annotation already chosen for this hierarchy, from an earlier bound in source ordernewAnnotation- a conflicting annotation from a later bound in the same hierarchyqualifierHierarchy- the qualifier hierarchy that both annotations belong to- Returns:
- the annotation to use as the intersection's summary for this hierarchy
-
getAnnotatedType
Returns an AnnotatedTypeMirror representing the annotated type ofclazz.- Parameters:
clazz- a class- Returns:
- the annotated type of
clazz
-
getAnnotationMirror
public @Nullable AnnotationMirror getAnnotationMirror(Tree tree, Class<? extends Annotation> target) Description copied from interface:AnnotationProviderReturns the annotation ontreethat is in the hierarchy that contains the qualifiertarget. Returns null if none exists.- Specified by:
getAnnotationMirrorin interfaceAnnotationProvider- Parameters:
tree- the tree of which the annotation is returnedtarget- the class of the annotation- Returns:
- the annotation on
treethat has the classtarget, or null
-
getAnnotatedType
Returns an AnnotatedTypeMirror representing the annotated type oftree.- Parameters:
tree- the AST node- Returns:
- the annotated type of
tree
-
preProcessClassTree
Called byBaseTypeVisitor.visitClass(ClassTree, Void)before the classTree is type checked.- Parameters:
classTree- the class on which to perform preprocessing
-
shouldStoreInBytecode
protected boolean shouldStoreInBytecode()Returns whetherpostProcessClassTree(com.sun.source.tree.ClassTree)stores into the class file the qualifiers that do not appear in the source code (defaulted types and inherited declaration annotations).The default implementation returns true unless
-AstoreInBytecode=falsewas supplied. A checker whose computed qualifiers must never reach bytecode (for example, because they are an implementation detail that no reader of the class file should depend on) can override this to return false.Called from the
AnnotatedTypeFactoryconstructor, before any subclass constructor body or field initializer runs, so an override must not depend on subclass state.- Returns:
- whether to store computed qualifiers into the class file
-
postProcessClassTree
Called byBaseTypeVisitor.visitClass(ClassTree, Void)after the ClassTree has been type checked.The default implementation stores the defaulted AnnotatedTypeMirrors and inherited declaration annotations back into the corresponding Elements, if
shouldStoreInBytecode()returned true, and then runs theTypeInformationPresenterreturned bycreateTypeInformationPresenter(), if any.- Parameters:
tree- the ClassTree that has been processed
-
getAnnotatedTypeFromTypeTree
Determines the annotated type from a type in tree form.Note that we cannot decide from a Tree alone (without attribution) whether it is a type use or an expression. For example, an identifier can be either a type or an expression. See
TreeUtils.isTypeTree(Tree).- Parameters:
tree- the type tree- Returns:
- the annotated type of the type in the AST
-
getTypeDeclarationBounds
Returns the set of qualifiers that are the upper bounds for a use of the type.For a specific type system, the type declaration bound is retrieved in the following precedence: (1) the annotation on the type declaration bound (2) if an annotation with
@UpperBoundFormentions the type or the type kind, use that annotation (3) the top annotation- Parameters:
type- a type whose upper bounds to obtain- Returns:
- the set of qualifiers that are the upper bounds for a use of the type
-
getTypeDeclarationBoundsFromUse
public AnnotationMirrorSet getTypeDeclarationBoundsFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType useType) Returns the set of qualifiers that are the upper bounds for a use of the type. If there is a viewpoint adapter, the type declaration bounds are viewpoint-adapted to the use type before they are returned.- Parameters:
useType- the actual type use whose upper bounds to obtain- Returns:
- the set of adapted qualifiers that are the upper bounds for a use of the type
-
getViewpointAdaptedTypeDeclarationBounds
public AnnotationMirrorSet getViewpointAdaptedTypeDeclarationBounds(AnnotationMirrorSet viewpointBounds, AnnotatedTypeMirror declarationBoundType) Returns the primary qualifiers ofdeclarationBoundType, viewpoint-adapted from the viewpoint ofviewpointBounds. Returns them unadapted if this type factory has no viewpoint adapter.- Parameters:
viewpointBounds- the type-declaration bounds that provide the viewpointdeclarationBoundType- the type whose declaration bounds to adapt- Returns:
- the adapted declaration bounds
-
getAnnotationOrTypeDeclarationBound
public AnnotationMirrorSet getAnnotationOrTypeDeclarationBound(TypeMirror type, Set<? extends AnnotationMirror> annos) Compare the givenannoswith the declaration bounds oftypeand return the appropriate qualifiers. For each qualifier inannos, if it is a subtype of the declaration bound in the same hierarchy, it will be added to the result; otherwise, the declaration bound will be added to the result instead.- Parameters:
type- java type that specifies the qualifier upper boundannos- a set of qualifiers to be compared with the declaration bounds oftype- Returns:
- the modified
annosafter applying the rules described above
-
getDefaultTypeDeclarationBounds
Returns the set of qualifiers that are the upper bound for a type use if no other bound is specified for the type.This implementation returns the top qualifiers by default. Subclass may override to return different qualifiers.
- Returns:
- the set of qualifiers that are the upper bound for a type use if no other bound is specified for the type
-
getDefaultAnnosForUses
Returns the set of qualifiers that should be applied to unannotated uses of the given element, as specified byDefaultQualifierForUse.This implementation always returns an empty set, because
@DefaultQualifierForUseis implemented byDefaultQualifierForUseTypeAnnotator, which only aGenericAnnotatedTypeFactorycreates.GenericAnnotatedTypeFactoryoverrides this to consult that annotator.- Parameters:
element- the element- Returns:
- the set of default-for-use qualifiers; empty in this implementation
-
getTypeOfExtendsImplements
Returns the type of the extends or implements clause.The primary qualifier is either an explicit annotation on
clause, or it is the qualifier upper bounds for uses of the type of the clause.- Parameters:
clause- tree that represents an extends or implements clause- Returns:
- the type of the extends or implements clause
-
fromElement
Creates an AnnotatedTypeMirror foreltthat includes: annotations explicitly written on the element and annotations from stub files. A method that the compiler generated for a record gets the annotations of thejava.lang.Recordmethod that it implements; seeapplyRecordMethodTypesToGeneratedMethod(javax.lang.model.element.Element, org.checkerframework.framework.type.AnnotatedTypeMirror).Does not include default qualifiers. To obtain them, use
getAnnotatedType(Element).Does not include fake overrides from the stub file.
- Parameters:
elt- the element- Returns:
- AnnotatedTypeMirror of the element with explicitly-written and stub file annotations
-
getElementAnnotations
Returns the primary annotations on the type thatfromElement(Element)computes forelt, without the defensive deep copy thatfromElementmakes on every cache hit.fromElementhands out a freshly deep-copied, mutable type so that callers may modify it. Callers that only read an element's primary annotations do not need that copy: when the type is cached, this returns the cached type's primary annotations directly.AnnotatedTypeMirror.getAnnotations()already returns an unmodifiable set, and cached types are never mutated, so the result is safe to read. The result must not be retained and mutated.- Parameters:
elt- the element- Returns:
- the primary annotations
fromElementwould put onelt's type; the caller must treat the result as read-only
-
mergeAnnotationFileAnnosIntoType
protected AnnotatedTypeMirror mergeAnnotationFileAnnosIntoType(@Nullable AnnotatedTypeMirror type, Element elt, AnnotationFileElementTypes source) Merges types from annotation files foreltintotypeby taking the greatest lower bound of the annotations in both.- Parameters:
type- the type to apply annotation file types toelt- the element from which to read annotation file typessource- storage for current annotation file annotations- Returns:
- the type, side-effected to add the annotation file types
-
canUseCachedFlowDependentType
Returns true if a cached type of the flow-dependent expressiontree(seeisFlowDependent(ExpressionTree)) is still correct, i.e., the refined types of the expressions it was computed from have not changed since it was cached. This implementation, which performs no dataflow analysis, returns true.A factory that computes the types of expressions from another factory's dataflow results, such as the Initialization Checker's from the
InitializationFieldAccessSubchecker's, relies on the order of the checkers: the subchecker finishes the compilation unit before the parent checker's visitor runs. It may keep this default only as long as it is not queried earlier. A factory that can be queried earlier must override this method andcanCacheFlowDependentType(ExpressionTree).isAnonymousDiamondSupertypeFinal(com.sun.source.tree.NewClassTree)has the same default for the same reason.- Parameters:
tree- a flow-dependent expression- Returns:
- true if a cached type of
treecan be used
-
canCacheFlowDependentType
Returns true if the type of the flow-dependent expressiontree(seeisFlowDependent(ExpressionTree)) can be cached, i.e., it is computed from refined types that remain correct as long ascanUseCachedFlowDependentType(ExpressionTree)holds. The type of a poly expression whose type arguments are inferred together with an enclosing invocation also depends on the other arguments of that invocation, not only on its own subexpressions. This implementation, which performs no dataflow analysis, returns true.- Parameters:
tree- a flow-dependent expression- Returns:
- true if the type of
treecan be cached
-
addComputedTypeAnnotations
Changes annotations on a type obtained from aTree. By default, this method does nothing. GenericAnnotatedTypeFactory uses this method to implement defaulting and inference (flow-sensitive type refinement). Its subclasses usually override it only to customize default annotations.Subclasses that override this method should also override
addComputedTypeAnnotations(Element, AnnotatedTypeMirror).- Parameters:
tree- an AST nodetype- the type obtained fromtree
-
addComputedTypeAnnotations
Changes annotations on a type obtained from anElement. By default, this method does nothing. GenericAnnotatedTypeFactory uses this method to implement defaulting.Subclasses that override this method should also override
addComputedTypeAnnotations(Tree, AnnotatedTypeMirror).- Parameters:
elt- an elementtype- the type obtained fromelt
-
addDefaultAnnotations
Adds default annotations totype. This method should only be used in places where the correct annotations cannot be computed because of type argument of raw types. (SeeAnnotatedTypeMirror.AnnotatedWildcardType.isTypeArgOfRawType().)- Parameters:
type- annotated type to which default annotations are added
-
postDirectSuperTypes
protected void postDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes) A callback method for the AnnotatedTypeFactory subtypes to customize directSupertypes(). Overriding methods should merely change the annotations on the supertypes, without adding or removing new types.The default provided implementation adds
typeannotations tosupertypes. This allows thetypeand its supertypes to have the qualifiers.- Parameters:
type- the type whose supertypes are desiredsupertypes- the supertypes as specified by the base AnnotatedTypeFactory
-
postAsMemberOf
A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf(). Overriding methods should merely change the annotations on the subtypes, without changing the types.- Parameters:
type- the annotated type of the elementowner- the annotated type of the receiver of the accessing treeelement- the element of the field or method
-
addAnnotationFromFieldInvariant
protected void addAnnotationFromFieldInvariant(AnnotatedTypeMirror type, AnnotatedTypeMirror accessedVia, VariableElement field) Adds the qualifier specified by a field invariant forfieldtotype.- Parameters:
type- annotated type to which the annotation is addedaccessedVia- the annotated type of the receiver of the accessing tree. (Only used to get the type element of the underling type.)field- element representing the field
-
getFieldInvariants
Returns the field invariants for the given class, as expressed by the user in@FieldInvariantmethod annotations.Subclasses may implement their own field invariant annotations if
@FieldInvariantis not expressive enough. They must override this method to properly create AnnotationMirror and also overridegetFieldInvariantDeclarationAnnotations()to return their field invariants.- Parameters:
element- class for which to get invariants- Returns:
- field invariants for
element
-
getFieldInvariantAnnotationTree
public @Nullable AnnotationTree getFieldInvariantAnnotationTree(@Nullable List<? extends AnnotationTree> annoTrees) Returns the element ofannoTreesthat is a use of one of the field invariant annotations (as specified viagetFieldInvariantDeclarationAnnotations(). If one isn't found, null is returned.- Parameters:
annoTrees- list of trees to search; the result is one of the list elements, or null- Returns:
- the AnnotationTree that is a use of one of the field invariant annotations, or null if one isn't found
-
getFieldInvariantDeclarationAnnotations
Returns the set of classes of field invariant annotations.- Returns:
- the set of classes of field invariant annotations
-
typeVariablesFromUse
public List<AnnotatedTypeParameterBounds> typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type, TypeElement element) Adapt the upper bounds of the type variables of a class relative to the type instantiation. In some type systems, the upper bounds depend on the instantiation of the class. For example, in the Generic Universe Type system, consider a class declaration
then the instantiationclass C<X extends @Peer Object>
is legal. The upper bounds of class C have to be adapted by the main modifier.@Rep C<@Rep Object>An example of an adaptation follows. Suppose, I have a declaration:
And an instantiation:class MyClass<E extends List<E>>new MyClass<@NonNull String>()The upper bound of E adapted to the argument String, would be
List<@NonNull String>and the lower bound would be an AnnotatedNullType.TODO: ensure that this method is consistently used instead of directly querying the type variables.
- Parameters:
type- the use of the typeelement- the corresponding element- Returns:
- the adapted bounds of the type parameters
-
getConstructorReceiverType
Returns the receiver type used to viewpoint-adapt a constructor invocation.- Parameters:
tree- a constructor invocation tree- Returns:
- the receiver type
- See Also:
-
getMethodReceiverType
Returns the receiver type used to viewpoint-adapt a method invocation.- Parameters:
tree- a method invocation tree- Returns:
- the receiver type, or null if the invocation has no receiver
- See Also:
-
getAnnotatedNullType
public AnnotatedTypeMirror.AnnotatedNullType getAnnotatedNullType(Set<? extends AnnotationMirror> annotations) Creates and returns an AnnotatedNullType qualified withannotations.- Parameters:
annotations- the set of AnnotationMirrors to qualify the returned type with- Returns:
- AnnotatedNullType qualified with
annotations
-
getImplicitReceiverType
protected @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(ExpressionTree tree) Returns the implicit receiver type of an expression tree.The result is null for expressions that don't have a receiver, e.g. for a local variable or method parameter access. The result is also null for expressions that have an explicit receiver.
Clients should generally call
getReceiverType(com.sun.source.tree.ExpressionTree).- Parameters:
tree- the expression that might have an implicit receiver- Returns:
- the type of the implicit receiver. Returns null if the expression has an explicit receiver or doesn't have a receiver.
-
getSelfType
Returns the type ofthisat the location oftree. Returnsnulliftreeis in a location wherethishas no meaning, such as the body of a static method.The parameter is an arbitrary tree and does not have to mention "this", neither explicitly nor implicitly. This method can be overridden for type-system specific behavior.
- Parameters:
tree- location used to decide the type ofthis- Returns:
- the type of
thisat the location oftree
-
getSelfType
Returns the type ofthisinclassElt: the class applied to its own type parameters, with the annotations that the class's defaults give it. This is the receiver that a method of the class has when neither the method nor a default in its scope says otherwise, and the type ofthisin a field initializer or an initializer block. A default that only a method is in the scope of is not part of it. Its enclosing type is the type of this in the enclosing class, without the defaults ofclassElt: a default of an inner class says nothing about its enclosing instance.- Parameters:
classElt- a class- Returns:
- the type of
thisinclassElt
-
getInitializerTargetType
Returns the target type of an initializer ofnewArray: the component type of the array (JLS 10.6), without the lub of the initializers' types thatgetAnnotatedType(Tree)gives the array. Type argument inference of a generic initializer, such asnew Pair<>(a, b), and the functional interface type of a lambda initializer use it. The lub would infer every initializer again for each initializer, which is quadratic in the number of initializers, and exponential where the initializers' inference asks for the target type again.- Parameters:
newArray- a new array expression with initializers- Returns:
- the target type of an initializer of
newArray
-
isComputingInitializerTargetType
Returns true if the type ofnewArrayis being computed bygetInitializerTargetType(com.sun.source.tree.NewArrayTree), so it must not depend on the types of the initializers.- Parameters:
newArray- a new array expression- Returns:
- true if the type of
newArrayis being computed for the target type of one of its initializers
-
getEnclosingClassOrMethod
Returns the innermost enclosing method or class tree oftree. Since artificial trees are assigned to be the child node of the original tree, their enclosing trees are found the same way as normal trees.If the tree is inside an annotation, then
nullis returned.- Parameters:
tree- tree to whose innermost enclosing method or class to return- Returns:
- the innermost enclosing method or class tree of
tree, ornulliftreeis inside an annotation
-
getEnclosingType
public AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(TypeElement typeElement, Tree tree) Returns theAnnotatedTypeMirrorof the enclosing type at the location oftreethat is the same type astypeElement.- Parameters:
typeElement- type of the enclosing type to returntree- location to use- Returns:
- the enclosing type at the location of
treethat is the same type astypeElement
-
getEnclosingSubType
public AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingSubType(TypeElement typeElement, Tree tree) Returns theAnnotatedTypeMirrorof the enclosing type at the location oftreethat is a subtype oftypeElement.- Parameters:
typeElement- super type of the enclosing type to returntree- location to use- Returns:
- the enclosing type at the location of
treethat is a subtype oftypeElement
-
getReceiverType
Returns the receiver type of the expression tree, which might be the type of an implicitthis. Returns null if the expression has no explicit or implicit receiver.- Parameters:
expression- the expression for which to determine the receiver type- Returns:
- the type of the receiver of expression
- See Also:
-
methodFromUse
public final AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree) Determines the type of the invoked method based on the passed method invocation tree.The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and method invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on method invocation parameters.
As an implementation detail, this method depends on
AnnotatedTypes.asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element), and customization based on receiver type should be in accordance to its specification.The return type is a pair of the type of the invoked method and the (inferred) type arguments. Note that neither the explicitly passed nor the inferred type arguments are guaranteed to be subtypes of the corresponding upper bounds. See method
BaseTypeVisitor.checkTypeArguments(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)for the checks of type argument well-formedness.Note that "this" and "super" constructor invocations are also handled by this method (explicit or implicit ones, at the beginning of a constructor). Method
constructorFromUse(NewClassTree)is only used for a constructor invocation in a "new" expression.- Parameters:
tree- the method invocation tree- Returns:
- the type of the invoked method and any (explict or inferred) type arguments
-
methodFromUseWithoutTypeArgInference
public AnnotatedTypeFactory.ParameterizedExecutableType methodFromUseWithoutTypeArgInference(MethodInvocationTree tree) Returns the same asmethodFromUse(MethodInvocationTree), but without inferred type arguments.- Parameters:
tree- a method invocation tree- Returns:
- the type of the invoked method and any explicit type arguments
-
methodFromUse
protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree, boolean inferTypeArgs) The implementation ofmethodFromUse(MethodInvocationTree)andmethodFromUseWithoutTypeArgInference(MethodInvocationTree).- Parameters:
tree- a method invocation treeinferTypeArgs- true if type arguments should be inferred- Returns:
- the type of the invoked method, any explicit type arguments, and if
inferTypeArgsis true, any inferred type arguments
-
methodFromUse
public final AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType) Determines the type of the invoked method based on the passed expression tree, executable element, and receiver type.- Parameters:
tree- either a MethodInvocationTree or a MemberReferenceTreemethodElt- the element of the referenced methodreceiverType- the type of the receiver- Returns:
- the type of the method being invoked with tree and the (inferred) type arguments
- See Also:
-
methodFromUseWithoutTypeArgInference
public final AnnotatedTypeFactory.ParameterizedExecutableType methodFromUseWithoutTypeArgInference(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType) Returns the same asmethodFromUse(ExpressionTree, ExecutableElement, AnnotatedTypeMirror), but without inferred type arguments.- Parameters:
tree- either a MethodInvocationTree or a MemberReferenceTreemethodElt- the element of the referenced methodreceiverType- the type of the receiver- Returns:
- the type of the method being invoked with tree without inferring type arguments
-
methodFromUse
protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType, boolean inferTypeArgs) The implementation ofmethodFromUse(ExpressionTree, ExecutableElement, AnnotatedTypeMirror)andmethodFromUseWithoutTypeArgInference(ExpressionTree, ExecutableElement, AnnotatedTypeMirror).- Parameters:
tree- either a MethodInvocationTree or a MemberReferenceTreemethodElt- the element of the referenced methodreceiverType- the type of the receiverinferTypeArgs- true if type arguments should be inferred- Returns:
- the type of the invoked method
-
shouldCacheMethodAsMemberOf
protected boolean shouldCacheMethodAsMemberOf()WhethermethodAsMemberOfCachemay be used. Returns true by default. A checker whose method types are call-site-dependent in a way not captured by(method, receiver)-- e.g. the Value Checker (results computed from argument values) or the MethodVal/Reflection Checker -- must override this to return false.- Returns:
- true if the method-as-member-of cache is sound for this checker
-
getDirectSupertypes
public List<AnnotatedTypeMirror.AnnotatedDeclaredType> getDirectSupertypes(AnnotatedTypeMirror.AnnotatedDeclaredType type) Returns the direct supertypes oftype: the result ofSupertypeFinder.directSupertypes(AnnotatedDeclaredType), cached.directSupertypesis a pure function oftype's structure and annotations (no tree or call arguments), so the structural(type)key is sound; the same structural type's supertypes are recomputed constantly while walking type hierarchies (asSuper,allSupertypes). Stores and returns deep copies, since callers mutate the supertypes' annotations. The exception is an anonymous class created with a diamond while its supertype, which is inferred from the creation expression, can still change; seehasChangingSupertype(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType).- Parameters:
type- a declared type- Returns:
- the direct supertypes of
type(an unmodifiable list)
-
methodFromUsePreSubstitution
protected void methodFromUsePreSubstitution(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.- Parameters:
tree- either a method invocation or a member reference treetype- declared method type before type variable substitutionresolvePolyQuals- if true, resolve polymorphic qualifiers
-
adaptGetClassReturnTypeToReceiver
protected void adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, ExpressionTree tree) Java special-cases the return type ofgetClass(). Though the method has a return type ofClass<?>, the compiler special cases this return-type and changes the bound of the type argument to the erasure of the receiver type. For example:x.getClass()has the typeClass< ? extends erasure_of_x >someInteger.getClass()has the typeClass< ? extends Integer >
A method reference such as
x::getClassorFoo::getClassreturns the same type as an invocation on the reference's receiver.- Parameters:
getClassType- this must be a type representing a call to Object.getClass otherwise a runtime exception will be thrown. It is modified by side effect.receiverType- the receiver type of the method invocation (not the declared receiver type)tree- a getClass method invocation or member reference tree
-
getIterableElementType
Returns the element type ofexpression. This is usually the type ofexpression.itertor().next(). Ifexpressionis an array, it is the component type of the array.- Parameters:
expression- an expression whose type is an array or implementsIterable- Returns:
- the type of
expression.itertor().next()or ifexpressionis an array, the component type of the array
-
getIterableElementType
protected AnnotatedTypeMirror getIterableElementType(ExpressionTree expression, AnnotatedTypeMirror iterableType) Returns the element type ofiterableType. This is usually the type ofexpression.itertor().next(). Ifexpressionis an array, it is the component type of the array.- Parameters:
expression- an expression whose type is an array or implementsIterableiterableType- the type of the expression- Returns:
- the type of
expression.itertor().next()or ifexpressionis an array, the component type of the array
-
constructorFromUse
Determines the type of the invoked constructor based on the passed new class tree.The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and constructor invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on constructor invocation parameters.
As an implementation detail, this method depends on
AnnotatedTypes.asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element), and customization based on receiver type should be in accordance with its specification.The return type is a pair of the type of the invoked constructor and the (inferred) type arguments. Note that neither the explicitly passed nor the inferred type arguments are guaranteed to be subtypes of the corresponding upper bounds. See method
BaseTypeVisitor.checkTypeArguments(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)for the checks of type argument well-formedness.Note that "this" and "super" constructor invocations are handled by method
methodFromUse(com.sun.source.tree.MethodInvocationTree). This method only handles constructor invocations in a "new" expression.- Parameters:
tree- the constructor invocation tree- Returns:
- the annotated type of the invoked constructor (as an executable type) and the (inferred) type arguments
-
constructorFromUseWithoutTypeArgInference
public AnnotatedTypeFactory.ParameterizedExecutableType constructorFromUseWithoutTypeArgInference(NewClassTree tree) The same asconstructorFromUse(NewClassTree), but no type arguments are inferred.- Parameters:
tree- the constructor invocation tree- Returns:
- the annotated type of the invoked constructor (as an executable type) and the explicit type arguments
-
clearParsePhaseCache
public void clearParsePhaseCache()Clears any caches used exclusively during the parse phase. Subclasses may override this to clear their own caches. -
getResultingTypeOfConstructorMemberReference
public AnnotatedTypeMirror getResultingTypeOfConstructorMemberReference(MemberReferenceTree memberReferenceTree, AnnotatedTypeMirror.AnnotatedExecutableType constructorType) Gets the type of the resulting constructor call of a MemberReferenceTree.- Parameters:
memberReferenceTree- MemberReferenceTree where the member is a constructorconstructorType- AnnotatedExecutableType of the declaration of the constructor- Returns:
- AnnotatedTypeMirror of the resulting type of the constructor
-
constructorFromUse
protected AnnotatedTypeFactory.ParameterizedExecutableType constructorFromUse(NewClassTree tree, boolean inferTypeArgs) The implementation ofconstructorFromUse(NewClassTree)andconstructorFromUseWithoutTypeArgInference(NewClassTree).- Parameters:
tree- the constructor invocation treeinferTypeArgs- true if the type arguments should be inferred- Returns:
- the annotated type of the invoked constructor (as an executable type) and the type arguments
-
getEnumConstructorQualifiers
Returns the annotations that should be applied to enum constructors. This implementation returns an empty set. Subclasses can override to return a different set.- Returns:
- the annotations that should be applied to enum constructors
-
getExplicitNewClassAnnos
Returns the annotations explicitly written on a NewClassTree.new @HERE Class()- Parameters:
newClassTree- a constructor invocation- Returns:
- the annotations explicitly written on a NewClassTree
-
getExplicitNewClassClassTypeArgs
Returns the partially-annotated explicit class type arguments of the new class tree. TheAnnotatedTypeMirroronly include the annotations explicitly written on the explict type arguments. (IfnewClassuse a diamond operator, this method returns the empty list.) For example, when called withnew MyClass<@HERE String>()this method would return a list containing@HERE String.- Parameters:
newClass- a new class tree- Returns:
- the partially annotated
AnnotatedTypeMirrors for the (explicit) class type arguments of the new class tree
-
getAnonymousDiamondSuperConstructor
public AnnotatedTypeMirror.AnnotatedExecutableType getAnonymousDiamondSuperConstructor(NewClassTree tree) Returns the type of the superclass constructor thattree, an anonymous class creation with a diamond such asnew C<>(args) {...}, invokes, as a member of the generic superclassC<T>. Type argument inference treatstreeasnew C<>(args)(JLS 15.9.3), and uses this type to infer the type arguments of the superclass. Polymorphic qualifiers are not resolved.- Parameters:
tree- an anonymous class creation with a diamond- Returns:
- the type of the invoked superclass constructor, before type argument inference
-
getAnonymousDiamondSupertype
public @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType getAnonymousDiamondSupertype(NewClassTree tree) Returns the supertype of the anonymous class created bytree, a diamond such asnew C<>(args) {...}, with the type arguments inferred as fornew C<>(args)(JLS 15.9.3). The supertype is the superclass, or the interface that the anonymous class implements.Returns null if inference does not determine the type arguments, or if this method is invoked again for
treewhile it infers them. The caller then uses javac's supertype, which has defaulted type arguments. Invariant: a supertype that is not the inferred one is never cached; seehasChangingSupertype(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType).- Parameters:
tree- an anonymous class creation with a diamond- Returns:
- the inferred supertype of the anonymous class, or null
-
isAnonymousDiamondSupertypeFinal
Returns true if the supertype inferred for the anonymous class created bycreation, a diamond such asnew C<>(args) {...}, can no longer change. It is inferred from the types of the arguments and of the context, which change during dataflow analysis of the enclosing method.This implementation, which performs no dataflow analysis, returns true, like
canUseCachedFlowDependentType(ExpressionTree).GenericAnnotatedTypeFactoryreturns true once dataflow analysis of the anonymous class has started, which is after that of the enclosing method. A factory that does not keep track of the analyzed classes itself must forward to the factory that does.- Parameters:
creation- an anonymous class creation with a diamond- Returns:
- true if the inferred supertype of the anonymous class can no longer change
-
getAnonymousDiamondCreation
public @Nullable NewClassTree getAnonymousDiamondCreation(AnnotatedTypeMirror.AnnotatedDeclaredType type) Returns the class instance creation expression oftype's class if that is an anonymous class created with a diamond, as innew C<>(args) {...}.The supertype of such a class is inferred from the creation expression and its context, and can change during dataflow analysis; see
hasChangingSupertype(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType).- Parameters:
type- a declared type- Returns:
- the anonymous class creation with a diamond that declares
type's class, or null
-
constructorFromUsePreSubstitution
protected void constructorFromUsePreSubstitution(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.- Parameters:
tree- a NewClassTree from constructorFromUse()type- declared method type before type variable substitutionresolvePolyQuals- if true, resolve polymorphic qualifiers
-
getMethodReturnType
Returns the return type of the methodm.- Parameters:
m- tree of a method declaration- Returns:
- the return type of the method
-
getMethodReturnType
Returns the return type of the methodmat the return statementr. This implementation just callsgetMethodReturnType(MethodTree), but subclasses may override this method to change the type based on the return statement.- Parameters:
m- tree of a method declarationr- a return statement within methodm- Returns:
- the return type of the method
mat the return statementr
-
getBoxedType
public AnnotatedTypeMirror.AnnotatedDeclaredType getBoxedType(AnnotatedTypeMirror.AnnotatedPrimitiveType type) Returns the annotated boxed type of the given primitive type. The returned type would only have the annotations on the given type.Subclasses may override this method safely to override this behavior.
- Parameters:
type- the primitive type- Returns:
- the boxed declared type of the passed primitive type
-
applyUnboxing
Returns a primitive type: either the argument, or the result of unboxing it (which might affect its annotations).Subclasses should override
getUnboxedType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)rather than this method.- Parameters:
type- a type: a primitive or boxed primitive- Returns:
- the unboxed variant of the type
-
getUnboxedType
public AnnotatedTypeMirror.AnnotatedPrimitiveType getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type) throws IllegalArgumentException Returns the annotated primitive type of the given declared type if it is a boxed declared type. Otherwise, it throws IllegalArgumentException exception.In the
AnnotatedTypeFactoryimplementation, the returned type has the same primary annotations as the given type. Subclasses may override this behavior.- Parameters:
type- the declared type- Returns:
- the unboxed primitive type
- Throws:
IllegalArgumentException- if the type given has no unbox conversion
-
getStringType
Returns AnnotatedDeclaredType with underlying type String and annotations copied from type. Subclasses may change the annotations.- Parameters:
type- type to convert to String- Returns:
- AnnotatedTypeMirror that results from converting type to a String type
-
getWidenedType
public final AnnotatedTypeMirror getWidenedType(AnnotatedTypeMirror exprType, AnnotatedTypeMirror widenedType) Returns a widened type if applicable, otherwise returns its first argument.Subclasses should override
getWidenedAnnotations(org.checkerframework.javacutil.AnnotationMirrorSet, javax.lang.model.type.TypeKind, javax.lang.model.type.TypeKind)rather than this method.- Parameters:
exprType- type to possibly widenwidenedType- type to possibly widen to; its annotations are ignored- Returns:
- if widening is applicable, the result of converting
typeto the underlying type ofwidenedType; otherwisetype
-
getWidenedType
public final AnnotatedTypeMirror getWidenedType(AnnotationMirrorSet exprAnnos, TypeMirror exprTypeMirror, AnnotatedTypeMirror widenedType) Applies widening if applicable, otherwise returns its first argument.Subclasses should override
getWidenedAnnotations(org.checkerframework.javacutil.AnnotationMirrorSet, javax.lang.model.type.TypeKind, javax.lang.model.type.TypeKind)rather than this method.- Parameters:
exprAnnos- annotations to possibly widenexprTypeMirror- type to possibly widenwidenedType- type to possibly widen to; its annotations are ignored- Returns:
- if widening is applicable, the result of converting
typeto the underlying type ofwidenedType; otherwisetype
-
getNarrowedAnnotations
public AnnotationMirrorSet getNarrowedAnnotations(AnnotationMirrorSet annos, TypeKind typeKind, TypeKind narrowedTypeKind) Returns annotations applicable to typenarrowedTypeKind, that are copied or adapted fromannos.- Parameters:
annos- annotations to narrow, from a primitive or boxed primitivetypeKind- primitive type to narrownarrowedTypeKind- target for the returned annotations; a primitive type that is narrower thantypeKind(in the sense of JLS 5.1.3)- Returns:
- result of converting
annosfromtypeKindtonarrowedTypeKind
-
getWidenedAnnotations
public AnnotationMirrorSet getWidenedAnnotations(AnnotationMirrorSet annos, TypeKind typeKind, TypeKind widenedTypeKind) Returns annotations applicable to typewidenedTypeKind, that are copied or adapted fromannos.- Parameters:
annos- annotations to widen, from a primitive or boxed primitivetypeKind- primitive type to widenwidenedTypeKind- target for the returned annotations; a primitive type that is wider thantypeKind(in the sense of JLS 5.1.2)- Returns:
- result of converting
annosfromtypeKindtowidenedTypeKind
-
binaryTreeArgTypes
Returns the types of the two arguments to the BinaryTree. Please refer tobinaryTreeArgTypes(TypeMirror, AnnotatedTypeMirror, AnnotatedTypeMirror))} for more details.- Parameters:
tree- a binary tree- Returns:
- the types of the two arguments
-
compoundAssignmentTreeArgTypes
public Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> compoundAssignmentTreeArgTypes(CompoundAssignmentTree tree) Returns the types of the two arguments to the CompoundAssignmentTree. Please refer tobinaryTreeArgTypes(TypeMirror, AnnotatedTypeMirror, AnnotatedTypeMirror)) for more details.- Parameters:
tree- a compound assignment tree- Returns:
- the types of the two arguments
-
binaryTreeArgTypes
protected Pair<AnnotatedTypeMirror,AnnotatedTypeMirror> binaryTreeArgTypes(TypeMirror resultType, AnnotatedTypeMirror left, AnnotatedTypeMirror right) Returns the types of the two arguments to a binary operation. There are two special cases:1. If both operands have numeric type, widening and unboxing will be applied accordingly.
2. If we have a non-string operand in a string concatenation (i.e., result is a string), we will always return a string ATM for the operand. The resulting ATM will have the original annotations with the declaration bounds of string type applied. Please check
getAnnotationOrTypeDeclarationBound(javax.lang.model.type.TypeMirror, java.util.Set<? extends javax.lang.model.element.AnnotationMirror>)for more details.- Parameters:
resultType- the type of the result of a binary operationleft- the type of the left argument of a binary operationright- the type of the right argument of a binary operation- Returns:
- the types of the two arguments
-
getNarrowedPrimitive
public AnnotatedTypeMirror.AnnotatedPrimitiveType getNarrowedPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type, TypeMirror narrowedTypeMirror) Returns AnnotatedPrimitiveType with underlying typenarrowedTypeMirrorand with annotations copied or adapted fromtype.Currently this method is called only for primitives that are narrowed at assignments from literal ints, for example,
byte b = 1;. All other narrowing conversions happen at typecasts.- Parameters:
type- type to narrownarrowedTypeMirror- underlying type for the returned type mirror- Returns:
- result of converting
typetonarrowedTypeMirror
-
getAnnotatedType
- See Also:
-
getAnnotatedType
- See Also:
-
getAnnotatedType
- See Also:
-
getAnnotatedType
- See Also:
-
getAnnotatedType
- See Also:
-
getAnnotatedType
- See Also:
-
fromElement
SeefromElement(Element).- See Also:
-
fromElement
SeefromElement(Element).- See Also:
-
isSupportedQualifier
@EnsuresNonNullIf(expression="#1", result=true) public boolean isSupportedQualifier(@Nullable AnnotationMirror am) Returns true if the given annotation is a part of the type system under which this type factory operates. Null is never a supported qualifier; the parameter is nullable to allow the result of canonicalAnnotation to be passed in directly.amis checked exactly as given: an alias for a supported qualifier fails this check. For an annotation as written, such as one read from anAnnotationTree, useisSupportedQualifierOrAlias(javax.lang.model.element.AnnotationMirror)instead.- Parameters:
am- any annotation- Returns:
- true if that annotation is part of the type system under which this type factory operates, false otherwise
-
isSupportedQualifier
Returns true if the given class is a part of the type system under which this type factory operates.- Parameters:
clazz- annotation class- Returns:
- true if that class is a type qualifier in the type system under which this type factory operates, false otherwise
-
isSupportedQualifier
Returns true if the given class name is a part of the type system under which this type factory operates.- Parameters:
className- fully-qualified annotation class name- Returns:
- true if that class name is a type qualifier in the type system under which this type factory operates, false otherwise
-
addAliasedTypeAnnotation
Adds the annotationaliasClassas an alias for the canonical annotationcanonicalAnnothat will be used by the Checker Framework in the alias's place.By specifying the alias/canonical relationship using this method, the elements of the alias are not preserved when the canonical annotation to use is constructed from the alias. If you want the elements to be copied over as well, use
addAliasedTypeAnnotation(Class, Class, boolean, String...).This method must be called before
postInit().- Parameters:
aliasClass- the class of the aliased annotationcanonicalAnno- the canonical annotation
-
addAliasedTypeAnnotation
protected void addAliasedTypeAnnotation(@FullyQualifiedName String aliasName, AnnotationMirror canonicalAnno) Adds the annotation, whose fully-qualified name is given byaliasName, as an alias for the canonical annotationcanonicalAnnothat will be used by the Checker Framework in the alias's place.Use this method if the alias class is not necessarily on the classpath at Checker Framework compile and run time. Otherwise, use
addAliasedTypeAnnotation(Class, AnnotationMirror)which prevents the possibility of a typo in the class name.- Parameters:
aliasName- the canonical name of the aliased annotationcanonicalAnno- the canonical annotation
-
addAliasedTypeAnnotation
protected void addAliasedTypeAnnotation(Class<?> aliasClass, Class<?> canonicalClass, boolean copyElements, String... ignorableElements) Adds the annotationaliasClassas an alias for the canonical annotationcanonicalClassthat will be used by the Checker Framework in the alias's place.You may specify the copyElements flag to indicate whether you want the elements of the alias to be copied over when the canonical annotation is constructed as a copy of
canonicalClass. Be careful that the framework will try to copy the elements by name matching, so make sure that names and types of the elements to be copied over are exactly the same as the ones in the canonical annotation. Otherwise, an 'Couldn't find element in annotation' error is raised.To facilitate the cases where some of the elements are ignored on purpose when constructing the canonical annotation, this method also provides a varargs
ignorableElementsfor you to explicitly specify the ignoring rules. For example,org.checkerframework.checker.index.qual.IndexForis an alias oforg.checkerframework.checker.index.qual.NonNegative, but the element "value" of@IndexForshould be ignored when constructing@NonNegative. In the cases where all elements are ignored, we can simply useaddAliasedTypeAnnotation(Class, AnnotationMirror)instead.- Parameters:
aliasClass- the class of the aliased annotationcanonicalClass- the class of the canonical annotationcopyElements- a flag that indicates whether you want to copy the elements over when getting the alias from the canonical annotationignorableElements- a list of elements that can be safely dropped when the elements are being copied over
-
addAliasedTypeAnnotation
protected void addAliasedTypeAnnotation(@FullyQualifiedName String aliasName, Class<?> canonicalAnno, boolean copyElements, String... ignorableElements) Adds the annotation, whose fully-qualified name is given byaliasName, as an alias for the canonical annotationcanonicalAnnothat will be used by the Checker Framework in the alias's place.Use this method if the alias class is not necessarily on the classpath at Checker Framework compile and run time. Otherwise, use
addAliasedTypeAnnotation(Class, Class, boolean, String[])which prevents the possibility of a typo in the class name.- Parameters:
aliasName- the canonical name of the aliased classcanonicalAnno- the canonical annotationcopyElements- a flag that indicates whether we want to copy the elements over when getting the alias from the canonical annotationignorableElements- a list of elements that can be safely dropped when the elements are being copied over
-
isAliasedTypeAnnotation
Returns true if the given annotation class is an alias for some other annotation.- Parameters:
annoClass- an annotation class- Returns:
- true if the given annotation class is an alias for some other annotation
-
canonicalAnnotation
Returns the canonical annotation for the passed annotation. May return its argument: that is the result if the passed annotation is not an alias of a canonical one in the framework.A canonical annotation is the internal annotation that will be used by the Checker Framework in the aliased annotation's place.
Use this on an annotation as written, such as one read from an
AnnotationTree, before comparing it against a canonical annotation. If the comparison is instead against this checker's supported qualifiers -- the most common case -- useasSupportedQualifier(javax.lang.model.element.AnnotationMirror)orisSupportedQualifierOrAlias(javax.lang.model.element.AnnotationMirror)directly:ammay resolve to an annotation this checker does not support, which those two methods filter out and this one does not.- Parameters:
am- the qualifier to canonicalize- Returns:
- the canonical annotation, which is
amitself ifamis not an alias
-
asSupportedQualifier
ReturnswrittenAnnoif it is a supported qualifier, or its canonical form if that is a supported qualifier, or null if neither is.Use this on an annotation as written when the caller needs the qualifier itself afterward, not just whether one exists -- for example, to add it to a type or to build a default from it. Unlike
canonicalAnnotation(javax.lang.model.element.AnnotationMirror), which returns a value regardless of whether it is actually supported, this filters to only a supported qualifier:writtenAnnomight be neither this checker's qualifier nor an alias for one, in which case there is nothing this checker can use it for.- Parameters:
writtenAnno- an annotation as written, possibly an alias- Returns:
writtenAnnoor its canonical form, whichever is a supported qualifier; null if neither is
-
isSupportedQualifierOrAlias
Returns true ifwrittenAnnois a supported qualifier, or an alias for one.Use this on an annotation as written when the caller needs only the yes/no answer, such as whether to report a diagnostic about it; see
asSupportedQualifier(javax.lang.model.element.AnnotationMirror)when the qualifier itself is needed afterward.- Parameters:
writtenAnno- an annotation as written, possibly an alias- Returns:
- true if
writtenAnnois a supported qualifier or an alias for one
-
containsSameOrAlias
public boolean containsSameOrAlias(Collection<? extends AnnotationMirror> writtenAnnos, AnnotationMirror target) Returns true if some annotation inwrittenAnnosistarget, or an alias for it.Use this rather than
AnnotationUtils.containsSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror>, javax.lang.model.element.AnnotationMirror)whenwrittenAnnosholds annotations as written, such as ones read from a tree.- Parameters:
writtenAnnos- annotations as written, possibly aliasestarget- a canonical annotation- Returns:
- true if some annotation in
writtenAnnosstands fortarget
-
addAliasedDeclAnnotation
protected void addAliasedDeclAnnotation(Class<? extends Annotation> alias, Class<? extends Annotation> annotationClass, AnnotationMirror annotationToUse) Add the annotationaliasas an alias for the declaration annotationannotation, where the annotation mirrorannotationToUsewill be used instead. If multiple calls are made with the sameannotation, then theannotationToUsemust be the same.The point of
annotationToUseis that it may include elements/fields.- Parameters:
alias- the class of the alias annotationannotationClass- the class of the canonical annotationannotationToUse- the annotation mirror to use
-
addAliasedDeclAnnotation
protected void addAliasedDeclAnnotation(@FullyQualifiedName String alias, @FullyQualifiedName String annotationClassName, AnnotationMirror annotationToUse) Add the annotationaliasas an alias for the declaration annotationannotation, where the annotation mirrorannotationToUsewill be used instead. If multiple calls are made with the sameannotation, then theannotationToUsemust be the same.The point of
annotationToUseis that it may include elements/fields.- Parameters:
alias- the fully-qualified name of the alias annotationannotationClassName- the fully-qualified name of the canonical annotationannotationToUse- the annotation mirror to use
-
addInheritedAnnotation
Adds the annotationannotationin the set of declaration annotations that should be inherited. A declaration annotation will be inherited if it is in this list, or if it has the meta-annotation @InheritedAnnotation. The meta-annotation @InheritedAnnotation should be used instead of this method, if possible. -
toAnnotatedType
A convenience method that converts aTypeMirrorto an emptyAnnotatedTypeMirrorusingAnnotatedTypeMirror.createType(javax.lang.model.type.TypeMirror, org.checkerframework.framework.type.AnnotatedTypeFactory, boolean).- Parameters:
t- theTypeMirrordeclaration- true if the result should be marked as a type declaration- Returns:
- an
AnnotatedTypeMirrorthat hastas its underlying type
-
type
Determines an empty annotated type of the given tree. In other words, finds theTypeMirrorfor the tree and converts that into anAnnotatedTypeMirror, but does not add any annotations to the result.Most users will want to use
getAnnotatedType(Tree)instead; this method is mostly for internal use.- Parameters:
tree- the tree to analyze- Returns:
- the type of
tree, without any annotations
-
declarationFromElement
Gets the declaration tree for the element, if the source is available.TODO: would be nice to move this to InternalUtils/TreeUtils.
- Parameters:
elt- an element- Returns:
- the tree declaration of the element if found
-
isWithinConstructor
Returns true iftreeis within a constructor.- Parameters:
tree- the tree that might be within a constructor- Returns:
- true if
treeis within a constructor
-
setVisitorTreePath
Sets the path to the tree that an external "visitor" is visiting. The visitor is either a subclass ofBaseTypeVisitororCFAbstractTransfer.- Parameters:
visitorTreePath- path to the current tree that an external "visitor" is visiting
-
getVisitorTreePath
Returns the path to the tree that an external "visitor" is visiting. The type factory does not update this value as it computes the types of any tree or element needed compute the type of the tree being visited. Therefore this path may not be the path to the tree whose type is being computed. This method should not be used directly. UsegetPath(Tree)instead.This method is used to save the previous tree path and to give a hint to
getPath(Tree)on where to look for a tree rather than searching starting at the root.- Returns:
- the path to the tree that an external "visitor" is visiting
-
getPath
Gets the path for the givenTreeunder the current root by checking from the visitor's current path, and usingTrees.getPath(CompilationUnitTree, Tree)(which is much slower) only iftreeis not found on the current path.Note that the given Tree has to be within the current compilation unit, otherwise null will be returned.
Within a subclass of BaseTypeVisitor, use
getCurrentPath()rather than this method.- Parameters:
tree- theTreeto get the path for- Returns:
- the path for
treeunder the current root. Returns null iftreeis not within the current compilation unit.
-
setPathForArtificialTree
Set the tree path for the given artificial tree.See
org.checkerframework.framework.flow.CFCFGBuilder.CFCFGTranslationPhaseOne.handleArtificialTree(Tree). -
parseAnnotationFiles
protected void parseAnnotationFiles()Parses all annotation files in the following order:- Stub files, see
AnnotationFileElementTypes.parseStubFiles(); - Ajava files, see
AnnotationFileElementTypes.parseAjavaFiles().
If a type is annotated with a qualifier from the same hierarchy in more than one stub file, the qualifier in the last stub file is applied.
The annotations are stored by side-effecting
stubTypesandajavaTypes. - Stub files, see
-
isParsingAnnotationFile
public boolean isParsingAnnotationFile()Returns true if any annotation file (stub or ajava) is currently being parsed.While an annotation file is being parsed, calls into the type factory can return incomplete results, so caches that store such results must not be populated. This method centralizes the check that guards those caches.
- Returns:
- true if a stub or ajava file is currently being parsed
-
getDeclAnnotation
Returns all of the declaration annotations whose name equals the passed annotation class (or is an alias for it) including annotations:- on the element
- written in stubfiles
- inherited from overridden methods, (see
InheritedAnnotation) - inherited from superclasses or super interfaces (see
Inherited)
- Specified by:
getDeclAnnotationin interfaceAnnotationProvider- Parameters:
elt- the element to retrieve the declaration annotation fromannoClass- annotation class- Returns:
- the annotation mirror for annoClass
- See Also:
-
getDeclAnnotationNoAliases
public final @Nullable AnnotationMirror getDeclAnnotationNoAliases(Element elt, Class<? extends Annotation> annoClass) Returns the annotation mirror used to annotate this element, whose name equals the passed annotation class. Looks in the same places specified bygetDeclAnnotation(Element, Class). Returns null if none exists. Does not check for aliases of the annotation class.Call this method from a checker that needs to alias annotations for one purpose and not for another. For example, in the Lock Checker,
@LockingFreeand@ReleasesNoLocksare both aliases of@SideEffectFreesince they are all considered side-effect-free with regard to the set of locks held before and after the method call. However, asynchronizedblock is permitted inside a@ReleasesNoLocksmethod but not inside a@LockingFreeor@SideEffectFreemethod.- Parameters:
elt- the element to retrieve the declaration annotation fromannoClass- annotation class- Returns:
- the annotation mirror for annoClass
- See Also:
-
isFromStubFile
Returns true if the element appears in a stub file (Currently only works for methods, constructors, and fields). -
isFromByteCode
Returns true if the element is from bytecode -- that is, it is not being compiled -- and did not appear in a stub file."Not being compiled" is decided by where the element is declared (
ElementUtils.isElementFromSourceCode(javax.lang.model.element.Element)), not by whether a classfile happens to exist for it (ElementUtils.isElementFromByteCode(javax.lang.model.element.Element), which is true even when the element is also being compiled from source), and not by whether a tree happens to be available for it (declarationFromElement(javax.lang.model.element.Element), which returns null for a source element too: wheneverrootis unset, and for a member javac synthesizes and has no tree for, such as a record's canonical constructor and its accessors).- Parameters:
element- an element- Returns:
- true if the element is from bytecode and did not appear in a stub file
-
shouldWarnIfStubRedundantWithBytecode
public boolean shouldWarnIfStubRedundantWithBytecode()Returns true if redundancy between a stub file and bytecode should be reported.For most type systems the default behavior of returning true is correct. For subcheckers, redundancy in one of the type hierarchies can be ok. Such implementations should return false.
- Returns:
- true if to warn about redundancy between a stub file and bytecode
-
getDeclAnnotations
Returns all of the declaration annotations on this element including annotations:- on the element
- written in stubfiles
- inherited from overridden methods, (see
InheritedAnnotation) - inherited from superclasses or super interfaces (see
Inherited)
This method returns the actual annotations not their aliases.
getDeclAnnotation(Element, Class)returns aliases.- Parameters:
elt- the element for which to determine annotations- Returns:
- all of the declaration annotations on this element, written in stub files, or inherited
-
getDeclAnnotationWithMetaAnnotation
public List<Pair<AnnotationMirror,AnnotationMirror>> getDeclAnnotationWithMetaAnnotation(Element element, Class<? extends Annotation> metaAnnotationClass) Returns a list of all declaration annotations used to annotate the element, which have a meta-annotation (i.e., an annotation on that annotation) with classmetaAnnotationClass.- Parameters:
element- the element for which to determine annotationsmetaAnnotationClass- the class of the meta-annotation that needs to be present- Returns:
- a list of pairs
(anno, metaAnno)whereannois the annotation mirror atelement, andmetaAnnois the annotation mirror (of typemetaAnnotationClass) used to meta-annotate the declaration ofanno
-
getAnnotationWithMetaAnnotation
public List<Pair<AnnotationMirror,AnnotationMirror>> getAnnotationWithMetaAnnotation(Element element, Class<? extends Annotation> metaAnnotationClass) Returns a list of all annotations used to annotate this element, which have a meta-annotation (i.e., an annotation on that annotation) with classmetaAnnotationClass.- Parameters:
element- the element at which to look for annotationsmetaAnnotationClass- the class of the meta-annotation that needs to be present- Returns:
- a list of pairs
(anno, metaAnno)whereannois the annotation mirror atelement, andmetaAnnois the annotation mirror used to annotateanno.
-
hasQualifierParameterInHierarchy
public boolean hasQualifierParameterInHierarchy(AnnotatedTypeMirror annotatedTypeMirror, AnnotationMirror top) Returns true if theannotatedTypeMirrorhas a qualifier parameter.- Parameters:
annotatedTypeMirror- the type to checktop- the top of the hierarchy to check- Returns:
- true if the type has a qualifier parameter
-
hasQualifierParameterInHierarchy
Returns true if theelementhas a qualifier parameter.- Parameters:
element- element to checktop- the top of the hierarchy to check- Returns:
- true if the type has a qualifier parameter
-
hasExplicitQualifierParameterInHierarchy
Returns true if theHasQualifierParameterannotation was explicitly written onelementfor the hierarchy given bytop.- Parameters:
element- the Element to checktop- the top qualifier for the hierarchy to check- Returns:
- true if the class given by
elementhas been explicitly annotated withHasQualifierParameterfor the given hierarchy
-
hasExplicitNoQualifierParameterInHierarchy
Returns true if theNoQualifierParameterannotation was explicitly written onelementfor the hierarchy given bytop.- Parameters:
element- the Element to checktop- the top qualifier for the hierarchy to check- Returns:
- true if the class given by
elementhas been explicitly annotated withNoQualifierParameterfor the given hierarchy
-
getQualifierParameterHierarchies
Returns the set of top annotations representing all the hierarchies for which this type has a qualifier parameter.- Parameters:
annotatedType- the type to check- Returns:
- the set of top annotations representing all the hierarchies for which this type has a qualifier parameter
-
getQualifierParameterHierarchies
Returns the set of top annotations representing all the hierarchies for which this element has a qualifier parameter.- Parameters:
element- the Element to check- Returns:
- the set of top annotations representing all the hierarchies for which this element has a qualifier parameter
-
replaceAnnotations
Replaces or adds all annotations fromfromtoto. Annotations fromfromwill be used everywhere they exist, but annotations intowill be kept anywhere thatfromis unannotated.- Parameters:
from- the annotated type mirror from which to take new annotationsto- the annotated type mirror to which the annotations will be added
-
replaceAnnotations
public void replaceAnnotations(AnnotatedTypeMirror from, AnnotatedTypeMirror to, AnnotationMirror top) Replaces or adds annotations intop's hierarchy fromfromtoto. Annotations fromfromwill be used everywhere they exist, but annotations intowill be kept anywhere thatfromis unannotated.- Parameters:
from- the annotated type mirror from which to take new annotationsto- the annotated type mirror to which the annotations will be addedtop- the top type of the hierarchy whose annotations will be added
-
containsCapturedTypes
Returns true iftypecontains any captured type variables.- Parameters:
type- type to check- Returns:
- true if
typecontains any captured type variables
-
getFunctionTypeFromTree
public AnnotatedTypeMirror.AnnotatedExecutableType getFunctionTypeFromTree(MemberReferenceTree tree) Returns the function type that this member reference targets.The function type is the type of the single method declared in the functional interface adapted as if it were invoked using the functional interface as the receiver expression.
The target type of a member reference is the type to which it is assigned or casted.
- Parameters:
tree- member reference tree- Returns:
- the function type that this method reference targets
-
getFunctionTypeFromTree
public AnnotatedTypeMirror.AnnotatedExecutableType getFunctionTypeFromTree(LambdaExpressionTree tree) Returns the function type that this lambda targets.The function type is the type of the single method declared in the functional interface adapted as if it were invoked using the functional interface as the receiver expression.
The target type of a lambda is the type to which it is assigned or casted.
- Parameters:
tree- lambda expression tree- Returns:
- the function type that this lambda targets
-
getFnInterfaceFromTree
public Pair<AnnotatedTypeMirror,AnnotatedTypeMirror.AnnotatedExecutableType> getFnInterfaceFromTree(Tree tree) Returns the functional interface and the function type that this lambda or member references targets.The function type is the type of the single method declared in the functional interface adapted as if it were invoked using the functional interface as the receiver expression.
The target type of a lambda or a method reference is the type to which it is assigned or casted.
- Parameters:
tree- lambda expression tree or member reference tree- Returns:
- the functional interface and the function type that this method reference or lambda targets
-
applyCaptureConversion
Apply capture conversion totypeToCapture.Capture conversion is the process of converting wildcards in a parameterized type to fresh type variables. See JLS 5.1.10 for details.
If
typeis not a declared type or if it does not have any wildcard type arguments, this method returnstype.- Parameters:
typeToCapture- type to capture- Returns:
- the result of applying capture conversion to
typeToCapture
-
applyCaptureConversion
Apply capture conversion totype.Capture conversion is the process of converting wildcards in a parameterized type to fresh type variables. See JLS 5.1.10 for details.
If
typeis not a declared type or if it does not have any wildcard type arguments, this method returnstype.- Parameters:
type- type to capturetypeMirror- the result of applying capture conversion to the underlying type oftype; it is used as the underlying type of the returned type- Returns:
- the result of applying capture conversion to
type
-
order
public List<AnnotatedTypeMirror.AnnotatedTypeVariable> order(Collection<AnnotatedTypeMirror.AnnotatedTypeVariable> collection) Returns the list of type variables such that a type variable in the list only references type variables at a lower index than itself.- Parameters:
collection- a collection of type variables- Returns:
- the type variables ordered so that each type variable only references earlier type variables
-
getElementUtils
Returns the utility class for working withElements.- Returns:
- the utility class for working with
Elements
-
getTreeUtils
Accessor for the tree utilities. -
getProcessingEnv
Accessor for the processing environment.- Returns:
- the processing environment
-
getExpressionAndOffset
Given an expression, split it into a subexpression and a constant offset. For example:
There are methods that can only take as input an expression that represents a JavaExpression. The purpose of this is to pre-process expressions to make those methods more likely to succeed."a" => <"a", "0"> "a + 5" => <"a", "5"> "a + -5" => <"a", "-5"> "a - 5" => <"a", "-5">- Parameters:
expression- an expression to remove a constant offset from- Returns:
- a sub-expression and a constant offset. The offset is "0" if this routine is unable to splite the given expression
-
negateConstant
Given an expression string, returns its negation.- Parameters:
constantExpression- a string representing an integer constant- Returns:
- the negation of constantExpression
-
getDummyAssignedTo
Returnsnullor an annotated type mirror that type argument inference should assumeexpressionTreeis assigned to.If
nullis returned, inference proceeds normally.If a type is returned, then inference assumes that
expressionTreewas asigned to it. This biases the inference algorithm toward the annotations in the returned type. In particular, if the annotations on type variables in invariant positions are a super type of the annotations inferred, the super type annotations are chosen.This implementation returns null, but subclasses may override this method to return a type.
- Parameters:
expressionTree- an expression which has no assignment context and for which type arguments need to be inferred- Returns:
nullor an annotated type mirror that inferrence should pretendexpressionTreeis assigned to
-
areSameByClass
Checks that the annotationamhas the name ofannoClass. Values are ignored.In the end, all annotation comparisons are by name. This method is faster than
AnnotationUtils.areSameByClass(AnnotationMirror, Class)because it caches the name ofannoClassrather than computing it on each invocation of this method.- Parameters:
am- the AnnotationMirror whose class to compareannoClass- the class to compare- Returns:
- true if annoclass is the class of am
-
containsSameByClass
public boolean containsSameByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> annoClass) Checks that the collection contains the annotation. UsingCollection.containsdoes not always work, because it does not useAnnotationUtils.areSame(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)for comparison.In the end, all annotation comparisons are by name. This method is faster than
AnnotationUtils.containsSameByClass(Collection, Class)because it (actually, its callee) caches the name ofannoClassrather than computing it each time.- Parameters:
c- a collection of AnnotationMirrorsannoClass- the annotation class to search for in c- Returns:
- true iff c contains an annotation of class annoClass, according to
areSameByClass(javax.lang.model.element.AnnotationMirror, java.lang.Class<? extends java.lang.annotation.Annotation>)
-
getAnnotationByClass
public @Nullable AnnotationMirror getAnnotationByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> annoClass) Returns the AnnotationMirror incthat has classannoClass.This method is faster than
AnnotationUtils.getAnnotationByClass(Collection, Class)because it (actually, its callee) caches the name of the class rather than computing it each time.- Parameters:
c- a collection of AnnotationMirrorsannoClass- the class to search for in c- Returns:
- an AnnotationMirror with class
annoClassiff c contains one, according to areSameByClass; otherwise,null
-
getAnnotatedForAnnotations
Returns everyAnnotatedForannotation onelt: each one written on it (there may be more than one, since@AnnotatedForis@Repeatable), together with one for each of its declaration annotations that is an alias forAnnotatedFor.See
getAllDeclAnnotations(javax.lang.model.element.Element, java.lang.String, java.lang.String, javax.lang.model.element.ExecutableElement), which does the work, for why a plaingetDeclAnnotation(javax.lang.model.element.Element, java.lang.Class<? extends java.lang.annotation.Annotation>)call does not suffice.- Parameters:
elt- an element- Returns:
- an unmodifiable set of the
AnnotatedForannotations onelt; may be empty
-
getUnannotatedForAnnotations
Returns everyUnannotatedForannotation onelt: each one written on it (there may be more than one, since@UnannotatedForis@Repeatable), together with one for each of its declaration annotations that is an alias forUnannotatedFor.The
@UnannotatedForcounterpart ofgetAnnotatedForAnnotations(javax.lang.model.element.Element).- Parameters:
elt- an element- Returns:
- an unmodifiable set of the
UnannotatedForannotations onelt; may be empty
-
getDefaultQualifierAnnotations
Returns everyDefaultQualifierannotation that applies toelt's own declaration, in source order: each one written on it (there may be more than one, since@DefaultQualifieris@Repeatable), plus one for each of its declaration annotations that is an alias for@DefaultQualifieror for@DefaultQualifier.List.Order is significant, unlike for
getAnnotatedForAnnotations(javax.lang.model.element.Element): two@DefaultQualifierannotations can set the sameTypeUseLocationin the same qualifier hierarchy to different qualifiers, and only one of them can win.QualifierDefaults, the only caller, keeps the first and reports the rest as conflicts, so this returns an orderedListrather than anAnnotationMirrorSet.The order is that of
getDeclAnnotations(javax.lang.model.element.Element), which forelt's own annotations is the source order thatjavacreports. Three consequences:- An aliasing annotation contributes its target
@DefaultQualifierat the aliasing annotation's own position. For example,@NullMarkedaliases to@DefaultQualifier(NonNull.class, locations = UPPER_BOUND), so writing@NullMarkedbefore or after a@DefaultQualifierdecides which of the two wins. - Two or more written
@DefaultQualifiers are reported by javac as a single@DefaultQualifier.Listpositioned where the first of them was written, and itsvalue()array is in source order; this expands that container in place, so the result is still in source order. - Annotations contributed by a stub or ajava file, and annotations inherited from a
supertype or an overridden method, are appended by
getDeclAnnotations(javax.lang.model.element.Element)afterelt's own, so they come last here and lose a conflict against an annotation written oneltitself. (Neither@DefaultQualifiernor@DefaultQualifier.Listis@Inherited, so today only a stub or ajava file can reach this case;@Inheritedannotations are the one kind thatElements.getAllAnnotationMirrorsplaces before the element's own, which would invert this precedence.)
- Parameters:
elt- an element- Returns:
- an unmodifiable list, in source order, of the
@DefaultQualifierannotations that apply toelt's own declaration; may be empty
- An aliasing annotation contributes its target
-
doesAnnotatedForApplyToSubpackages
DoesannotatedForAnno, which is anAnnotatedForannotation written on a package, also apply to subpackages of that package?- Parameters:
annotatedForAnno- anAnnotatedForannotation written on a package- Returns:
- whether
annotatedForAnnoapplies to subpackages
-
doesUnannotatedForApplyToSubpackages
DoesunannotatedForAnno, which is anUnannotatedForannotation written on a package, also apply to subpackages of that package?- Parameters:
unannotatedForAnno- anUnannotatedForannotation written on a package- Returns:
- whether
unannotatedForAnnoapplies to subpackages
-
doesAnnotatedForApplyToThisChecker
DoesannotatedForAnno, which is anAnnotatedForannotation, apply to this checker?- Parameters:
annotatedForAnno- anAnnotatedForannotation- Returns:
- true if
annotatedForAnnoapplies to this checker
-
doesUnannotatedForApplyToThisChecker
DoesunannotatedForAnno, which is anUnannotatedForannotation, apply to this checker?- Parameters:
unannotatedForAnno- anUnannotatedForannotation- Returns:
- whether
unannotatedForAnnoapplies to this checker
-
annotatedForPrecedesUnannotatedFor
Returns true if the@AnnotatedForthat applies to this checker oneltis written before the@UnannotatedForthat also applies to it.Call this only for an element that carries both; it decides which one wins. The two contradict each other, and resolving that by source order is what
@DefaultQualifierdoes for the same situation, which matters because one annotation can supply both kinds at once: JSpecify's@NullUnmarkedaliases to an@UnannotatedForand to a@DefaultQualifier. Were the two halves resolved by different rules, writing@NullUnmarked @NullMarkedwould leave the declaration in scope for checking while its upper-bound default came from the annotation that lost, a state neither annotation produces on its own.The order is that of
getDeclAnnotations(javax.lang.model.element.Element), which forelt's own annotations is the source order thatjavacreports; an aliasing annotation contributes at its own position, and a@Repeatablecontainer at the position of the first repeat.- Parameters:
elt- an element carrying an applicable@AnnotatedForand an applicable@UnannotatedFor- Returns:
- true if the
@AnnotatedForcomes first
-
getContractExpressions
Returns theexpressionfield/element of the given contract annotation.- Parameters:
contractAnno- aRequiresQualifier,EnsuresQualifier, orEnsuresQualifier- Returns:
- the
expressionfield/element of the given annotation
-
getContractListValues
Returns thevaluefield/element of the given contract list annotation.- Parameters:
contractListAnno- aRequiresQualifier.List,EnsuresQualifier.List, orEnsuresQualifierIf.List- Returns:
- the
valuefield/element of the given annotation
-
isImmutable
Returns true if the type is immutable. Subclasses can override this method to add types that are mutable, but the annotated type of an object is immutable.- Parameters:
type- type to test- Returns:
- true if the type is immutable
-
isSideEffectFree
Description copied from interface:AnnotationProviderReturns true if the given method is side-effect-free according to this AnnotationProvider — that is, if a call to the given method does not undo flow-sensitive type refinement.Note that this method takes account of this AnnotationProvider's semantics, whereas
org.checkerframework.dataflow.util.PurityUtils#isSideEffectFreedoes not.- Specified by:
isSideEffectFreein interfaceAnnotationProvider- Parameters:
methodElement- a method- Returns:
- true if a call to the method does not undo flow-sensitive type refinement
-
isDeterministic
Description copied from interface:AnnotationProviderReturns true if the given method is deterministic according to this AnnotationProvider — that is, if multiple calls to the given method (with the same arguments) return the same value.Note that this method takes account of this AnnotationProvider's semantics, whereas
org.checkerframework.dataflow.util.PurityUtils#isDeterministicdoes not.- Specified by:
isDeterministicin interfaceAnnotationProvider- Parameters:
methodElement- a method- Returns:
- true if multiple calls to the method (with the same arguments) return the same value
-