Package com.google.common.reflect
Class TypeVisitor
- java.lang.Object
-
- com.google.common.reflect.TypeVisitor
-
- Direct Known Subclasses:
TypeResolver.TypeMappingIntrospector
abstract class TypeVisitor extends java.lang.ObjectBased on what aTypeis, dispatch it to the correspondingvisit*method. By default, no recursion is done for type arguments or type bounds. But subclasses can opt to do recursion by callingvisit(java.lang.reflect.Type...)for anyTypewhile visitation is in progress. For example, this can be used to reject wildcards or type variables contained in a type as in:new TypeVisitor() { protected void visitParameterizedType(ParameterizedType t) { visit(t.getOwnerType()); visit(t.getActualTypeArguments()); } protected void visitGenericArrayType(GenericArrayType t) { visit(t.getGenericComponentType()); } protected void visitTypeVariable(TypeVariable<?> t) { throw new IllegalArgumentException("Cannot contain type variable."); } protected void visitWildcardType(WildcardType t) { throw new IllegalArgumentException("Cannot contain wildcard type."); } }.visit(type);One
Typeis visited at most once. The second time the same type is visited, it's ignored byvisit(java.lang.reflect.Type...). This avoids infinite recursion caused by recursive type bounds.This class is not thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.reflect.Type>visited
-
Constructor Summary
Constructors Constructor Description TypeVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidvisit(java.lang.reflect.Type... types)Visits the given types.(package private) voidvisitClass(java.lang.Class<?> t)(package private) voidvisitGenericArrayType(java.lang.reflect.GenericArrayType t)(package private) voidvisitParameterizedType(java.lang.reflect.ParameterizedType t)(package private) voidvisitTypeVariable(java.lang.reflect.TypeVariable<?> t)(package private) voidvisitWildcardType(java.lang.reflect.WildcardType t)
-
-
-
Method Detail
-
visit
public final void visit(java.lang.reflect.Type... types)
Visits the given types. Null types are ignored. This allows subclasses to callvisit(parameterizedType.getOwnerType())safely without having to check nulls.
-
visitClass
void visitClass(java.lang.Class<?> t)
-
visitGenericArrayType
void visitGenericArrayType(java.lang.reflect.GenericArrayType t)
-
visitParameterizedType
void visitParameterizedType(java.lang.reflect.ParameterizedType t)
-
visitTypeVariable
void visitTypeVariable(java.lang.reflect.TypeVariable<?> t)
-
visitWildcardType
void visitWildcardType(java.lang.reflect.WildcardType t)
-
-