Class InitializationParentAnnotatedTypeFactory

    • Field Detail

      • UNKNOWN_INITIALIZATION

        protected final javax.lang.model.element.AnnotationMirror UNKNOWN_INITIALIZATION
      • INITIALIZED

        protected final javax.lang.model.element.AnnotationMirror INITIALIZED
      • UNDER_INITALIZATION

        protected final javax.lang.model.element.AnnotationMirror UNDER_INITALIZATION
      • NOT_ONLY_INITIALIZED

        protected final javax.lang.model.element.AnnotationMirror NOT_ONLY_INITIALIZED
      • POLY_INITIALIZED

        protected final javax.lang.model.element.AnnotationMirror POLY_INITIALIZED
      • FBCBOTTOM

        protected final javax.lang.model.element.AnnotationMirror FBCBOTTOM
      • objectTypeMirror

        protected final javax.lang.model.type.TypeMirror objectTypeMirror
        The java.lang.Object type.
      • unusedWhenElement

        protected final javax.lang.model.element.ExecutableElement unusedWhenElement
        The Unused.when field/element.
      • underInitializationValueElement

        protected final javax.lang.model.element.ExecutableElement underInitializationValueElement
        The UnderInitialization.value field/element.
      • unknownInitializationValueElement

        protected final javax.lang.model.element.ExecutableElement unknownInitializationValueElement
        The UnknownInitialization.value field/element.
    • Constructor Detail

      • InitializationParentAnnotatedTypeFactory

        public InitializationParentAnnotatedTypeFactory​(BaseTypeChecker checker)
        Create a new InitializationParentAnnotatedTypeFactory.

        Don't forget to call GenericAnnotatedTypeFactory.postInit() in the concrete subclass.

        Parameters:
        checker - the checker to which the new type factory belongs
    • Method Detail

      • createSupportedTypeQualifiers

        protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> createSupportedTypeQualifiers()
        Description copied from class: AnnotatedTypeFactory
        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 AnnotatedTypeFactory.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 of ElementType.TYPE_PARAMETER, but no other ElementType values) are automatically considered as supported annotations.

        To support a different set of annotations than those in the qual subdirectory, or that have other ElementType values, see examples below.

        In total, there are 5 ways to indicate annotations that are supported by a checker:

        1. Only support annotations located in a checker's qual directory:

          This is the default behavior. Simply place those annotations within the qual directory.

        2. Support annotations located in a checker's qual directory and a list of other annotations:

          Place those annotations within the qual directory, and override AnnotatedTypeFactory.createSupportedTypeQualifiers() by calling AnnotatedTypeFactory.getBundledTypeQualifiers(Class...) with a varargs parameter list of the other annotations. Code example:

           @Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
                return getBundledTypeQualifiers(Regex.class, PartialRegex.class, RegexBottom.class, UnknownRegex.class);
            } 
           
        3. Supporting only annotations that are explicitly listed: Override AnnotatedTypeFactory.createSupportedTypeQualifiers() and return a mutable set of the supported annotations. Code example:
           @Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
                return new HashSet<Class<? extends Annotation>>(
                        Arrays.asList(A.class, B.class));
            } 
           
          The set of qualifiers returned by AnnotatedTypeFactory.createSupportedTypeQualifiers() must be a fresh, mutable set. The methods AnnotatedTypeFactory.getBundledTypeQualifiers(Class...) must return a fresh, mutable set
        Overrides:
        createSupportedTypeQualifiers in class AnnotatedTypeFactory
        Returns:
        the type qualifiers supported this processor, or an empty set if none
      • isImmutable

        public boolean isImmutable​(javax.lang.model.type.TypeMirror type)
        Returns true. Initialization cannot be undone, i.e., an @Initialized object always stays @Initialized, an @UnderInitialization(A) object always stays @UnderInitialization(A) (though it may additionally become @Initialized), etc.
        Overrides:
        isImmutable in class AnnotatedTypeFactory
        Parameters:
        type - type to test
        Returns:
        true if the type is immutable
      • createUnderInitializationAnnotation

        public javax.lang.model.element.AnnotationMirror createUnderInitializationAnnotation​(javax.lang.model.type.TypeMirror typeFrame)
        Creates a UnderInitialization annotation with the given type as its type frame argument.
        Parameters:
        typeFrame - the type down to which some value has been initialized
        Returns:
        an UnderInitialization annotation with the given argument
      • getSelfType

        public @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType​(com.sun.source.tree.Tree tree)
        Description copied from class: AnnotatedTypeFactory
        Returns the type of this at the location of tree. Returns null if tree is in a location where this has 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.

        Overrides:
        getSelfType in class AnnotatedTypeFactory
        Parameters:
        tree - location used to decide the type of this
        Returns:
        the type of this at the location of tree
      • setSelfTypeInInitializationCode

        protected void setSelfTypeInInitializationCode​(com.sun.source.tree.Tree tree,
                                                       AnnotatedTypeMirror.AnnotatedDeclaredType selfType,
                                                       com.sun.source.util.TreePath path)
        Side-effects argument selfType to make it @Initialized or @UnderInitialization, depending on whether all fields have been set.
        Parameters:
        tree - a tree
        selfType - the type to side-effect
        path - a path
      • getUnderInitializationAnnotationOfSuperType

        protected javax.lang.model.element.AnnotationMirror getUnderInitializationAnnotationOfSuperType​(javax.lang.model.type.TypeMirror type)
        Returns an UnderInitialization annotation that has the superclass of type as type frame.
        Parameters:
        type - a type
        Returns:
        true an UnderInitialization for the supertype of type
      • isUnused

        protected boolean isUnused​(com.sun.source.tree.VariableTree field,
                                   java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> receiverAnnos)
        Returns whether the specified field is unused, given the specified annotations on the receiver.
        Parameters:
        field - the field to check
        receiverAnnos - the annotations on the receiver
        Returns:
        whether field is unused given receiverAnnos
      • createUnderInitializationAnnotation

        public javax.lang.model.element.AnnotationMirror createUnderInitializationAnnotation​(java.lang.Class<?> typeFrame)
        Creates a UnderInitialization annotation with the given type frame.
        Parameters:
        typeFrame - the type down to which some value has been initialized
        Returns:
        an UnderInitialization annotation with the given argument
      • areAllFieldsInitializedOnly

        protected boolean areAllFieldsInitializedOnly​(com.sun.source.tree.ClassTree classTree)
        Are all fields initialized-only?
        Parameters:
        classTree - the class to query
        Returns:
        true if all fields are initialized-only
      • getUninitializedFields

        public java.util.List<com.sun.source.tree.VariableTree> getUninitializedFields​(InitializationStore store,
                                                                                       com.sun.source.util.TreePath path,
                                                                                       boolean isStatic,
                                                                                       java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> receiverAnnotations)
        Returns the fields that are not yet initialized in a given store.
        Parameters:
        store - a store
        path - the current path, used to determine the current class
        isStatic - whether to report static fields or instance fields
        receiverAnnotations - the annotations on the receiver
        Returns:
        the fields that are not yet initialized in a given store
      • getInitializedFields

        public java.util.List<com.sun.source.tree.VariableTree> getInitializedFields​(InitializationStore store,
                                                                                     com.sun.source.util.TreePath path)
        Returns the fields that are initialized in the given store.
        Parameters:
        store - a store
        path - the current path; used to compute the current class
        Returns:
        the fields that are initialized in the given store
      • createUnknownInitializationAnnotation

        public javax.lang.model.element.AnnotationMirror createUnknownInitializationAnnotation​(java.lang.Class<?> typeFrame)
        Creates a UnknownInitialization annotation with a given type frame.
        Parameters:
        typeFrame - the type down to which some value has been initialized
        Returns:
        an UnknownInitialization annotation with the given argument
      • createUnknownInitializationAnnotation

        public javax.lang.model.element.AnnotationMirror createUnknownInitializationAnnotation​(javax.lang.model.type.TypeMirror typeFrame)
        Creates an UnknownInitialization annotation with a given type frame.
        Parameters:
        typeFrame - the type down to which some value has been initialized
        Returns:
        an UnknownInitialization annotation with the given argument
      • isUnderInitialization

        public boolean isUnderInitialization​(javax.lang.model.element.AnnotationMirror anno)
        Is anno the UnderInitialization annotation (with any type frame)?
        Parameters:
        anno - the annotation to check
        Returns:
        true if anno is UnderInitialization
      • isUnknownInitialization

        public boolean isUnknownInitialization​(javax.lang.model.element.AnnotationMirror anno)
        Is anno the UnknownInitialization annotation (with any type frame)?
        Parameters:
        anno - the annotation to check
        Returns:
        true if anno is UnknownInitialization
      • isFbcBottom

        public boolean isFbcBottom​(javax.lang.model.element.AnnotationMirror anno)
        Is anno the bottom annotation?
        Parameters:
        anno - the annotation to check
        Returns:
        true if anno is FBCBottom
      • isInitialized

        public boolean isInitialized​(javax.lang.model.element.AnnotationMirror anno)
        Is anno the Initialized annotation?
        Parameters:
        anno - the annotation to check
        Returns:
        true if anno is Initialized
      • isFbcBottom

        public boolean isFbcBottom​(AnnotatedTypeMirror anno)
        Does anno have the bottom annotation?
        Parameters:
        anno - the annotation to check
        Returns:
        true if anno has FBCBottom
      • isInitializedForFrame

        public boolean isInitializedForFrame​(AnnotatedTypeMirror type,
                                             javax.lang.model.type.TypeMirror frame)
        Return true if the type is initialized with respect to the given frame -- that is, all of the fields of the frame are initialized.
        Parameters:
        type - the type whose initialization type qualifiers to check
        frame - a class in type's class hierarchy
        Returns:
        true if the type is initialized for the given frame
      • getTypeFrameFromAnnotation

        public javax.lang.model.type.TypeMirror getTypeFrameFromAnnotation​(javax.lang.model.element.AnnotationMirror annotation)
        Returns the type frame (that is, the argument) of a given initialization annotation.
        Parameters:
        annotation - a UnderInitialization or UnknownInitialization annotation
        Returns:
        the annotation's argument
      • shouldWarnIfStubRedundantWithBytecode

        public boolean shouldWarnIfStubRedundantWithBytecode()
        Returns false. Redundancy in only the initialization hierarchy is ok and may even be caused by implicit default annotations. The parent checker should determine whether to warn about redundancy.
        Overrides:
        shouldWarnIfStubRedundantWithBytecode in class AnnotatedTypeFactory
        Returns:
        whether to warn about redundancy between a stub file and bytecode