Class TypeDeclarationApplier


  • public class TypeDeclarationApplier
    extends java.lang.Object
    Apply annotations to a declared type based on its declaration.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.lang.model.element.Element element
      An Element that type represents.
      static int SUPERCLASS_INDEX
      If a type_index == -1 it means that the index refers to the immediate supertype class of the declaration.
      protected AnnotatedTypeMirror type
      The type to which we wish to apply annotations.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean accepts​(AnnotatedTypeMirror type, javax.lang.model.element.Element element)
      Returns true if type is an annotated declared type and element is a ClassSymbol.
      protected com.sun.tools.javac.code.TargetType[] annotatedTargets()
      Returns the TargetTypes that identify annotations we wish to apply with this object.
      static void apply​(AnnotatedTypeMirror type, javax.lang.model.element.Element element, AnnotatedTypeFactory atypeFactory)  
      void extractAndApply()
      Adds extends/implements and class annotations to type.
      protected java.lang.Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> getRawTypeAttributes()
      All TypeCompounds (annotations) on the ClassSymbol.
      protected void handleInvalid​(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid)
      This implementation reports all invalid annotations as errors.
      protected void handleTargeted​(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> extendsAndImplementsAnnos)
      While more than just annotations on extends or implements clause are annotated by this class, only these annotations are passed to handleTargeted (as they are the only in the annotatedTargets list).
      protected void handleValid​(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> valid)
      The default implementation of this method does nothing.
      protected boolean isAccepted()
      Tests element/type fields to ensure that this TargetedElementAnnotationApplier is valid for this element/type pair.
      protected java.util.Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,​java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound>> sift​(java.lang.Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> typeCompounds)
      Separate the input annotations into a Map of TargetClass (TARGETED, VALID, INVALID) to the annotations that fall into each of those categories.
      protected com.sun.tools.javac.code.TargetType[] validTargets()
      Returns the TargetTypes that identify annotations that are valid but we wish to ignore.
      • Methods inherited from class java.lang.Object

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

      • SUPERCLASS_INDEX

        public static final int SUPERCLASS_INDEX
        If a type_index == -1 it means that the index refers to the immediate supertype class of the declaration. There is only ever one of these since Java has no multiple inheritance
        See Also:
        Constant Field Values
      • type

        protected final AnnotatedTypeMirror type
        The type to which we wish to apply annotations.
      • element

        protected final javax.lang.model.element.Element element
        An Element that type represents.
    • Method Detail

      • accepts

        public static boolean accepts​(AnnotatedTypeMirror type,
                                      javax.lang.model.element.Element element)
        Returns true if type is an annotated declared type and element is a ClassSymbol.
        Parameters:
        type - a type
        element - an element
        Returns:
        true if type is an annotated declared type and element is a ClassSymbol
      • annotatedTargets

        protected com.sun.tools.javac.code.TargetType[] annotatedTargets()
        Returns the TargetTypes that identify annotations we wish to apply with this object. Any annotations that have these target types will be passed to handleTargeted.
        Returns:
        the TargetTypes that identify annotations we wish to apply with this object. Any annotations that have these target types will be passed to handleTargeted
      • validTargets

        protected com.sun.tools.javac.code.TargetType[] validTargets()
        Returns the TargetTypes that identify annotations that are valid but we wish to ignore. Any annotations that have these target types will be passed to handleValid, providing they aren't also in annotatedTargets.
        Returns:
        the TargetTypes that identify annotations that are valid but we wish to ignore
      • getRawTypeAttributes

        protected java.lang.Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> getRawTypeAttributes()
        All TypeCompounds (annotations) on the ClassSymbol.
        Returns:
        the annotations that we MAY wish to apply to the given type
      • handleTargeted

        protected void handleTargeted​(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> extendsAndImplementsAnnos)
                               throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
        While more than just annotations on extends or implements clause are annotated by this class, only these annotations are passed to handleTargeted (as they are the only in the annotatedTargets list). See extractAndApply for type parameters
        Parameters:
        extendsAndImplementsAnnos - annotations with a TargetType of CLASS_EXTENDS
        Throws:
        ElementAnnotationUtil.UnexpectedAnnotationLocationException
      • isAccepted

        protected boolean isAccepted()
        Tests element/type fields to ensure that this TargetedElementAnnotationApplier is valid for this element/type pair.
        Returns:
        true if the type/element members are handled by this class false otherwise
      • handleValid

        protected void handleValid​(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> valid)
        The default implementation of this method does nothing.
        Parameters:
        valid - the list of annotations that were returned by getRawTypeAttributes and had a TargetType contained by valid and NOT annotatedTargets
      • handleInvalid

        protected void handleInvalid​(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid)
        This implementation reports all invalid annotations as errors.
        Parameters:
        invalid - the list of annotations that were returned by getRawTypeAttributes and were not handled by handleTargeted or handleValid
      • sift

        protected java.util.Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,​java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound>> sift​(java.lang.Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> typeCompounds)
        Separate the input annotations into a Map of TargetClass (TARGETED, VALID, INVALID) to the annotations that fall into each of those categories.
        Parameters:
        typeCompounds - annotations to sift through, should be those returned by getRawTypeAttributes
        Returns:
        a Map<TargetClass => Annotations>.