Class AbstractViewpointAdapter

java.lang.Object
org.checkerframework.framework.type.AbstractViewpointAdapter
All Implemented Interfaces:
ViewpointAdapter
Direct Known Subclasses:
ViewpointTestViewpointAdapter

public abstract class AbstractViewpointAdapter extends 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.

  • Field Details

  • Constructor Details

    • AbstractViewpointAdapter

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

    • viewpointAdaptMember

      public void viewpointAdaptMember(AnnotatedTypeMirror receiverType, Element memberElement, AnnotatedTypeMirror memberType)
      Description copied from interface: ViewpointAdapter
      Viewpoint-adapts a member or 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 memberType should be replaced by the viewpoint-adapted ones.

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

      protected boolean shouldAdaptMember(AnnotatedTypeMirror type, 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, 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 adaptation in place, modifying the parameter. The type variables of the class stay in place: AnnotatedTypes#asMemberOf substitutes the type arguments for them afterwards.
      Specified by:
      viewpointAdaptConstructor in interface ViewpointAdapter
      Parameters:
      receiverType - the receiver type through which a constructor is invoked
      constructorElt - the element of the invoked constructor
      constructorType - the 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, 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 adaptation in place, modifying the parameter. The type variables of the class stay in place: AnnotatedTypes#asMemberOf substitutes the receiver's type arguments for them afterwards.
      Specified by:
      viewpointAdaptMethod in interface ViewpointAdapter
      Parameters:
      receiverType - the receiver type through which a method is invoked
      methodElt - the element of the invoked method. Only used to determine whether this type should be viewpoint-adapted.
      methodType - the 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(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, 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 - the 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.
    • viewpointAdaptTypeDeclarationBounds

      public AnnotationMirrorSet viewpointAdaptTypeDeclarationBounds(AnnotationMirrorSet viewpointBounds, AnnotatedTypeMirror declarationBoundType)
      Description copied from interface: ViewpointAdapter
      Viewpoint-adapts the primary qualifiers of declarationBoundType from the viewpoint of viewpointBounds. This is how a supertype declared with a receiver-dependent bound takes on the bound of the subtype that extends or implements it.
      Specified by:
      viewpointAdaptTypeDeclarationBounds in interface ViewpointAdapter
      Parameters:
      viewpointBounds - the type-declaration bounds that provide the viewpoint
      declarationBoundType - the type whose declaration bounds to adapt
      Returns:
      the adapted declaration bounds
    • viewpointAdaptType

      public AnnotatedTypeMirror viewpointAdaptType(AnnotatedTypeMirror receiverType, AnnotatedTypeMirror declaredType)
      Description copied from interface: ViewpointAdapter
      Viewpoint-adapts a type written from the receiver's declaration viewpoint.
      Specified by:
      viewpointAdaptType in interface ViewpointAdapter
      Parameters:
      receiverType - the receiver type through which declaredType is viewed
      declaredType - the type to viewpoint-adapt
      Returns:
      the viewpoint-adapted type
    • combineTypeWithType

      protected AnnotatedTypeMirror combineTypeWithType(AnnotatedTypeMirror receiver, AnnotatedTypeMirror declared)
      Viewpoint adapt declared type to receiver type, and return the result atm
      Parameters:
      receiver - receiver type
      declared - declared type
      Returns:
      AnnotatedTypeMirror after viewpoint adaptation
    • extractAnnotationMirror

      protected abstract AnnotationMirror extractAnnotationMirror(AnnotatedTypeMirror atm)
      Extract the relevant qualifier from an AnnotatedTypeMirror.
      Parameters:
      atm - AnnotatedTypeMirror from which qualifier is extracted
      Returns:
      extracted qualifier
    • extractAnnotationMirror

      protected abstract AnnotationMirror extractAnnotationMirror(AnnotationMirrorSet annotations)
      Extracts the qualifier that this adapter adapts with, from a set of qualifiers. The counterpart of extractAnnotationMirror(AnnotatedTypeMirror) for a bare qualifier set, such as a type's declaration bounds.
      Parameters:
      annotations - a set of qualifiers containing one in this adapter's hierarchy
      Returns:
      the qualifier used for viewpoint adaptation
    • combineAnnotationWithType

      protected AnnotatedTypeMirror combineAnnotationWithType(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 AnnotationMirror combineAnnotationWithAnnotation(AnnotationMirror receiverAnnotation, AnnotationMirror declaredAnnotation)
      Viewpoint adapt declared qualifier to receiver qualifier.
      Parameters:
      receiverAnnotation - receiver qualifier
      declaredAnnotation - declared qualifier
      Returns:
      result qualifier after viewpoint adaptation