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.element;
027
028 import java.util.List;
029
030 import javax.lang.model.type.TypeMirror;
031
032 /**
033 * A visitor of the values of annotation type elements, using a
034 * variant of the visitor design pattern. Unlike a standard visitor
035 * which dispatches based on the concrete type of a member of a type
036 * hierarchy, this visitor dispatches based on the type of data
037 * stored; there are no distinct subclasses for storing, for example,
038 * {@code boolean} values versus {@code int} values. Classes
039 * implementing this interface are used to operate on a value when the
040 * type of that value is unknown at compile time. When a visitor is
041 * passed to a value's {@link AnnotationValue#accept accept} method,
042 * the <tt>visit<i>XYZ</i></tt> method applicable to that value is
043 * invoked.
044 *
045 * <p> Classes implementing this interface may or may not throw a
046 * {@code NullPointerException} if the additional parameter {@code p}
047 * is {@code null}; see documentation of the implementing class for
048 * details.
049 *
050 * <p> <b>WARNING:</b> It is possible that methods will be added to
051 * this interface to accommodate new, currently unknown, language
052 * structures added to future versions of the Java™ programming
053 * language. Therefore, visitor classes directly implementing this
054 * interface may be source incompatible with future versions of the
055 * platform. To avoid this source incompatibility, visitor
056 * implementations are encouraged to instead extend the appropriate
057 * abstract visitor class that implements this interface. However, an
058 * API should generally use this visitor interface as the type for
059 * parameters, return type, etc. rather than one of the abstract
060 * classes.
061 *
062 * @param <R> the return type of this visitor's methods
063 * @param <P> the type of the additional parameter to this visitor's methods.
064 * @author Joseph D. Darcy
065 * @author Scott Seligman
066 * @author Peter von der Ahé
067 * @version 1.12 07/05/05
068 * @since 1.6
069 */
070 public interface AnnotationValueVisitor<R, P> {
071 /**
072 * Visits an annotation value.
073 * @param av the value to visit
074 * @param p a visitor-specified parameter
075 * @return a visitor-specified result
076 */
077 R visit(AnnotationValue av, P p);
078
079 /**
080 * A convenience method equivalent to {@code v.visit(av, null)}.
081 * @param av the value to visit
082 * @return a visitor-specified result
083 */
084 R visit(AnnotationValue av);
085
086 /**
087 * Visits a {@code boolean} value in an annotation.
088 * @param b the value being visited
089 * @param p a visitor-specified parameter
090 * @return the result of the visit
091 */
092 R visitBoolean(boolean b, P p);
093
094 /**
095 * Visits a {@code byte} value in an annotation.
096 * @param b the value being visited
097 * @param p a visitor-specified parameter
098 * @return the result of the visit
099 */
100 R visitByte(byte b, P p);
101
102 /**
103 * Visits a {@code char} value in an annotation.
104 * @param c the value being visited
105 * @param p a visitor-specified parameter
106 * @return the result of the visit
107 */
108 R visitChar(char c, P p);
109
110 /**
111 * Visits a {@code double} value in an annotation.
112 * @param d the value being visited
113 * @param p a visitor-specified parameter
114 * @return the result of the visit
115 */
116 R visitDouble(double d, P p);
117
118 /**
119 * Visits a {@code float} value in an annotation.
120 * @param f the value being visited
121 * @param p a visitor-specified parameter
122 * @return the result of the visit
123 */
124 R visitFloat(float f, P p);
125
126 /**
127 * Visits an {@code int} value in an annotation.
128 * @param i the value being visited
129 * @param p a visitor-specified parameter
130 * @return the result of the visit
131 */
132 R visitInt(int i, P p);
133
134 /**
135 * Visits a {@code long} value in an annotation.
136 * @param i the value being visited
137 * @param p a visitor-specified parameter
138 * @return the result of the visit
139 */
140 R visitLong(long i, P p);
141
142 /**
143 * Visits a {@code short} value in an annotation.
144 * @param s the value being visited
145 * @param p a visitor-specified parameter
146 * @return the result of the visit
147 */
148 R visitShort(short s, P p);
149
150 /**
151 * Visits a string value in an annotation.
152 * @param s the value being visited
153 * @param p a visitor-specified parameter
154 * @return the result of the visit
155 */
156 R visitString(String s, P p);
157
158 /**
159 * Visits a type value in an annotation.
160 * @param t the value being visited
161 * @param p a visitor-specified parameter
162 * @return the result of the visit
163 */
164 R visitType(TypeMirror t, P p);
165
166 /**
167 * Visits an {@code enum} value in an annotation.
168 * @param c the value being visited
169 * @param p a visitor-specified parameter
170 * @return the result of the visit
171 */
172 R visitEnumConstant(VariableElement c, P p);
173
174 /**
175 * Visits an annotation value in an annotation.
176 * @param a the value being visited
177 * @param p a visitor-specified parameter
178 * @return the result of the visit
179 */
180 R visitAnnotation(AnnotationMirror a, P p);
181
182 /**
183 * Visits an array value in an annotation.
184 * @param vals the value being visited
185 * @param p a visitor-specified parameter
186 * @return the result of the visit
187 */
188 R visitArray(List<? extends AnnotationValue> vals, P p);
189
190 /**
191 * Visits an unknown kind of annotation value.
192 * This can occur if the language evolves and new kinds
193 * of value can be stored in an annotation.
194 * @param av the unknown value being visited
195 * @param p a visitor-specified parameter
196 * @return the result of the visit
197 * @throws UnknownAnnotationValueException
198 * a visitor implementation may optionally throw this exception
199 */
200 R visitUnknown(AnnotationValue av, P p);
201 }
|