KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > lang > model > type > TypeVisitor


1 /*
2  * @(#)TypeVisitor.java 1.5 06/07/31
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.lang.model.type;
9
10 import javax.lang.model.element.*;
11
12 /**
13  * A visitor of types, in the style of the
14  * visitor design pattern. Classes implementing this
15  * interface are used to operate on a type when the kind of
16  * type is unknown at compile time. When a visitor is passed to a
17  * type's {@link TypeMirror#accept accept} method, the <tt>visit<i>XYZ</i></tt>
18  * method most applicable to that type is invoked.
19  *
20  * <p> Classes implementing this interface may or may not throw a
21  * {@code NullPointerException} if the additional parameter {@code p}
22  * is {@code null}; see documentation of the implementing class for
23  * details.
24  *
25  * <p> <b>WARNING:</b> It is possible that methods will be added to
26  * this interface to accommodate new, currently unknown, language
27  * structures added to future versions of the Java&trade; programming
28  * language. Therefore, visitor classes directly implementing this
29  * interface may be source incompatible with future versions of the
30  * platform. To avoid this source incompatibility, visitor
31  * implementations are encouraged to instead extend the appropriate
32  * abstract visitor class that implements this interface. However, an
33  * API should generally use this visitor interface as the type for
34  * parameters, return type, etc. rather than one of the abstract
35  * classes.
36  *
37  * @param <R> the return type of this visitor's methods. Use {@link
38  * Void} for visitors that do not need to return results.
39  * @param <P> the type of the additional parameter to this visitor's
40  * methods. Use {@code Void} for visitors that do not need an
41  * additional parameter.
42  *
43  * @author Joseph D. Darcy
44  * @author Scott Seligman
45  * @author Peter von der Ah&eacute;
46  * @version 1.5 06/07/31
47  * @since 1.6
48  */

49 public interface TypeVisitor<R, P> {
50     /**
51      * Visits a type.
52      * @param t the type to visit
53      * @param p a visitor-specified parameter
54      * @return a visitor-specified result
55      */

56     R visit(TypeMirror t, P p);
57
58     /**
59      * A convenience method equivalent to {@code v.visit(t, null)}.
60      * @param t the element to visit
61      * @return a visitor-specified result
62      */

63     R visit(TypeMirror t);
64
65     /**
66      * Visits a primitive type.
67      * @param t the type to visit
68      * @param p a visitor-specified parameter
69      * @return a visitor-specified result
70      */

71     R visitPrimitive(PrimitiveType t, P p);
72
73     /**
74      * Visits the null type.
75      * @param t the type to visit
76      * @param p a visitor-specified parameter
77      * @return a visitor-specified result
78      */

79     R visitNull(NullType t, P p);
80
81     /**
82      * Visits an array type.
83      * @param t the type to visit
84      * @param p a visitor-specified parameter
85      * @return a visitor-specified result
86      */

87     R visitArray(ArrayType t, P p);
88
89     /**
90      * Visits a declared type.
91      * @param t the type to visit
92      * @param p a visitor-specified parameter
93      * @return a visitor-specified result
94      */

95     R visitDeclared(DeclaredType t, P p);
96
97     /**
98      * Visits an error type.
99      * @param t the type to visit
100      * @param p a visitor-specified parameter
101      * @return a visitor-specified result
102      */

103     R visitError(ErrorType t, P p);
104
105     /**
106      * Visits a type variable.
107      * @param t the type to visit
108      * @param p a visitor-specified parameter
109      * @return a visitor-specified result
110      */

111     R visitTypeVariable(TypeVariable t, P p);
112
113     /**
114      * Visits a wildcard type.
115      * @param t the type to visit
116      * @param p a visitor-specified parameter
117      * @return a visitor-specified result
118      */

119     R visitWildcard(WildcardType t, P p);
120
121     /**
122      * Visits an executable type.
123      * @param t the type to visit
124      * @param p a visitor-specified parameter
125      * @return a visitor-specified result
126      */

127     R visitExecutable(ExecutableType t, P p);
128
129     /**
130      * Visits a {@link NoType} instance.
131      * @param t the type to visit
132      * @param p a visitor-specified parameter
133      * @return a visitor-specified result
134      */

135     R visitNoType(NoType t, P p);
136
137     /**
138      * Visits an unknown kind of type.
139      * This can occur if the language evolves and new kinds
140      * of types are added to the {@code TypeMirror} hierarchy.
141      * @param t the type to visit
142      * @param p a visitor-specified parameter
143      * @return a visitor-specified result
144      * @throws UnknownTypeException
145      * a visitor implementation may optionally throw this exception
146      */

147     R visitUnknown(TypeMirror t, P p);
148 }
149
Popular Tags