public class AnnotatedTypeCopier extends Object implements AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>
When making copies, a map of encountered references => copied types is maintained. This ensures that, if a reference appears in multiple locations in the original type, a corresponding copy of the original type appears in the same locations in the output copy. This ensures that the recursive loops in the input type are preserved in its output copy (see makeOrReturnCopy)
In general, AnnotatedTypeMirrors should be copied via AnnotatedTypeMirror#deepCopy and AnnotatedTypeMirror#shallowCopy. AnnotatedTypeMirror#deepCopy makes use of AnnotatedTypeCopier under the covers. However, this visitor and its subclasses can be invoked as follows:
new AnnotatedTypeCopier().visit(myTypeVar);
Note: There are methods that may require a copy of a type mirror with slight changes. It is
intended that this class can be overridden for these cases.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
copyAnnotations
|
protected boolean |
visitingExecutableTypeParam
This is a hack to handle the curious behavior of substitution on an AnnotatedExecutableType.
|
| Constructor and Description |
|---|
AnnotatedTypeCopier()
Creates an AnnotatedTypeCopier that copies both the structure and annotations of the source
AnnotatedTypeMirror.
|
AnnotatedTypeCopier(boolean copyAnnotations)
Creates an AnnotatedTypeCopier that may or may not copyAnnotations By default
AnnotatedTypeCopier provides two major properties in its copies:
Structure preservation -- the exact structure of the original AnnotatedTypeMirror is
preserved in the copy including all component types.
|
protected boolean visitingExecutableTypeParam
protected final boolean copyAnnotations
AnnotatedTypeCopier(boolean)public AnnotatedTypeCopier(boolean copyAnnotations)
public AnnotatedTypeCopier()
AnnotatedTypeCopier(boolean)public AnnotatedTypeMirror visit(AnnotatedTypeMirror type)
AnnotatedTypeVisitorv.visit(t, null).visit in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>type - the type to visitpublic AnnotatedTypeMirror visit(AnnotatedTypeMirror type, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisit in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>type - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitDeclared(AnnotatedTypeMirror.AnnotatedDeclaredType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitDeclared in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitIntersection(AnnotatedTypeMirror.AnnotatedIntersectionType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitIntersection in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitUnion(AnnotatedTypeMirror.AnnotatedUnionType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitUnion in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitExecutable(AnnotatedTypeMirror.AnnotatedExecutableType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitExecutable in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitArray(AnnotatedTypeMirror.AnnotatedArrayType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitArray in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitTypeVariable in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitPrimitive in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitNoType(AnnotatedTypeMirror.AnnotatedNoType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitNoType in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitNull(AnnotatedTypeMirror.AnnotatedNullType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitornull type.visitNull in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterpublic AnnotatedTypeMirror visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
AnnotatedTypeVisitorvisitWildcard in interface AnnotatedTypeVisitor<AnnotatedTypeMirror,IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror>>original - the type to visitoriginalToCopy - a visitor-specified parameterprotected <T extends AnnotatedTypeMirror> T makeOrReturnCopy(T original, IdentityHashMap<AnnotatedTypeMirror,AnnotatedTypeMirror> originalToCopy)
makeOrReturnCopy first checks to see if an object has been encountered before. If so, it returns the previously generated duplicate of that object if not, it creates a duplicate of the object and stores it in the history, originalToCopy
T - the type of original copy, this is a shortcut to avoid having to insert casts all
over the visitororiginal - a reference to a type to copyoriginalToCopy - a mapping of previously encountered references to the copies made for
those referencesprotected <T extends AnnotatedTypeMirror> T makeCopy(T original)
protected void maybeCopyPrimaryAnnotations(AnnotatedTypeMirror source, AnnotatedTypeMirror dest)
source - the type whose primary annotations are being copieddest - a copy of source that should receive its primary annotations