KickJava   Java API By Example, From Geeks To Geeks.

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


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

53 @SupportedSourceVersion(RELEASE_6)
54 public abstract class AbstractElementVisitor6<R, P> implements ElementVisitor<R, P> {
55     /**
56      * Constructor for concrete subclasses to call.
57      */

58     protected AbstractElementVisitor6(){}
59
60     /**
61      * Visits any program element as if by passing itself to that
62      * element's {@link Element#accept accept} method. The invocation
63      * {@code v.visit(elem)} is equivalent to {@code elem.accept(v,
64      * p)}.
65      *
66      * @param e the element to visit
67      * @param p a visitor-specified parameter
68      * @return a visitor-specified result
69      */

70     public final R visit(Element e, P p) {
71     return e.accept(this, p);
72     }
73
74     /**
75      * Visits any program element as if by passing itself to that
76      * element's {@link Element#accept accept} method and passing
77      * {@code null} for the additional parameter. The invocation
78      * {@code v.visit(elem)} is equivalent to {@code elem.accept(v,
79      * null)}.
80      *
81      * @param e the element to visit
82      * @return a visitor-specified result
83      */

84     public final R visit(Element e) {
85     return e.accept(this, null);
86     }
87
88     /**
89      * {@inheritDoc}
90      *
91      * <p> The default implementation of this method in
92      * {@code AbstractElementVisitor6} will always throw
93      * {@code UnknownElementException}.
94      * This behavior is not required of a subclass.
95      *
96      * @param e the element to visit
97      * @param p a visitor-specified parameter
98      * @return a visitor-specified result
99      * @throws UnknownElementException
100      * a visitor implementation may optionally throw this exception
101      */

102     public R visitUnknown(Element e, P p) {
103     throw new UnknownElementException(e, p);
104     }
105 }
106
Popular Tags