KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > lang > model > util > TypeKindVisitor6


1 /*
2  * @(#)TypeKindVisitor6.java 1.6 06/08/07
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.util;
9
10
11 import javax.lang.model.type.*;
12 import javax.annotation.processing.SupportedSourceVersion;
13 import static javax.lang.model.element.ElementKind.*;
14 import static javax.lang.model.SourceVersion.*;
15 import javax.lang.model.SourceVersion;
16
17 /**
18  * A visitor of types based on their {@linkplain TypeKind kind} with
19  * default behavior appropriate for the {@link SourceVersion#RELEASE_6
20  * RELEASE_6} source version. For {@linkplain
21  * TypeMirror types} <tt><i>XYZ</i></tt> that may have more than one
22  * kind, the <tt>visit<i>XYZ</i></tt> methods in this class delegate
23  * to the <tt>visit<i>XYZKind</i></tt> method corresponding to the
24  * first argument's kind. The <tt>visit<i>XYZKind</i></tt> methods
25  * call {@link #defaultAction defaultAction}, passing their arguments
26  * to {@code defaultAction}'s corresponding parameters.
27  *
28  * <p> Methods in this class may be overridden subject to their
29  * general contract. Note that annotating methods in concrete
30  * subclasses with {@link java.lang.Override @Override} will help
31  * ensure that methods are overridden as intended.
32  *
33  * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented
34  * by this class may have methods added to it in the future to
35  * accommodate new, currently unknown, language structures added to
36  * future versions of the Java&trade; programming language.
37  * Therefore, methods whose names begin with {@code "visit"} may be
38  * added to this class in the future; to avoid incompatibilities,
39  * classes which extend this class should not declare any instance
40  * methods with names beginning with {@code "visit"}.
41  *
42  * <p>When such a new visit method is added, the default
43  * implementation in this class will be to call the {@link
44  * #visitUnknown visitUnknown} method. A new type kind visitor class
45  * will also be introduced to correspond to the new language level;
46  * this visitor will have different default behavior for the visit
47  * method in question. When the new visitor is introduced, all or
48  * portions of this visitor may be deprecated.
49  *
50  * @param <R> the return type of this visitor's methods. Use {@link
51  * Void} for visitors that do not need to return results.
52  * @param <P> the type of the additional parameter to this visitor's
53  * methods. Use {@code Void} for visitors that do not need an
54  * additional parameter.
55  *
56  * @author Joseph D. Darcy
57  * @author Scott Seligman
58  * @author Peter von der Ah&eacute;
59  * @version 1.6 06/08/07
60  * @since 1.6
61  */

