01: package com.sun.istack.tools;
02:
03: import com.sun.mirror.type.TypeMirror;
04: import com.sun.mirror.type.ArrayType;
05: import com.sun.mirror.type.ClassType;
06: import com.sun.mirror.type.InterfaceType;
07: import com.sun.mirror.type.TypeVariable;
08: import com.sun.mirror.type.VoidType;
09: import com.sun.mirror.type.WildcardType;
10: import com.sun.mirror.type.PrimitiveType;
11:
12: /**
13: * Visitor that works on APT {@link TypeMirror} and computes a value.
14: *
15: * <p>
16: * This visitor takes a parameter 'P' so that visitor code can be made stateless.
17: *
18: * @author Kohsuke Kawaguchi
19: */
20: public abstract class APTTypeVisitor<T, P> {
21: public final T apply(TypeMirror type, P param) {
22: if (type instanceof ArrayType)
23: return onArrayType((ArrayType) type, param);
24: if (type instanceof PrimitiveType)
25: return onPrimitiveType((PrimitiveType) type, param);
26: if (type instanceof ClassType)
27: return onClassType((ClassType) type, param);
28: if (type instanceof InterfaceType)
29: return onInterfaceType((InterfaceType) type, param);
30: if (type instanceof TypeVariable)
31: return onTypeVariable((TypeVariable) type, param);
32: if (type instanceof VoidType)
33: return onVoidType((VoidType) type, param);
34: if (type instanceof WildcardType)
35: return onWildcard((WildcardType) type, param);
36: assert false;
37: throw new IllegalArgumentException();
38: }
39:
40: protected abstract T onPrimitiveType(PrimitiveType type, P param);
41:
42: protected abstract T onArrayType(ArrayType type, P param);
43:
44: protected abstract T onClassType(ClassType type, P param);
45:
46: protected abstract T onInterfaceType(InterfaceType type, P param);
47:
48: protected abstract T onTypeVariable(TypeVariable type, P param);
49:
50: protected abstract T onVoidType(VoidType type, P param);
51:
52: protected abstract T onWildcard(WildcardType type, P param);
53:
54: }
|