Class AnnotatedTypeCopier
- All Implemented Interfaces:
AnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>>
- Direct Known Subclasses:
AnnotatedTypeCopierWithReplacement.Visitor
,AnnotatedTypeFactory.CapturedTypeVarSubstitutor
,TypeVariableSubstitutor.Visitor
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.-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
protected boolean
This is a hack to handle the curious behavior of substitution on an AnnotatedExecutableType. -
Constructor Summary
ConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends AnnotatedTypeMirror>
TmakeCopy
(T original) Returns a copy of the given type.protected <T extends AnnotatedTypeMirror>
TmakeOrReturnCopy
(T original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) For any given object in the type being copied, we only want to generate one copy of that object.protected void
This method is called in any location in which a primary annotation would be copied from source to dest.visit
(AnnotatedTypeMirror type) A convenience method equivalent tov.visit(t, null)
.visit
(AnnotatedTypeMirror type, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits a type.visitArray
(AnnotatedTypeMirror.AnnotatedArrayType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits an array type.visitDeclared
(AnnotatedTypeMirror.AnnotatedDeclaredType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits a declared type.visitExecutable
(AnnotatedTypeMirror.AnnotatedExecutableType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits an executable type.visitIntersection
(AnnotatedTypeMirror.AnnotatedIntersectionType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits an intersection type.visitNoType
(AnnotatedTypeMirror.AnnotatedNoType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits NoType type.visitNull
(AnnotatedTypeMirror.AnnotatedNullType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits anull
type.visitPrimitive
(AnnotatedTypeMirror.AnnotatedPrimitiveType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits a primitive type.visitTypeVariable
(AnnotatedTypeMirror.AnnotatedTypeVariable original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits a type variable.visitUnion
(AnnotatedTypeMirror.AnnotatedUnionType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits an union type.visitWildcard
(AnnotatedTypeMirror.AnnotatedWildcardType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Visits a wildcard type.
-
Field Details
-
visitingExecutableTypeParam
protected boolean visitingExecutableTypeParamThis is a hack to handle the curious behavior of substitution on an AnnotatedExecutableType. -
copyAnnotations
protected final boolean copyAnnotations- See Also:
-
-
Constructor Details
-
AnnotatedTypeCopier
public 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.
- Annotation preservation -- All of the annotations from the original AnnotatedTypeMirror and its components have been copied to the new type.
-
AnnotatedTypeCopier
public AnnotatedTypeCopier()Creates an AnnotatedTypeCopier that copies both the structure and annotations of the source AnnotatedTypeMirror.- See Also:
-
-
Method Details
-
visit
Description copied from interface:AnnotatedTypeVisitor
A convenience method equivalent tov.visit(t, null)
.- Specified by:
visit
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
type
- the type to visit- Returns:
- a visitor-specified result
-
visit
public AnnotatedTypeMirror visit(AnnotatedTypeMirror type, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits a type.- Specified by:
visit
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
type
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitDeclared
public AnnotatedTypeMirror visitDeclared(AnnotatedTypeMirror.AnnotatedDeclaredType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits a declared type.- Specified by:
visitDeclared
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitIntersection
public AnnotatedTypeMirror visitIntersection(AnnotatedTypeMirror.AnnotatedIntersectionType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits an intersection type.- Specified by:
visitIntersection
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitUnion
public AnnotatedTypeMirror visitUnion(AnnotatedTypeMirror.AnnotatedUnionType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits an union type.- Specified by:
visitUnion
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitExecutable
public AnnotatedTypeMirror visitExecutable(AnnotatedTypeMirror.AnnotatedExecutableType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits an executable type.- Specified by:
visitExecutable
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitArray
public AnnotatedTypeMirror visitArray(AnnotatedTypeMirror.AnnotatedArrayType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits an array type.- Specified by:
visitArray
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitTypeVariable
public AnnotatedTypeMirror visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits a type variable.- Specified by:
visitTypeVariable
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitPrimitive
public AnnotatedTypeMirror visitPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits a primitive type.- Specified by:
visitPrimitive
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitNoType
public AnnotatedTypeMirror visitNoType(AnnotatedTypeMirror.AnnotatedNoType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits NoType type.- Specified by:
visitNoType
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitNull
public AnnotatedTypeMirror visitNull(AnnotatedTypeMirror.AnnotatedNullType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits anull
type.- Specified by:
visitNull
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
visitWildcard
public AnnotatedTypeMirror visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) Description copied from interface:AnnotatedTypeVisitor
Visits a wildcard type.- Specified by:
visitWildcard
in interfaceAnnotatedTypeVisitor<AnnotatedTypeMirror,
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>> - Parameters:
original
- the type to visitoriginalToCopy
- a visitor-specified parameter- Returns:
- a visitor-specified result
-
makeOrReturnCopy
protected <T extends AnnotatedTypeMirror> T makeOrReturnCopy(T original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) For any given object in the type being copied, we only want to generate one copy of that object. When that object is encountered again, using the previously generated copy will preserve the structure of the original AnnotatedTypeMirror.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
- Type Parameters:
T
- the type of original copy, this is a shortcut to avoid having to insert casts all over the visitor- Parameters:
original
- a reference to a type to copyoriginalToCopy
- a mapping of previously encountered references to the copies made for those references- Returns:
- a copy of original
-
makeCopy
Returns a copy of the given type.- Type Parameters:
T
- the type of the AnnotatedTypeMirror to copy- Parameters:
original
- an AnnotatedTypeMirror (more specifically, aT
)- Returns:
- a copy of the given AnnotatedTypeMirror
-
maybeCopyPrimaryAnnotations
This method is called in any location in which a primary annotation would be copied from source to dest. Note, this method obeys the copyAnnotations field. Subclasses of AnnotatedTypeCopier can use this method to customize annotations before copying.- Parameters:
source
- the type whose primary annotations are being copieddest
- a copy of source that should receive its primary annotations
-