001: /*
002: * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package javax.lang.model.util;
027:
028: import javax.lang.model.type.*;
029: import javax.annotation.processing.SupportedSourceVersion;
030: import javax.lang.model.SourceVersion;
031: import static javax.lang.model.SourceVersion.*;
032:
033: /**
034: * A simple visitor of types with default behavior appropriate for the
035: * {@link SourceVersion#RELEASE_6 RELEASE_6} source version.
036: *
037: * Visit methods corresponding to {@code RELEASE_6} language
038: * constructs call {@link #defaultAction}, passing their arguments to
039: * {@code defaultAction}'s corresponding parameters.
040: *
041: * <p> Methods in this class may be overridden subject to their
042: * general contract. Note that annotating methods in concrete
043: * subclasses with {@link java.lang.Override @Override} will help
044: * ensure that methods are overridden as intended.
045: *
046: * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented
047: * by this class may have methods added to it in the future to
048: * accommodate new, currently unknown, language structures added to
049: * future versions of the Java™ programming language.
050: * Therefore, methods whose names begin with {@code "visit"} may be
051: * added to this class in the future; to avoid incompatibilities,
052: * classes which extend this class should not declare any instance
053: * methods with names beginning with {@code "visit"}.
054: *
055: * <p>When such a new visit method is added, the default
056: * implementation in this class will be to call the {@link
057: * #visitUnknown visitUnknown} method. A new simple type visitor
058: * class will also be introduced to correspond to the new language
059: * level; this visitor will have different default behavior for the
060: * visit method in question. When the new visitor is introduced, all
061: * or portions of this visitor may be deprecated.
062: *
063: * @param <R> the return type of this visitor's methods. Use {@link
064: * Void} for visitors that do not need to return results.
065: * @param <P> the type of the additional parameter to this visitor's
066: * methods. Use {@code Void} for visitors that do not need an
067: * additional parameter.
068: *
069: * @author Joseph D. Darcy
070: * @author Scott Seligman
071: * @author Peter von der Ahé
072: * @version 1.13 07/05/05
073: * @since 1.6
074: */
075: @SupportedSourceVersion(RELEASE_6)
076: public class SimpleTypeVisitor6<R, P> extends
077: AbstractTypeVisitor6<R, P> {
078: /**
079: * Default value to be returned; {@link #defaultAction
080: * defaultAction} returns this value unless the method is
081: * overridden.
082: */
083: protected final R DEFAULT_VALUE;
084:
085: /**
086: * Constructor for concrete subclasses; uses {@code null} for the
087: * default value.
088: */
089: protected SimpleTypeVisitor6() {
090: DEFAULT_VALUE = null;
091: }
092:
093: /**
094: * Constructor for concrete subclasses; uses the argument for the
095: * default value.
096: *
097: * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
098: */
099: protected SimpleTypeVisitor6(R defaultValue) {
100: DEFAULT_VALUE = defaultValue;
101: }
102:
103: /**
104: * The default action for visit methods. The implementation in
105: * this class just returns {@link #DEFAULT_VALUE}; subclasses will
106: * commonly override this method.
107: */
108: protected R defaultAction(TypeMirror e, P p) {
109: return DEFAULT_VALUE;
110: }
111:
112: /**
113: * {@inheritDoc} This implementation calls {@code defaultAction}.
114: *
115: * @param t {@inheritDoc}
116: * @param p {@inheritDoc}
117: * @return the result of {@code defaultAction}
118: */
119: public R visitPrimitive(PrimitiveType t, P p) {
120: return defaultAction(t, p);
121: }
122:
123: /**
124: * {@inheritDoc} This implementation calls {@code defaultAction}.
125: *
126: * @param t {@inheritDoc}
127: * @param p {@inheritDoc}
128: * @return the result of {@code defaultAction}
129: */
130: public R visitNull(NullType t, P p) {
131: return defaultAction(t, p);
132: }
133:
134: /**
135: * {@inheritDoc} This implementation calls {@code defaultAction}.
136: *
137: * @param t {@inheritDoc}
138: * @param p {@inheritDoc}
139: * @return the result of {@code defaultAction}
140: */
141: public R visitArray(ArrayType t, P p) {
142: return defaultAction(t, p);
143: }
144:
145: /**
146: * {@inheritDoc} This implementation calls {@code defaultAction}.
147: *
148: * @param t {@inheritDoc}
149: * @param p {@inheritDoc}
150: * @return the result of {@code defaultAction}
151: */
152: public R visitDeclared(DeclaredType t, P p) {
153: return defaultAction(t, p);
154: }
155:
156: /**
157: * {@inheritDoc} This implementation calls {@code defaultAction}.
158: *
159: * @param t {@inheritDoc}
160: * @param p {@inheritDoc}
161: * @return the result of {@code defaultAction}
162: */
163: public R visitError(ErrorType t, P p) {
164: return defaultAction(t, p);
165: }
166:
167: /**
168: * {@inheritDoc} This implementation calls {@code defaultAction}.
169: *
170: * @param t {@inheritDoc}
171: * @param p {@inheritDoc}
172: * @return the result of {@code defaultAction}
173: */
174: public R visitTypeVariable(TypeVariable t, P p) {
175: return defaultAction(t, p);
176: }
177:
178: /**
179: * {@inheritDoc} This implementation calls {@code defaultAction}.
180: *
181: * @param t {@inheritDoc}
182: * @param p {@inheritDoc}
183: * @return the result of {@code defaultAction}
184: */
185: public R visitWildcard(WildcardType t, P p) {
186: return defaultAction(t, p);
187: }
188:
189: /**
190: * {@inheritDoc} This implementation calls {@code defaultAction}.
191: *
192: * @param t {@inheritDoc}
193: * @param p {@inheritDoc}
194: * @return the result of {@code defaultAction}
195: */
196: public R visitExecutable(ExecutableType t, P p) {
197: return defaultAction(t, p);
198: }
199:
200: /**
201: * {@inheritDoc} This implementation calls {@code defaultAction}.
202: *
203: * @param t {@inheritDoc}
204: * @param p {@inheritDoc}
205: * @return the result of {@code defaultAction}
206: */
207: public R visitNoType(NoType t, P p) {
208: return defaultAction(t, p);
209: }
210: }
|