Class AnnotationFileElementTypes


  • public class AnnotationFileElementTypes
    extends java.lang.Object
    Holds information about types parsed from annotation files (stub files or ajava files). When using an ajava file, only holds information on public elements as with stub files.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @Nullable AnnotatedTypeMirror getAnnotatedTypeMirror​(javax.lang.model.element.Element e)
      Returns the annotated type for e containing only annotations explicitly written in an annotation file.
      @Nullable AnnotationMirrorSet getDeclAnnotations​(javax.lang.model.element.Element elt)
      Returns the set of declaration annotations for e containing only annotations explicitly written in an annotation file or the empty set if e does not appear in an annotation file.
      @Nullable AnnotatedTypeMirror.AnnotatedExecutableType getFakeOverride​(javax.lang.model.element.Element elt, AnnotatedTypeMirror receiverType)
      Returns the method type of the most specific fake override for the given element, when used as a member of the given type.
      void injectRecordComponentType​(javax.lang.model.util.Types types, javax.lang.model.element.Element elt, AnnotatedTypeMirror.AnnotatedExecutableType memberType)
      Adds annotations from stub files for the corresponding record components (if the given constructor/method is the canonical constructor or a record accessor).
      boolean isParsing()
      Returns true if files are currently being parsed; otherwise, false.
      void parseAjavaFiles()
      Parses the ajava files passed through the -Aajava command-line option.
      void parseAjavaFileWithTree​(java.lang.String ajavaPath, com.sun.source.tree.CompilationUnitTree root)
      Parses the ajava file at ajavaPath assuming root represents the compilation unit of that file.
      void parseStubFiles()
      Parses the stub files in the following order: jdk.astub in this directory, if it exists and ignorejdkastub option is not supplied jdk.astub in the same directory as the checker, if it exists and ignorejdkastub option is not supplied If parsing annotated JDK as stub files, all package-info.java files under the jdk/ directory Stub files listed in @StubFiles annotation on the checker; must be in same directory as the checker Stub files returned by BaseTypeChecker.getExtraStubFiles() (treated like those listed in @StubFiles annotation) Stub files provided via -Astubs compiler option
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AnnotationFileElementTypes

        public AnnotationFileElementTypes​(AnnotatedTypeFactory atypeFactory)
        Creates an empty annotation source.
        Parameters:
        atypeFactory - a type factory
    • Method Detail

      • isParsing

        public boolean isParsing()
        Returns true if files are currently being parsed; otherwise, false.
        Returns:
        true if files are currently being parsed; otherwise, false
      • parseStubFiles

        public void parseStubFiles()
        Parses the stub files in the following order:
        1. jdk.astub in this directory, if it exists and ignorejdkastub option is not supplied
        2. jdk.astub in the same directory as the checker, if it exists and ignorejdkastub option is not supplied
        3. If parsing annotated JDK as stub files, all package-info.java files under the jdk/ directory
        4. Stub files listed in @StubFiles annotation on the checker; must be in same directory as the checker
        5. Stub files returned by BaseTypeChecker.getExtraStubFiles() (treated like those listed in @StubFiles annotation)
        6. Stub files provided via -Astubs compiler option

        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.

        If using JDK 11, then the JDK stub files are only parsed if a type or declaration annotation is requested from a class in that file.

      • parseAjavaFiles

        public void parseAjavaFiles()
        Parses the ajava files passed through the -Aajava command-line option.
      • parseAjavaFileWithTree

        public void parseAjavaFileWithTree​(java.lang.String ajavaPath,
                                           com.sun.source.tree.CompilationUnitTree root)
        Parses the ajava file at ajavaPath assuming root represents the compilation unit of that file. Uses root to get information from javac on specific elements of ajavaPath, enabling storage of more detailed annotation information than with just the ajava file.
        Parameters:
        ajavaPath - path to an ajava file
        root - javac tree for the compilation unit stored in ajavaFile
      • getAnnotatedTypeMirror

        public @Nullable AnnotatedTypeMirror getAnnotatedTypeMirror​(javax.lang.model.element.Element e)
        Returns the annotated type for e containing only annotations explicitly written in an annotation file. Returns null if e does not appear in an annotation file.
        Parameters:
        e - an Element whose type is returned
        Returns:
        an AnnotatedTypeMirror for e containing only annotations explicitly written in the annotation file and in the element. Returns null if element does not appear in an annotation file.
      • getDeclAnnotations

        public @Nullable AnnotationMirrorSet getDeclAnnotations​(javax.lang.model.element.Element elt)
        Returns the set of declaration annotations for e containing only annotations explicitly written in an annotation file or the empty set if e does not appear in an annotation file.
        Parameters:
        elt - element for which annotations are returned
        Returns:
        an AnnotatedTypeMirror for e containing only annotations explicitly written in the annotation file and in the element. null is returned if element does not appear in an annotation file.
      • injectRecordComponentType

        public void injectRecordComponentType​(javax.lang.model.util.Types types,
                                              javax.lang.model.element.Element elt,
                                              AnnotatedTypeMirror.AnnotatedExecutableType memberType)
        Adds annotations from stub files for the corresponding record components (if the given constructor/method is the canonical constructor or a record accessor). Such transfer is automatically done by javac usually, but not from stubs.
        Parameters:
        types - a Types instance used for checking type equivalence
        elt - a member. This method does nothing if it's not a method or constructor.
        memberType - the type corresponding to the element elt; side-effected by this method
      • getFakeOverride

        public @Nullable AnnotatedTypeMirror.AnnotatedExecutableType getFakeOverride​(javax.lang.model.element.Element elt,
                                                                                     AnnotatedTypeMirror receiverType)
        Returns the method type of the most specific fake override for the given element, when used as a member of the given type.
        Parameters:
        elt - element for which annotations are returned
        receiverType - the type of the class that contains member (or a subtype of it)
        Returns:
        the most specific AnnotatedTypeMirror for elt that is a fake override, or null if there are no fake overrides