KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > lang > model > element > ElementVisitor


1 /*
2  * @(#)ElementVisitor.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.element;
9
10 import javax.lang.model.util.*;
11
12 /**
13  * A visitor of program elements, in the style of the visitor design
14  * pattern. Classes implementing this interface are used to operate
15  * on an element when the kind of element is unknown at compile time.
16  * When a visitor is passed to an element's {@link Element#accept
17  * accept} method, the <tt>visit<i>XYZ</i></tt> method most applicable
18  * to that element is invoked.
19  *
20  * <p> Classes implementing this interface may or may not throw a
21  * {@code NullPointerException} if the additional parameter {@code p}
22  * is {@code null}; see documentation of the implementing class for
23  * details.
24  *
25  * <p> <b>WARNING:</b> It is possible that methods will be added to
26  * this interface to accommodate new, currently unknown, language
27  * structures added to future versions of the Java&trade; programming
28  * language. Therefore, visitor classes directly implementing this
29  * interface may be source incompatible with future versions of the
30  * platform. To avoid this source incompatibility, visitor
31  * implementations are encouraged to instead extend the appropriate
32  * abstract visitor class that implements this interface. However, an
33  * API should generally use this visitor interface as the type for
34  * parameters, return type, etc. rather than one of the abstract
35  * classes.
36  *
37  * @param <R> the return type of this visitor's methods. Use {@link
38  * Void} for visitors that do not need to return results.
39  * @param <P> the type of the additional parameter to this visitor's
40  * methods. Use {@code Void} for visitors that do not need an
41  * additional parameter.
42  *
43  * @author Joseph D. Darcy
44  * @author Scott Seligman
45  * @author Peter von der Ah&eacute;
46  * @version 1.4 06/07/31
47  * @see AbstractElementVisitor6
48  * @since 1.6
49  */

50 public interface ElementVisitor<R, P> {
51     /**
52      * Visits an element.
53      * @param e the element to visit
54      * @param p a visitor-specified parameter
55      * @return a visitor-specified result
56      */

57     R visit(Element e, P p);
58
59     /**
60      * A convenience method equivalent to {@code v.visit(e, null)}.
61      * @param e the element to visit
62      * @return a visitor-specified result
63      */

64     R visit(Element e);
65
66     /**
67      * Visits a package element.
68      * @param e the element to visit
69      * @param p a visitor-specified parameter
70      * @return a visitor-specified result
71      */

72     R visitPackage(PackageElement e, P p);
73
74     /**
75      * Visits a type element.
76      * @param e the element to visit
77      * @param p a visitor-specified parameter
78      * @return a visitor-specified result
79      */

80     R visitType(TypeElement e, P p);
81
82     /**
83      * Visits a variable element.
84      * @param e the element to visit
85      * @param p a visitor-specified parameter
86      * @return a visitor-specified result
87      */

88     R visitVariable(VariableElement e, P p);
89
90     /**
91      * Visits an executable element.
92      * @param e the element to visit
93      * @param p a visitor-specified parameter
94      * @return a visitor-specified result
95      */

96     R visitExecutable(ExecutableElement e, P p);
97
98     /**
99      * Visits a type parameter element.
100      * @param e the element to visit
101      * @param p a visitor-specified parameter
102      * @return a visitor-specified result
103      */

104     R visitTypeParameter(TypeParameterElement e, P p);
105
106     /**
107      * Visits an unknown kind of element.
108      * This can occur if the language evolves and new kinds
109      * of elements are added to the {@code Element} hierarchy.
110      *
111      * @param e the element to visit
112      * @param p a visitor-specified parameter
113      * @return a visitor-specified result
114      * @throws UnknownElementException
115      * a visitor implementation may optionally throw this exception
116      */

117     R visitUnknown(Element e, P p);
118 }
119
Popular Tags