Class AbstractViewpointAdapter
java.lang.Object
org.checkerframework.framework.type.AbstractViewpointAdapter
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final AnnotatedTypeFactory
The annotated type factory. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractViewpointAdapter
(AnnotatedTypeFactory atypeFactory) Construct an abstract viewpoint adapter with the given type factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AnnotationMirror
combineAnnotationWithAnnotation
(AnnotationMirror receiverAnnotation, AnnotationMirror declaredAnnotation) Viewpoint adapt declared qualifier to receiver qualifier.protected AnnotatedTypeMirror
combineAnnotationWithType
(AnnotationMirror receiverAnnotation, AnnotatedTypeMirror declared) Combine receiver qualifiers with declared types.protected AnnotatedTypeMirror
combineTypeWithType
(AnnotatedTypeMirror receiver, AnnotatedTypeMirror declared) Viewpoint adapt declared type to receiver type, and return the result atmprotected abstract AnnotationMirror
Extract the relevant qualifier from anAnnotatedTypeMirror
.protected boolean
shouldAdaptMember
(AnnotatedTypeMirror type, Element element) Determines whether a particular member should be viewpoint adapted or not.protected boolean
shouldAdaptMethod
(ExecutableElement element) Determine if an invocation of the given method needs to be adapted.void
viewpointAdaptConstructor
(AnnotatedTypeMirror receiverType, ExecutableElement constructorElt, AnnotatedTypeMirror.AnnotatedExecutableType constructorType) Viewpoint adapts a constructor invocation.void
viewpointAdaptMember
(AnnotatedTypeMirror receiverType, Element memberElement, AnnotatedTypeMirror memberType) Viewpoint adapts a member/field access.void
viewpointAdaptMethod
(AnnotatedTypeMirror receiverType, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Viewpoint adapts a method invocation.void
viewpointAdaptTypeParameterBounds
(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: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 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 ofViewpointAdapter
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 adaption in place, modifying the parameter.- Specified by:
viewpointAdaptConstructor
in 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: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 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:ViewpointAdapter
Viewpoint adapts a type parameter bound when being instantiated.- Specified by:
viewpointAdaptTypeParameterBounds
in 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:
AnnotatedTypeMirror
after 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:
AnnotatedTypeMirror
after 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
-