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 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/field access.voidviewpointAdaptMethod(AnnotatedTypeMirror receiverType, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Viewpoint adapts a method invocation.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/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:
viewpointAdaptMemberin interfaceViewpointAdapter- 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
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 adaption in place, modifying the parameter.- Specified by:
viewpointAdaptConstructorin interfaceViewpointAdapter- 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, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Description copied from interface:ViewpointAdapterViewpoint adapts a method invocation. Takes an unsubstituted method invocation type and performs the viewpoint adaption in place, modifying the parameter.- Specified by:
viewpointAdaptMethodin interfaceViewpointAdapter- 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 adaptedmethodType- 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- 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.
-
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
-
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
-