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.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected booleanThis is a hack to handle the curious behavior of substitution on an AnnotatedExecutableType. -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 voidThis 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 anulltype.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.- See Also:
-
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:AnnotatedTypeVisitorA convenience method equivalent tov.visit(t, null).- Specified by:
visitin 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:AnnotatedTypeVisitorVisits a type.- Specified by:
visitin 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:AnnotatedTypeVisitorVisits a declared type.- Specified by:
visitDeclaredin 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:AnnotatedTypeVisitorVisits an intersection type.- Specified by:
visitIntersectionin 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:AnnotatedTypeVisitorVisits an union type.- Specified by:
visitUnionin 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:AnnotatedTypeVisitorVisits an executable type.- Specified by:
visitExecutablein 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:AnnotatedTypeVisitorVisits an array type.- Specified by:
visitArrayin 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:AnnotatedTypeVisitorVisits a type variable.- Specified by:
visitTypeVariablein 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:AnnotatedTypeVisitorVisits a primitive type.- Specified by:
visitPrimitivein 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:AnnotatedTypeVisitorVisits NoType type.- Specified by:
visitNoTypein 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:AnnotatedTypeVisitorVisits anulltype.- Specified by:
visitNullin 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:AnnotatedTypeVisitorVisits a wildcard type.- Specified by:
visitWildcardin 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
-