Top Description Fields Constructors Methods
com.google.common.reflect

pack-priv abstract Class TypeVisitor

extends Object
Class Inheritance
Known Direct Subclasses
com.google.common.reflect.TypeResolver.TypeMappingIntrospector
Annotations
@ElementTypesAreNonnullByDefault
Imports
com.google.common.collect.Sets, java.lang.reflect.GenericArrayType, .ParameterizedType, .Type, .TypeVariable, .WildcardType, java.util.Set, org.checkerframework.checker.nullness.qual.Nullable

Based on what a Type is, dispatch it to the corresponding visit* method. By default, no recursion is done for type arguments or type bounds. But subclasses can opt to do recursion by calling visit for any Type while 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 Type is visited at most once. The second time the same type is visited, it's ignored by visit. This avoids infinite recursion caused by recursive type bounds.

This class is not thread safe.

Author
Ben Yu

Field Summary

Modifier and TypeField and Description
private final Set<Type>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final void
visit(@Nullable Type... types)

Visits the given types.

pack-priv void
pack-priv void
pack-priv void
pack-priv void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

visitedback to summary
private final Set<Type> visited

Constructor Detail

TypeVisitorback to summary
pack-priv TypeVisitor()

Method Detail

visitback to summary
public final void visit(@Nullable Type... types)

Visits the given types. Null types are ignored. This allows subclasses to call visit(parameterizedType.getOwnerType()) safely without having to check nulls.

visitClassback to summary
pack-priv void visitClass(Class<?> t)
visitGenericArrayTypeback to summary
pack-priv void visitGenericArrayType(GenericArrayType t)
visitParameterizedTypeback to summary
pack-priv void visitParameterizedType(ParameterizedType t)
visitTypeVariableback to summary
pack-priv void visitTypeVariable(TypeVariable<?> t)
visitWildcardTypeback to summary
pack-priv void visitWildcardType(WildcardType t)