Class AbstractViewpointAdapter

  • All Implemented Interfaces:
    ViewpointAdapter

    public abstract class AbstractViewpointAdapter
    extends java.lang.Object
    implements ViewpointAdapter
    Abstract utility class for performing viewpoint adaptation.

    This class contains the common logic for extracting and inserting viewpoint adapted annotations into the corresponding types for member/field access, constructor and method invocations, and type parameter bound instantiations.

    Subclasses implement the computation of the precise viewpoint adapted type given a receiver type and a declared type, and implement how to extract the qualifier given an ATM.

    • Constructor Detail

      • AbstractViewpointAdapter

        protected AbstractViewpointAdapter​(AnnotatedTypeFactory atypeFactory)
        Construct an abstract viewpoint adapter with the given type factory.
        Parameters:
        atypeFactory - the type factory to use
    • Method Detail

      • viewpointAdaptMember

        public void viewpointAdaptMember​(AnnotatedTypeMirror receiverType,
                                         javax.lang.model.element.Element memberElement,
                                         AnnotatedTypeMirror memberType)
        Description copied from interface: ViewpointAdapter
        Viewpoint adapts a member/field access.

        Developer notes: When this method is invoked on a member/field with a type given by a type parameter, the type arguments are correctly substituted, and memberType is already in a good shape. Only annotations on the memberType should be replaced by the viewpoint adapted ones.

        Specified by:
        viewpointAdaptMember in interface ViewpointAdapter
        Parameters:
        receiverType - receiver type through which the member/field is accessed.
        memberElement - element of the accessed member/field.
        memberType - accessed type of the member/field. After the method returns, it will be mutated to the viewpoint adapted result.
      • shouldAdaptMember

        protected boolean shouldAdaptMember​(AnnotatedTypeMirror type,
                                            javax.lang.model.element.Element element)
        Determines whether a particular member should be viewpoint adapted or not. The default implementation adapts all members except for local variables and method formal parameters.
        Parameters:
        type - type of the member, used to decide whether a member should be viewpoint adapted or not. A subclass of ViewpointAdapter may disable viewpoint adaptation for elements based on their types.
        element - element of the member
        Returns:
        true if the member needs viewpoint adaptation
      • viewpointAdaptConstructor

        public void viewpointAdaptConstructor​(AnnotatedTypeMirror receiverType,
                                              javax.lang.model.element.ExecutableElement constructorElt,
                                              AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
        Description copied from interface: ViewpointAdapter
        Viewpoint adapts a constructor invocation. Takes an unsubstituted method invocation type and performs the viewpoint adaption in place, modifying the parameter.
        Specified by:
        viewpointAdaptConstructor in interface ViewpointAdapter
        Parameters:
        receiverType - receiver type through which a constructor is invoked.
        constructorElt - element of the invoked constructor.
        constructorType - invoked type of the constructor with type variables not substituted. After the method returns, it will be mutated to the viewpoint adapted constructor type.
      • viewpointAdaptMethod

        public void viewpointAdaptMethod​(AnnotatedTypeMirror receiverType,
                                         javax.lang.model.element.ExecutableElement methodElt,
                                         AnnotatedTypeMirror.AnnotatedExecutableType methodType)
        Description copied from interface: ViewpointAdapter
        Viewpoint adapts a method invocation. Takes an unsubstituted method invocation type and performs the viewpoint adaption in place, modifying the parameter.
        Specified by:
        viewpointAdaptMethod in interface ViewpointAdapter
        Parameters:
        receiverType - receiver type through which a method is invoked.
        methodElt - element of the invoked method. Only used to determine whether this type should be viewpoint adapted
        methodType - invoked type of the method with type variables not substituted. After the method returns, it will be mutated to the viewpoint adapted method type.
      • shouldAdaptMethod

        protected boolean shouldAdaptMethod​(javax.lang.model.element.ExecutableElement element)
        Determine if an invocation of the given method needs to be adapted.
        Parameters:
        element - the executable element for a method
        Returns:
        true if an invocation of the executable element needs to be adapted
      • viewpointAdaptTypeParameterBounds

        public void viewpointAdaptTypeParameterBounds​(AnnotatedTypeMirror receiverType,
                                                      java.util.List<AnnotatedTypeParameterBounds> typeParameterBounds)
        Description copied from interface: ViewpointAdapter
        Viewpoint adapts a type parameter bound when being instantiated.
        Specified by:
        viewpointAdaptTypeParameterBounds in interface ViewpointAdapter
        Parameters:
        receiverType - receiver type through which the type parameter is instantiated.
        typeParameterBounds - a list of type parameter bounds. After the method returns, it will be mutated to the viewpoint adapted type parameter bounds.
      • extractAnnotationMirror

        protected abstract javax.lang.model.element.AnnotationMirror extractAnnotationMirror​(AnnotatedTypeMirror atm)
        Extract the relevant qualifier from an AnnotatedTypeMirror.
        Parameters:
        atm - AnnotatedTypeMirror from which qualifier is extracted
        Returns:
        extracted qualifier
      • combineAnnotationWithType

        protected AnnotatedTypeMirror combineAnnotationWithType​(javax.lang.model.element.AnnotationMirror receiverAnnotation,
                                                                AnnotatedTypeMirror declared)
        Combine receiver qualifiers with declared types. Qualifiers are extracted from declared types to further perform viewpoint adaptation only between two qualifiers.
        Parameters:
        receiverAnnotation - receiver qualifier
        declared - declared type
        Returns:
        AnnotatedTypeMirror after viewpoint adaptation
      • combineAnnotationWithAnnotation

        @SideEffectFree
        protected abstract javax.lang.model.element.AnnotationMirror combineAnnotationWithAnnotation​(javax.lang.model.element.AnnotationMirror receiverAnnotation,
                                                                                                     javax.lang.model.element.AnnotationMirror declaredAnnotation)
        Viewpoint adapt declared qualifier to receiver qualifier.
        Parameters:
        receiverAnnotation - receiver qualifier
        declaredAnnotation - declared qualifier
        Returns:
        result qualifier after viewpoint adaptation