public abstract class AbstractViewpointAdapter extends Object implements ViewpointAdapter
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.
Modifier and Type | Field and Description |
---|---|
protected AnnotatedTypeFactory |
atypeFactory
The annotated type factory.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractViewpointAdapter(AnnotatedTypeFactory atypeFactory)
Construct an abstract viewpoint adapter with the given type factory.
|
Modifier and Type | Method and Description |
---|---|
protected 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 atm
|
protected abstract AnnotationMirror |
extractAnnotationMirror(AnnotatedTypeMirror atm)
Extract the relevant qualifier from an
AnnotatedTypeMirror . |
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.
|
protected final AnnotatedTypeFactory atypeFactory
protected AbstractViewpointAdapter(AnnotatedTypeFactory atypeFactory)
atypeFactory
- the type factory to usepublic void viewpointAdaptMember(AnnotatedTypeMirror receiverType, Element memberElement, AnnotatedTypeMirror memberType)
ViewpointAdapter
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.
viewpointAdaptMember
in interface ViewpointAdapter
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.protected boolean shouldAdaptMember(AnnotatedTypeMirror type, Element element)
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 memberpublic void viewpointAdaptConstructor(AnnotatedTypeMirror receiverType, ExecutableElement constructorElt, AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
ViewpointAdapter
viewpointAdaptConstructor
in interface ViewpointAdapter
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.public void viewpointAdaptMethod(AnnotatedTypeMirror receiverType, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType methodType)
ViewpointAdapter
viewpointAdaptMethod
in interface ViewpointAdapter
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.protected boolean shouldAdaptMethod(ExecutableElement element)
element
- the executable element for a methodpublic void viewpointAdaptTypeParameterBounds(AnnotatedTypeMirror receiverType, List<AnnotatedTypeParameterBounds> typeParameterBounds)
ViewpointAdapter
viewpointAdaptTypeParameterBounds
in interface ViewpointAdapter
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.protected AnnotatedTypeMirror combineTypeWithType(AnnotatedTypeMirror receiver, AnnotatedTypeMirror declared)
receiver
- receiver typedeclared
- declared typeAnnotatedTypeMirror
after viewpoint adaptationprotected abstract AnnotationMirror extractAnnotationMirror(AnnotatedTypeMirror atm)
AnnotatedTypeMirror
.atm
- AnnotatedTypeMirror from which qualifier is extractedprotected AnnotatedTypeMirror combineAnnotationWithType(AnnotationMirror receiverAnnotation, AnnotatedTypeMirror declared)
receiverAnnotation
- receiver qualifierdeclared
- declared typeAnnotatedTypeMirror
after viewpoint adaptation@SideEffectFree protected abstract AnnotationMirror combineAnnotationWithAnnotation(AnnotationMirror receiverAnnotation, AnnotationMirror declaredAnnotation)
receiverAnnotation
- receiver qualifierdeclaredAnnotation
- declared qualifier