Class AbstractViewpointAdapter
java.lang.Object
org.checkerframework.framework.type.AbstractViewpointAdapter
- All Implemented Interfaces:
ViewpointAdapter
- Direct Known Subclasses:
ViewpointTestViewpointAdapter
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final AnnotatedTypeFactoryThe annotated type factory. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractViewpointAdapter(AnnotatedTypeFactory atypeFactory) Construct an abstract viewpoint adapter with the given type factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AnnotationMirrorcombineAnnotationWithAnnotation(AnnotationMirror receiverAnnotation, AnnotationMirror declaredAnnotation) Viewpoint adapt declared qualifier to receiver qualifier.protected AnnotatedTypeMirrorcombineAnnotationWithType(AnnotationMirror receiverAnnotation, AnnotatedTypeMirror declared) Combine receiver qualifiers with declared types.protected AnnotatedTypeMirrorcombineTypeWithType(AnnotatedTypeMirror receiver, AnnotatedTypeMirror declared) Viewpoint adapt declared type to receiver type, and return the result atmprotected abstract AnnotationMirrorExtract the relevant qualifier from anAnnotatedTypeMirror.protected abstract AnnotationMirrorextractAnnotationMirror(AnnotationMirrorSet annotations) Extracts the qualifier that this adapter adapts with, from a set of qualifiers.protected booleanshouldAdaptMember(AnnotatedTypeMirror type, Element element) Determines whether a particular member should be viewpoint adapted or not.protected booleanshouldAdaptMethod(ExecutableElement element) Determine if an invocation of the given method needs to be adapted.voidviewpointAdaptConstructor(AnnotatedTypeMirror receiverType, ExecutableElement constructorElt, AnnotatedTypeMirror.AnnotatedExecutableType constructorType) Viewpoint-adapts a constructor invocation.voidviewpointAdaptMember(AnnotatedTypeMirror receiverType, Element memberElement, AnnotatedTypeMirror memberType) Viewpoint-adapts a member or field access.voidviewpointAdaptMethod(AnnotatedTypeMirror receiverType, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Viewpoint-adapts a method invocation.viewpointAdaptType(AnnotatedTypeMirror receiverType, AnnotatedTypeMirror declaredType) Viewpoint-adapts a type written from the receiver's declaration viewpoint.viewpointAdaptTypeDeclarationBounds(AnnotationMirrorSet viewpointBounds, AnnotatedTypeMirror declarationBoundType) Viewpoint-adapts the primary qualifiers ofdeclarationBoundTypefrom the viewpoint ofviewpointBounds.voidviewpointAdaptTypeParameterBounds(AnnotatedTypeMirror receiverType, List<AnnotatedTypeParameterBounds> typeParameterBounds) Viewpoint-adapts a type parameter bound when being instantiated.
-
Field Details
-
atypeFactory
The annotated type factory.
-
-
Constructor Details
-
AbstractViewpointAdapter
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:ViewpointAdapterViewpoint-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
memberTypeis already in a good shape. Only annotations onmemberTypeshould be replaced by the viewpoint-adapted ones.- Specified by:
viewpointAdaptMemberin interfaceViewpointAdapter- Parameters:
receiverType- the receiver type through which the member or field is accessedmemberElement- the element of the accessed member or fieldmemberType- the accessed type of the member or field. After the method returns, it will be mutated to the viewpoint-adapted result.
-
shouldAdaptMember
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 ofViewpointAdaptermay 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:ViewpointAdapterViewpoint-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#asMemberOfsubstitutes the type arguments for them afterwards.- Specified by:
viewpointAdaptConstructorin interfaceViewpointAdapter- Parameters:
receiverType- the receiver type through which a constructor is invokedconstructorElt- the element of the invoked constructorconstructorType- 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:ViewpointAdapterViewpoint-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#asMemberOfsubstitutes the receiver's type arguments for them afterwards.- Specified by:
viewpointAdaptMethodin interfaceViewpointAdapter- Parameters:
receiverType- the receiver type through which a method is invokedmethodElt- 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
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:ViewpointAdapterViewpoint-adapts a type parameter bound when being instantiated.- Specified by:
viewpointAdaptTypeParameterBoundsin interfaceViewpointAdapter- Parameters:
receiverType- the receiver type through which the type parameter is instantiatedtypeParameterBounds- 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:ViewpointAdapterViewpoint-adapts the primary qualifiers ofdeclarationBoundTypefrom the viewpoint ofviewpointBounds. 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:
viewpointAdaptTypeDeclarationBoundsin interfaceViewpointAdapter- Parameters:
viewpointBounds- the type-declaration bounds that provide the viewpointdeclarationBoundType- the type whose declaration bounds to adapt- Returns:
- the adapted declaration bounds
-
viewpointAdaptType
public AnnotatedTypeMirror viewpointAdaptType(AnnotatedTypeMirror receiverType, AnnotatedTypeMirror declaredType) Description copied from interface:ViewpointAdapterViewpoint-adapts a type written from the receiver's declaration viewpoint.- Specified by:
viewpointAdaptTypein interfaceViewpointAdapter- Parameters:
receiverType- the receiver type through whichdeclaredTypeis vieweddeclaredType- 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 typedeclared- declared type- Returns:
AnnotatedTypeMirrorafter viewpoint adaptation
-
extractAnnotationMirror
Extract the relevant qualifier from anAnnotatedTypeMirror.- Parameters:
atm- AnnotatedTypeMirror from which qualifier is extracted- Returns:
- extracted qualifier
-
extractAnnotationMirror
Extracts the qualifier that this adapter adapts with, from a set of qualifiers. The counterpart ofextractAnnotationMirror(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 qualifierdeclared- declared type- Returns:
AnnotatedTypeMirrorafter viewpoint adaptation
-
combineAnnotationWithAnnotation
@SideEffectFree protected abstract AnnotationMirror combineAnnotationWithAnnotation(AnnotationMirror receiverAnnotation, AnnotationMirror declaredAnnotation) Viewpoint adapt declared qualifier to receiver qualifier.- Parameters:
receiverAnnotation- receiver qualifierdeclaredAnnotation- declared qualifier- Returns:
- result qualifier after viewpoint adaptation
-