Class AnnotatedTypeReplacer
- java.lang.Object
-
- org.checkerframework.framework.type.visitor.AnnotatedTypeScanner<R,AnnotatedTypeMirror>
-
- org.checkerframework.framework.type.visitor.DoubleAnnotatedTypeScanner<java.lang.Void>
-
- org.checkerframework.framework.type.AnnotatedTypeReplacer
-
- All Implemented Interfaces:
AnnotatedTypeVisitor<java.lang.Void,AnnotatedTypeMirror>
public class AnnotatedTypeReplacer extends DoubleAnnotatedTypeScanner<java.lang.Void>
Replaces or adds all the annotations in the parameter with the annotations from the visited type. An annotation is replaced if the parameter type already has an annotation in the same hierarchy at the same location as the visited type.Example use:
AnnotatedTypeMirror visitType = ...; AnnotatedTypeMirror parameter = ...; visitType.accept(new AnnotatedTypeReplacer(), parameter);
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.checkerframework.framework.type.visitor.AnnotatedTypeScanner
AnnotatedTypeScanner.Reduce<R>
-
-
Field Summary
-
Fields inherited from class org.checkerframework.framework.type.visitor.AnnotatedTypeScanner
defaultResult, reduceFunction, visitedNodes
-
-
Constructor Summary
Constructors Constructor Description AnnotatedTypeReplacer()
Construct an AnnotatedTypeReplacer that will replace all annotations.AnnotatedTypeReplacer(@Nullable javax.lang.model.element.AnnotationMirror top)
Construct an AnnotatedTypeReplacer that will only replace annotations intop
's hierarchy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Void
defaultAction(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
Called by default for any visit method that is not overridden.protected void
replaceAnnotations(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
Replace the annotations in to with the annotations in from, wherever from has an annotation.void
resolvePrimaries(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
For type variables and wildcards, the absence of a primary annotations has an implied meaning on substitution.void
setTop(@Nullable javax.lang.model.element.AnnotationMirror top)
Iftop != null
, then only annotations in the hierarchy oftop
are affected; otherwise, all annotations are replaced.java.lang.Void
visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable from, AnnotatedTypeMirror to)
Visits a type variable.java.lang.Void
visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType from, AnnotatedTypeMirror to)
Visits a wildcard type.-
Methods inherited from class org.checkerframework.framework.type.visitor.DoubleAnnotatedTypeScanner
scan, scan, scanAndReduce, scanAndReduce, visitArray, visitDeclared, visitExecutable, visitIntersection, visitUnion
-
Methods inherited from class org.checkerframework.framework.type.visitor.AnnotatedTypeScanner
reduce, reset, scan, scanAndReduce, visit, visit, visitNoType, visitNull, visitPrimitive
-
-
-
-
Constructor Detail
-
AnnotatedTypeReplacer
public AnnotatedTypeReplacer()
Construct an AnnotatedTypeReplacer that will replace all annotations.
-
AnnotatedTypeReplacer
public AnnotatedTypeReplacer(@Nullable javax.lang.model.element.AnnotationMirror top)
Construct an AnnotatedTypeReplacer that will only replace annotations intop
's hierarchy.- Parameters:
top
- if top != null, then only annotations in the hierarchy of top are affected
-
-
Method Detail
-
setTop
public void setTop(@Nullable javax.lang.model.element.AnnotationMirror top)
Iftop != null
, then only annotations in the hierarchy oftop
are affected; otherwise, all annotations are replaced.- Parameters:
top
- if top != null, then only annotations in the hierarchy of top are replaced; otherwise, all annotations are replaced.
-
defaultAction
protected java.lang.Void defaultAction(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
Description copied from class:DoubleAnnotatedTypeScanner
Called by default for any visit method that is not overridden.- Specified by:
defaultAction
in classDoubleAnnotatedTypeScanner<java.lang.Void>
- Parameters:
from
- the type to visitto
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
replaceAnnotations
protected void replaceAnnotations(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
Replace the annotations in to with the annotations in from, wherever from has an annotation.- Parameters:
from
- the source of the annotationsto
- the destination of the annotations, modified by this method
-
visitTypeVariable
public java.lang.Void visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable from, AnnotatedTypeMirror to)
Description copied from interface:AnnotatedTypeVisitor
Visits a type variable.- Specified by:
visitTypeVariable
in interfaceAnnotatedTypeVisitor<java.lang.Void,AnnotatedTypeMirror>
- Overrides:
visitTypeVariable
in classDoubleAnnotatedTypeScanner<java.lang.Void>
- Parameters:
from
- the type to visitto
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitWildcard
public java.lang.Void visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType from, AnnotatedTypeMirror to)
Description copied from interface:AnnotatedTypeVisitor
Visits a wildcard type.- Specified by:
visitWildcard
in interfaceAnnotatedTypeVisitor<java.lang.Void,AnnotatedTypeMirror>
- Overrides:
visitWildcard
in classDoubleAnnotatedTypeScanner<java.lang.Void>
- Parameters:
from
- the type to visitto
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
resolvePrimaries
public void resolvePrimaries(AnnotatedTypeMirror from, AnnotatedTypeMirror to)
For type variables and wildcards, the absence of a primary annotations has an implied meaning on substitution. Therefore, in these cases we remove the primary annotation and rely on the fact that the bounds are also merged into the type to.- Parameters:
from
- a type variable or wildcardto
- the destination annotated type mirror
-
-