Class KeyForPropagator


  • public class KeyForPropagator
    extends java.lang.Object
    KeyForPropagator is used to move nested KeyFor annotations in type arguments from one side of a pseudo-assignment to the other. The KeyForPropagationTreeAnnotator details the locations in which this occurs.
    See Also:
    KeyForPropagationTreeAnnotator
    • Constructor Detail

      • KeyForPropagator

        public KeyForPropagator​(javax.lang.model.element.AnnotationMirror unknownKeyfor)
        Creates a KeyForPropagator
        Parameters:
        unknownKeyfor - an UnknownKeyFor annotation
    • Method Detail

      • propagate

        public void propagate​(AnnotatedTypeMirror.AnnotatedDeclaredType subtype,
                              AnnotatedTypeMirror.AnnotatedDeclaredType supertype,
                              KeyForPropagator.PropagationDirection direction,
                              AnnotatedTypeFactory typeFactory)
        Propagate annotations from the type arguments of one type to another. Which type is the source and destination of the annotations depends on the direction parameter. Only @KeyFor annotations are propagated and only if the type to which it would be propagated contains an @UnknownKeyFor or contains no key for annotations of any kind. If any of the type arguments are wildcards than they are ignored.

        Note the primary annotations of subtype/supertype are not used.

        Simple Example:

        
         typeOf(subtype) = ArrayList<@KeyFor("a") String>
         typeOf(supertype) = List<@UnknownKeyFor String>
         direction = TO_SUPERTYPE
         
        The type of supertype after propagate would be: List<@KeyFor("a") String>

        A more complex example would be:

        
         typeOf(subtype) = HashMap<@UnknownKeyFor String, @KeyFor("b") List<@KeyFor("c") String>>
         typeOf(supertype) = Map<@KeyFor("a") String, @KeyFor("b") List<@KeyFor("c") String>>
         direction = TO_SUBTYPE
         
        The type of subtype after propagate would be: HashMap<@KeyFor("a") String, @KeyFor("b") List<@KeyFor("c") String>>
      • propagateNewClassTree

        public void propagateNewClassTree​(com.sun.source.tree.NewClassTree newClassTree,
                                          AnnotatedTypeMirror type,
                                          KeyForAnnotatedTypeFactory atypeFactory)
        Propagate annotations from the type arguments of type to the assignment context of newClassTree if one exists.
        Parameters:
        newClassTree - new class tree
        type - annotated type of newClassTree
        atypeFactory - factory