KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

82     protected SimpleElementVisitor6(R defaultValue){
83     DEFAULT_VALUE = defaultValue;
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      * @param e the element to process
91      * @param p a visitor-specified parameter
92      * @return {@code DEFAULT_VALUE} unless overridden
93      */

94     protected R defaultAction(Element e, P p) {
95     return DEFAULT_VALUE;
96     }
97
98     /**
99      * {@inheritDoc} This implementation calls {@code defaultAction}.
100      *
101      * @param e {@inheritDoc}
102      * @param p {@inheritDoc}
103      * @return the result of {@code defaultAction}
104      */

105     public R visitPackage(PackageElement e, P p) {
106     return defaultAction(e, p);
107     }
108
109     /**
110      * {@inheritDoc} This implementation calls {@code defaultAction}.
111      *
112      * @param e {@inheritDoc}
113      * @param p {@inheritDoc}
114      * @return the result of {@code defaultAction}
115      */

116     public R visitType(TypeElement e, P p) {
117     return defaultAction(e, p);
118     }
119
120     /**
121      * {@inheritDoc} This implementation calls {@code defaultAction}.
122      *
123      * @param e {@inheritDoc}
124      * @param p {@inheritDoc}
125      * @return the result of {@code defaultAction}
126      */

127     public R visitVariable(VariableElement e, P p) {
128     return defaultAction(e, p);
129     }
130
131     /**
132      * {@inheritDoc} This implementation calls {@code defaultAction}.
133      *
134      * @param e {@inheritDoc}
135      * @param p {@inheritDoc}
136      * @return the result of {@code defaultAction}
137      */

138     public R visitExecutable(ExecutableElement e, P p) {
139     return defaultAction(e, p);
140     }
141
142     /**
143      * {@inheritDoc} This implementation calls {@code defaultAction}.
144      *
145      * @param e {@inheritDoc}
146      * @param p {@inheritDoc}
147      * @return the result of {@code defaultAction}
148      */

149     public R visitTypeParameter(TypeParameterElement e, P p) {
150     return defaultAction(e, p);
151     }
152 }
153
Popular Tags