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.element.*;
029: import javax.annotation.processing.SupportedSourceVersion;
030: import static javax.lang.model.element.ElementKind.*;
031: import javax.lang.model.SourceVersion;
032: import static javax.lang.model.SourceVersion.*;
033:
034: /**
035: * A simple visitor of program elements with default behavior
036: * appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
037: * source version.
038: *
039: * Visit methods corresponding to {@code RELEASE_6} language
040: * constructs call {@link #defaultAction}, passing their arguments to
041: * {@code defaultAction}'s corresponding parameters.
042: *
043: * <p> Methods in this class may be overridden subject to their
044: * general contract. Note that annotating methods in concrete
045: * subclasses with {@link java.lang.Override @Override} will help
046: * ensure that methods are overridden as intended.
047: *
048: * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
049: * implemented by this class may have methods added to it in the
050: * future to accommodate new, currently unknown, language structures
051: * added to future versions of the Java™ programming language.
052: * Therefore, methods whose names begin with {@code "visit"} may be
053: * added to this class in the future; to avoid incompatibilities,
054: * classes which extend this class should not declare any instance
055: * methods with names beginning with {@code "visit"}.
056: *
057: * <p>When such a new visit method is added, the default
058: * implementation in this class will be to call the {@link
059: * #visitUnknown visitUnknown} method. A new simple element visitor
060: * class will also be introduced to correspond to the new language
061: * level; this visitor will have different default behavior for the
062: * visit method in question. When the new visitor is introduced, all
063: * or portions of this visitor may be deprecated.
064: *
065: * @param <R> the return type of this visitor's methods. Use {@code Void}
066: * for visitors that do not need to return results.
067: * @param <P> the type of the additional parameter to this visitor's methods. Use {@code Void}
068: * for visitors that do not need an additional parameter.
069: *
070: * @author Joseph D. Darcy
071: * @author Scott Seligman
072: * @author Peter von der Ahé
073: * @version 1.13 07/05/05
074: * @since 1.6
075: */
076: @SupportedSourceVersion(RELEASE_6)
077: public class SimpleElementVisitor6<R, P> extends
078: AbstractElementVisitor6<R, P> {
079: /**
080: * Default value to be returned; {@link #defaultAction
081: * defaultAction} returns this value unless the method is
082: * overridden.
083: */
084: protected final R DEFAULT_VALUE;
085:
086: /**
087: * Constructor for concrete subclasses; uses {@code null} for the
088: * default value.
089: */
090: protected SimpleElementVisitor6() {
091: DEFAULT_VALUE = null;
092: }
093:
094: /**
095: * Constructor for concrete subclasses; uses the argument for the
096: * default value.
097: *
098: * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
099: */
100: protected SimpleElementVisitor6(R defaultValue) {
101: DEFAULT_VALUE = defaultValue;
102: }
103:
104: /**
105: * The default action for visit methods. The implementation in
106: * this class just returns {@link #DEFAULT_VALUE}; subclasses will
107: * commonly override this method.
108: *
109: * @param e the element to process
110: * @param p a visitor-specified parameter
111: * @return {@code DEFAULT_VALUE} unless overridden
112: */
113: protected R defaultAction(Element e, P p) {
114: return DEFAULT_VALUE;
115: }
116:
117: /**
118: * {@inheritDoc} This implementation calls {@code defaultAction}.
119: *
120: * @param e {@inheritDoc}
121: * @param p {@inheritDoc}
122: * @return the result of {@code defaultAction}
123: */
124: public R visitPackage(PackageElement e, P p) {
125: return defaultAction(e, p);
126: }
127:
128: /**
129: * {@inheritDoc} This implementation calls {@code defaultAction}.
130: *
131: * @param e {@inheritDoc}
132: * @param p {@inheritDoc}
133: * @return the result of {@code defaultAction}
134: */
135: public R visitType(TypeElement e, P p) {
136: return defaultAction(e, p);
137: }
138:
139: /**
140: * {@inheritDoc} This implementation calls {@code defaultAction}.
141: *
142: * @param e {@inheritDoc}
143: * @param p {@inheritDoc}
144: * @return the result of {@code defaultAction}
145: */
146: public R visitVariable(VariableElement e, P p) {
147: return defaultAction(e, p);
148: }
149:
150: /**
151: * {@inheritDoc} This implementation calls {@code defaultAction}.
152: *
153: * @param e {@inheritDoc}
154: * @param p {@inheritDoc}
155: * @return the result of {@code defaultAction}
156: */
157: public R visitExecutable(ExecutableElement e, P p) {
158: return defaultAction(e, p);
159: }
160:
161: /**
162: * {@inheritDoc} This implementation calls {@code defaultAction}.
163: *
164: * @param e {@inheritDoc}
165: * @param p {@inheritDoc}
166: * @return the result of {@code defaultAction}
167: */
168: public R visitTypeParameter(TypeParameterElement e, P p) {
169: return defaultAction(e, p);
170: }
171: }
|