KickJava   Java API By Example, From Geeks To Geeks.

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


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

58 @SupportedSourceVersion(RELEASE_6)
59 public class SimpleTypeVisitor6<R, P> extends AbstractTypeVisitor6<R, P> {
60     /**
61      * Default value to be returned; {@link #defaultAction
62      * defaultAction} returns this value unless the method is
63      * overridden.
64      */

65     protected final R DEFAULT_VALUE;
66
67     /**
68      * Constructor for concrete subclasses; uses {@code null} for the
69      * default value.
70      */

71     protected SimpleTypeVisitor6(){
72     DEFAULT_VALUE = null;
73     }
74
75     /**
76      * Constructor for concrete subclasses; uses the argument for the
77      * default value.
78      *
79      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
80      */

81     protected SimpleTypeVisitor6(R defaultValue){
82     DEFAULT_VALUE = defaultValue;
83     }
84
85     /**
86      * The default action for visit methods. The implementation in
87      * this class just returns {@link #DEFAULT_VALUE}; subclasses will
88      * commonly override this method.
89      */

90     protected R defaultAction(TypeMirror e, P p) {
91     return DEFAULT_VALUE;
92     }
93
94     /**
95      * {@inheritDoc} This implementation calls {@code defaultAction}.
96      *
97      * @param t {@inheritDoc}
98      * @param p {@inheritDoc}
99      * @return the result of {@code defaultAction}
100      */

101     public R visitPrimitive(PrimitiveType t, P p) {
102     return defaultAction(t, p);
103     }
104
105     /**
106      * {@inheritDoc} This implementation calls {@code defaultAction}.
107      *
108      * @param t {@inheritDoc}
109      * @param p {@inheritDoc}
110      * @return the result of {@code defaultAction}
111      */

112     public R visitNull(NullType t, P p){
113     return defaultAction(t, p);
114     }
115
116     /**
117      * {@inheritDoc} This implementation calls {@code defaultAction}.
118      *
119      * @param t {@inheritDoc}
120      * @param p {@inheritDoc}
121      * @return the result of {@code defaultAction}
122      */

123     public R visitArray(ArrayType t, P p){
124     return defaultAction(t, p);
125     }
126
127     /**
128      * {@inheritDoc} This implementation calls {@code defaultAction}.
129      *
130      * @param t {@inheritDoc}
131      * @param p {@inheritDoc}
132      * @return the result of {@code defaultAction}
133      */

134     public R visitDeclared(DeclaredType t, P p){
135     return defaultAction(t, p);
136     }
137
138     /**
139      * {@inheritDoc} This implementation calls {@code defaultAction}.
140      *
141      * @param t {@inheritDoc}
142      * @param p {@inheritDoc}
143      * @return the result of {@code defaultAction}
144      */

145     public R visitError(ErrorType t, P p){
146     return defaultAction(t, p);
147     }
148
149     /**
150      * {@inheritDoc} This implementation calls {@code defaultAction}.
151      *
152      * @param t {@inheritDoc}
153      * @param p {@inheritDoc}
154      * @return the result of {@code defaultAction}
155      */

156     public R visitTypeVariable(TypeVariable t, P p){
157     return defaultAction(t, p);
158     }
159
160     /**
161      * {@inheritDoc} This implementation calls {@code defaultAction}.
162      *
163      * @param t {@inheritDoc}
164      * @param p {@inheritDoc}
165      * @return the result of {@code defaultAction}
166      */

167     public R visitWildcard(WildcardType t, P p){
168     return defaultAction(t, p);
169     }
170
171     /**
172      * {@inheritDoc} This implementation calls {@code defaultAction}.
173      *
174      * @param t {@inheritDoc}
175      * @param p {@inheritDoc}
176      * @return the result of {@code defaultAction}
177      */

178     public R visitExecutable(ExecutableType t, P p) {
179     return defaultAction(t, p);
180     }
181     
182     /**
183      * {@inheritDoc} This implementation calls {@code defaultAction}.
184      *
185      * @param t {@inheritDoc}
186      * @param p {@inheritDoc}
187      * @return the result of {@code defaultAction}
188      */

189     public R visitNoType(NoType t, P p){
190     return defaultAction(t, p);
191     }
192 }
193
Popular Tags