62 @SupportedSourceVersion(RELEASE_6)
63 public class TypeKindVisitor6<R, P> extends SimpleTypeVisitor6<R, P> {
64     /**
65      * Constructor for concrete subclasses to call; uses {@code null}
66      * for the default value.
67      */

68     protected TypeKindVisitor6() {
69     super(null);
70     }
71     
72
73     /**
74      * Constructor for concrete subclasses to call; uses the argument
75      * for the default value.
76      *
77      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
78      */

79     protected TypeKindVisitor6(R defaultValue) {
80     super(defaultValue);
81     }
82
83     /**
84      * Visits a primitive type, dispatching to the visit method for
85      * the specific {@linkplain TypeKind kind} of primitive type:
86      * {@code BOOLEAN}, {@code BYTE}, etc.
87      *
88      * @param t {@inheritDoc}
89      * @param p {@inheritDoc}
90      * @return the result of the kind-specific visit method
91      */

92     @Override JavaDoc
93     public R visitPrimitive(PrimitiveType t, P p) {
94     TypeKind k = t.getKind();
95     switch (k) {
96     case BOOLEAN:
97         return visitPrimitiveAsBoolean(t, p);
98
99     case BYTE:
100         return visitPrimitiveAsByte(t, p);
101         
102     case SHORT:
103         return visitPrimitiveAsShort(t, p);
104         
105     case INT:
106         return visitPrimitiveAsInt(t, p);
107         
108     case LONG:
109         return visitPrimitiveAsLong(t, p);
110         
111     case CHAR:
112         return visitPrimitiveAsChar(t, p);
113         
114     case FLOAT:
115         return visitPrimitiveAsFloat(t, p);
116         
117     case DOUBLE:
118         return visitPrimitiveAsDouble(t, p);
119         
120     default:
121         throw new AssertionError JavaDoc("Bad kind " + k + " for PrimitiveType" + t);
122     }
123     }
124
125     /**
126      * Visits a {@code BOOLEAN} primitive type by calling
127      * {@code defaultAction}.
128      *
129      * @param t the type to visit
130      * @param p a visitor-specified parameter
131      * @return the result of {@code defaultAction}
132      */

133     public R visitPrimitiveAsBoolean(PrimitiveType t, P p) {
134     return defaultAction(t, p);
135     }
136
137     /**
138      * Visits a {@code BYTE} primitive type by calling
139      * {@code defaultAction}.
140      *
141      * @param t the type to visit
142      * @param p a visitor-specified parameter
143      * @return the result of {@code defaultAction}
144      */

145     public R visitPrimitiveAsByte(PrimitiveType t, P p) {
146     return defaultAction(t, p);
147     }
148
149     /**
150      * Visits a {@code SHORT} primitive type by calling
151      * {@code defaultAction}.
152      *
153      * @param t the type to visit
154      * @param p a visitor-specified parameter
155      * @return the result of {@code defaultAction}
156      */

157     public R visitPrimitiveAsShort(PrimitiveType t, P p) {
158     return defaultAction(t, p);
159     }
160     
161     /**
162      * Visits an {@code INT} primitive type by calling
163      * {@code defaultAction}.
164      *
165      * @param t the type to visit
166      * @param p a visitor-specified parameter
167      * @return the result of {@code defaultAction}
168      */

169     public R visitPrimitiveAsInt(PrimitiveType t, P p) {
170     return defaultAction(t, p);
171     }
172     
173     /**
174      * Visits a {@code LONG} primitive type by calling
175      * {@code defaultAction}.
176      *
177      * @param t the type to visit
178      * @param p a visitor-specified parameter
179      * @return the result of {@code defaultAction}
180      */

181     public R visitPrimitiveAsLong(PrimitiveType t, P p) {
182     return defaultAction(t, p);
183     }
184     
185     /**
186      * Visits a {@code CHAR} primitive type by calling
187      * {@code defaultAction}.
188      *
189      * @param t the type to visit
190      * @param p a visitor-specified parameter
191      * @return the result of {@code defaultAction}
192      */

193     public R visitPrimitiveAsChar(PrimitiveType t, P p) {
194     return defaultAction(t, p);
195     }
196     
197     /**
198      * Visits a {@code FLOAT} primitive type by calling
199      * {@code defaultAction}.
200      *
201      * @param t the type to visit
202      * @param p a visitor-specified parameter
203      * @return the result of {@code defaultAction}
204      */

205     public R visitPrimitiveAsFloat(PrimitiveType t, P p) {
206     return defaultAction(t, p);
207     }
208     
209     /**
210      * Visits a {@code DOUBLE} primitive type by calling
211      * {@code defaultAction}.
212      *
213      * @param t the type to visit
214      * @param p a visitor-specified parameter
215      * @return the result of {@code defaultAction}
216      */

217     public R visitPrimitiveAsDouble(PrimitiveType t, P p) {
218     return defaultAction(t, p);
219     }
220
221     /**
222      * Visits a {@link NoType} instance, dispatching to the visit method for
223      * the specific {@linkplain TypeKind kind} of pseudo-type:
224      * {@code VOID}, {@code PACKAGE}, or {@code NONE}.
225      *
226      * @param t {@inheritDoc}
227      * @param p {@inheritDoc}
228      * @return the result of the kind-specific visit method
229      */

230     @Override JavaDoc
231     public R visitNoType(NoType t, P p) {
232     TypeKind k = t.getKind();
233     switch (k) {
234     case VOID:
235         return visitNoTypeAsVoid(t, p);
236
237     case PACKAGE:
238         return visitNoTypeAsPackage(t, p);
239         
240     case NONE:
241         return visitNoTypeAsNone(t, p);
242         
243     default:
244         throw new AssertionError JavaDoc("Bad kind " + k + " for NoType" + t);
245     }
246     }
247     
248     /**
249      * Visits a {@link TypeKind#VOID VOID} pseudo-type by calling
250      * {@code defaultAction}.
251      *
252      * @param t the type to visit
253      * @param p a visitor-specified parameter
254      * @return the result of {@code defaultAction}
255      */

256     public R visitNoTypeAsVoid(NoType t, P p) {
257     return defaultAction(t, p);
258     }
259     
260     /**
261      * Visits a {@link TypeKind#PACKAGE PACKAGE} pseudo-type by calling
262      * {@code defaultAction}.
263      *
264      * @param t the type to visit
265      * @param p a visitor-specified parameter
266      * @return the result of {@code defaultAction}
267      */

268     public R visitNoTypeAsPackage(NoType t, P p) {
269     return defaultAction(t, p);
270     }
271     
272     /**
273      * Visits a {@link TypeKind#NONE NONE} pseudo-type by calling
274      * {@code defaultAction}.
275      *
276      * @param t the type to visit
277      * @param p a visitor-specified parameter
278      * @return the result of {@code defaultAction}
279      */

280     public R visitNoTypeAsNone(NoType t, P p) {
281     return defaultAction(t, p);
282     }
283 }
284
Popular Tags