AnnotationValueVisitor.java revision 3884:b6960e2da008
1109998Smarkm/* 268651Skris * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. 368651Skris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 468651Skris * 568651Skris * This code is free software; you can redistribute it and/or modify it 668651Skris * under the terms of the GNU General Public License version 2 only, as 768651Skris * published by the Free Software Foundation. Oracle designates this 8296465Sdelphij * particular file as subject to the "Classpath" exception as provided 968651Skris * by Oracle in the LICENSE file that accompanied this code. 1068651Skris * 1168651Skris * This code is distributed in the hope that it will be useful, but WITHOUT 1268651Skris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1368651Skris * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1468651Skris * version 2 for more details (a copy is included in the LICENSE file that 15296465Sdelphij * accompanied this code). 1668651Skris * 1768651Skris * You should have received a copy of the GNU General Public License version 1868651Skris * 2 along with this work; if not, write to the Free Software Foundation, 1968651Skris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2068651Skris * 2168651Skris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22296465Sdelphij * or visit www.oracle.com if you need additional information or have any 2368651Skris * questions. 2468651Skris */ 2568651Skris 2668651Skrispackage javax.lang.model.element; 2768651Skris 2868651Skris 2968651Skrisimport java.util.List; 3068651Skris 3168651Skrisimport javax.lang.model.type.TypeMirror; 3268651Skris 3368651Skris 3468651Skris/** 3568651Skris * A visitor of the values of annotation type elements, using a 3668651Skris * variant of the visitor design pattern. Unlike a standard visitor 37296465Sdelphij * which dispatches based on the concrete type of a member of a type 3868651Skris * hierarchy, this visitor dispatches based on the type of data 3968651Skris * stored; there are no distinct subclasses for storing, for example, 40296465Sdelphij * {@code boolean} values versus {@code int} values. Classes 4168651Skris * implementing this interface are used to operate on a value when the 4268651Skris * type of that value is unknown at compile time. When a visitor is 4368651Skris * passed to a value's {@link AnnotationValue#accept accept} method, 4468651Skris * the <code>visit<i>Xyz</i></code> method applicable to that value is 4568651Skris * invoked. 4668651Skris * 4768651Skris * <p> Classes implementing this interface may or may not throw a 4868651Skris * {@code NullPointerException} if the additional parameter {@code p} 4968651Skris * is {@code null}; see documentation of the implementing class for 5068651Skris * details. 5168651Skris * 52296465Sdelphij * <p> <b>WARNING:</b> It is possible that methods will be added to 5368651Skris * this interface to accommodate new, currently unknown, language 5468651Skris * structures added to future versions of the Java™ programming 5568651Skris * language. Therefore, visitor classes directly implementing this 5668651Skris * interface may be source incompatible with future versions of the 5768651Skris * platform. To avoid this source incompatibility, visitor 5868651Skris * implementations are encouraged to instead extend the appropriate 5968651Skris * abstract visitor class that implements this interface. However, an 6068651Skris * API should generally use this visitor interface as the type for 6168651Skris * parameters, return type, etc. rather than one of the abstract 6268651Skris * classes. 6368651Skris * 6468651Skris * <p>Note that methods to accommodate new language constructs could 6568651Skris * be added in a source <em>compatible</em> way if they were added as 66296465Sdelphij * <em>default methods</em>. However, default methods are only 6768651Skris * available on Java SE 8 and higher releases and the {@code 6868651Skris * javax.lang.model.*} packages bundled in Java SE 8 were required to 6968651Skris * also be runnable on Java SE 7. Therefore, default methods 7068651Skris * were <em>not</em> used when extending {@code javax.lang.model.*} 7168651Skris * to cover Java SE 8 language features. However, default methods may 7268651Skris * be used in subsequent revisions of the {@code javax.lang.model.*} 7368651Skris * packages that are only required to run on Java SE 8 and higher 7468651Skris * platform versions. 7568651Skris * 7668651Skris * @param <R> the return type of this visitor's methods 7768651Skris * @param <P> the type of the additional parameter to this visitor's methods. 7868651Skris * @author Joseph D. Darcy 7968651Skris * @author Scott Seligman 8068651Skris * @author Peter von der Ahé 8168651Skris * @since 1.6 8268651Skris */ 8368651Skrispublic interface AnnotationValueVisitor<R, P> { 8468651Skris /** 8568651Skris * Visits an annotation value. 8668651Skris * @param av the value to visit 8768651Skris * @param p a visitor-specified parameter 8868651Skris * @return a visitor-specified result 8968651Skris */ 9068651Skris R visit(AnnotationValue av, P p); 9168651Skris 9268651Skris /** 9368651Skris * A convenience method equivalent to {@code v.visit(av, null)}. 9468651Skris * @param av the value to visit 9568651Skris * @return a visitor-specified result 9668651Skris */ 9768651Skris R visit(AnnotationValue av); 9868651Skris 9968651Skris /** 10068651Skris * Visits a {@code boolean} value in an annotation. 10168651Skris * @param b the value being visited 10268651Skris * @param p a visitor-specified parameter 10368651Skris * @return the result of the visit 10468651Skris */ 10568651Skris R visitBoolean(boolean b, P p); 10668651Skris 10768651Skris /** 10868651Skris * Visits a {@code byte} value in an annotation. 10968651Skris * @param b the value being visited 11068651Skris * @param p a visitor-specified parameter 11168651Skris * @return the result of the visit 11268651Skris */ 113296465Sdelphij R visitByte(byte b, P p); 11468651Skris 115296465Sdelphij /** 11668651Skris * Visits a {@code char} value in an annotation. 117296465Sdelphij * @param c the value being visited 118296465Sdelphij * @param p a visitor-specified parameter 119296465Sdelphij * @return the result of the visit 120296465Sdelphij */ 121296465Sdelphij R visitChar(char c, P p); 122296465Sdelphij 123296465Sdelphij /** 124296465Sdelphij * Visits a {@code double} value in an annotation. 125296465Sdelphij * @param d the value being visited 126296465Sdelphij * @param p a visitor-specified parameter 127296465Sdelphij * @return the result of the visit 128296465Sdelphij */ 129296465Sdelphij R visitDouble(double d, P p); 13068651Skris 131296465Sdelphij /** 132296465Sdelphij * Visits a {@code float} value in an annotation. 133296465Sdelphij * @param f the value being visited 134296465Sdelphij * @param p a visitor-specified parameter 135296465Sdelphij * @return the result of the visit 136296465Sdelphij */ 137296465Sdelphij R visitFloat(float f, P p); 138296465Sdelphij 139296465Sdelphij /** 140296465Sdelphij * Visits an {@code int} value in an annotation. 141296465Sdelphij * @param i the value being visited 142296465Sdelphij * @param p a visitor-specified parameter 143296465Sdelphij * @return the result of the visit 144296465Sdelphij */ 145296465Sdelphij R visitInt(int i, P p); 146296465Sdelphij 147296465Sdelphij /** 148296465Sdelphij * Visits a {@code long} value in an annotation. 149296465Sdelphij * @param i the value being visited 150296465Sdelphij * @param p a visitor-specified parameter 151296465Sdelphij * @return the result of the visit 152296465Sdelphij */ 153296465Sdelphij R visitLong(long i, P p); 154296465Sdelphij 15568651Skris /** 156296465Sdelphij * Visits a {@code short} value in an annotation. 157296465Sdelphij * @param s the value being visited 158296465Sdelphij * @param p a visitor-specified parameter 159296465Sdelphij * @return the result of the visit 160296465Sdelphij */ 161194206Ssimon R visitShort(short s, P p); 162296465Sdelphij 163194206Ssimon /** 164296465Sdelphij * Visits a string value in an annotation. 16568651Skris * @param s the value being visited 16668651Skris * @param p a visitor-specified parameter 167 * @return the result of the visit 168 */ 169 R visitString(String s, P p); 170 171 /** 172 * Visits a type value in an annotation. 173 * @param t the value being visited 174 * @param p a visitor-specified parameter 175 * @return the result of the visit 176 */ 177 R visitType(TypeMirror t, P p); 178 179 /** 180 * Visits an {@code enum} value in an annotation. 181 * @param c the value being visited 182 * @param p a visitor-specified parameter 183 * @return the result of the visit 184 */ 185 R visitEnumConstant(VariableElement c, P p); 186 187 /** 188 * Visits an annotation value in an annotation. 189 * @param a the value being visited 190 * @param p a visitor-specified parameter 191 * @return the result of the visit 192 */ 193 R visitAnnotation(AnnotationMirror a, P p); 194 195 /** 196 * Visits an array value in an annotation. 197 * @param vals the value being visited 198 * @param p a visitor-specified parameter 199 * @return the result of the visit 200 */ 201 R visitArray(List<? extends AnnotationValue> vals, P p); 202 203 /** 204 * Visits an unknown kind of annotation value. 205 * This can occur if the language evolves and new kinds 206 * of value can be stored in an annotation. 207 * @param av the unknown value being visited 208 * @param p a visitor-specified parameter 209 * @return the result of the visit 210 * @throws UnknownAnnotationValueException 211 * a visitor implementation may optionally throw this exception 212 */ 213 R visitUnknown(AnnotationValue av, P p); 214} 215