Class SubtypeVisitHistory
VisitHistory tracks triples of (type1, type2, top), where type1 is a subtype of type2. It does not track when type1 is not a subtype of type2; such entries are missing from the history. Clients of this class can check whether or not they have visited an equivalent pair of AnnotatedTypeMirrors already. This is necessary in order to halt visiting on recursive bounds.
This class is primarily used to implement isSubtype(ATM, ATM). The pair of types corresponds
to the subtype and the supertype being checked. A single subtype may be visited more than once,
but with a different supertype. For example, if the two types are @A T extends @B
Serializable<T> and @C Serializable<?>, then isSubtype is first called on those types
and then on @B Serializable<T> and @C Serializable<?>.
Callers should call clear() once an outermost (non-nested) isSubtype call
completes, so that the history does not accumulate entries across unrelated isSubtype
calls. Entries only need to persist for the duration of a single such call, to guard against
infinite recursion within it; letting the map grow for the whole compilation unit only makes
every subsequent lookup slower, for no benefit, since unrelated calls do not repeat the same
(type1, type2) pair.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entries from the history.booleancontains(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror currentTop) Returns true if type1 and type2 (or an equivalent pair) have been passed to the put method previously.voidput(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror currentTop, boolean isSubtype) Put a visit fortype1,type2, andtopin the history.voidremove(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror currentTop) Removetype1andtype2.toString()
-
Constructor Details
-
SubtypeVisitHistory
public SubtypeVisitHistory()Creates a new SubtypeVisitHistory.
-
-
Method Details
-
put
public void put(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror currentTop, boolean isSubtype) Put a visit fortype1,type2, andtopin the history. Has no effect if isSubtype is false.- Parameters:
type1- the first typetype2- the second typecurrentTop- the top of the relevant type hierarchy; only annotations from that hierarchy are consideredisSubtype- true iftype1is a subtype oftype2; if false, this method does nothing
-
remove
public void remove(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror currentTop) Removetype1andtype2. -
contains
public boolean contains(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, AnnotationMirror currentTop) Returns true if type1 and type2 (or an equivalent pair) have been passed to the put method previously.- Returns:
- true if an equivalent pair has already been added to the history
-
clear
public void clear()Removes all entries from the history. -
toString
-