Interface ViewpointAdapter

All Known Implementing Classes:
AbstractViewpointAdapter, ViewpointTestViewpointAdapter

public interface ViewpointAdapter
An interface for viewpoint adaptation.

Viewpoint adaptation takes a type that was written from a particular viewpoint (the declaration viewpoint) and translates it to a type from another viewpoint (the receiver viewpoint). For example, if a field's type uses an annotation like @This, viewpoint adaptation replaces that annotation with the actual receiver type at the use site.

Viewpoint adaptation applies to member/field accesses, constructor invocations, method invocations, and type parameter bound instantiations.

  • Method Details

    • viewpointAdaptMember

      void viewpointAdaptMember(AnnotatedTypeMirror receiverType, Element memberElement, AnnotatedTypeMirror memberType)
      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.

      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.
    • viewpointAdaptConstructor

      void viewpointAdaptConstructor(AnnotatedTypeMirror receiverType, ExecutableElement constructorElt, AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
      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.
      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

      void viewpointAdaptMethod(AnnotatedTypeMirror receiverType, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType methodType)
      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.
      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.
    • viewpointAdaptTypeParameterBounds

      void viewpointAdaptTypeParameterBounds(AnnotatedTypeMirror receiverType, List<AnnotatedTypeParameterBounds> typeParameterBounds)
      Viewpoint-adapts a type parameter bound when being instantiated.
      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

      AnnotationMirrorSet viewpointAdaptTypeDeclarationBounds(AnnotationMirrorSet viewpointBounds, AnnotatedTypeMirror declarationBoundType)
      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.
      Parameters:
      viewpointBounds - the type-declaration bounds that provide the viewpoint
      declarationBoundType - the type whose declaration bounds to adapt
      Returns:
      the adapted declaration bounds
    • viewpointAdaptType

      AnnotatedTypeMirror viewpointAdaptType(AnnotatedTypeMirror receiverType, AnnotatedTypeMirror declaredType)
      Viewpoint-adapts a type written from the receiver's declaration viewpoint.
      Parameters:
      receiverType - the receiver type through which declaredType is viewed
      declaredType - the type to viewpoint-adapt
      Returns:
      the viewpoint-adapted type