1 /* 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.lang.model.element; 27 28 29 import java.util.List; 30 31 import javax.lang.model.type.TypeMirror; 32 33 34 /** 35 * A visitor of the values of annotation type elements, using a 36 * variant of the visitor design pattern. Unlike a standard visitor 37 * which dispatches based on the concrete type of a member of a type 38 * hierarchy, this visitor dispatches based on the type of data 39 * stored; there are no distinct subclasses for storing, for example, 40 * {@code boolean} values versus {@code int} values. Classes 41 * implementing this interface are used to operate on a value when the 42 * type of that value is unknown at compile time. When a visitor is 43 * passed to a value's {@link AnnotationValue#accept accept} method, 44 * the <code>visit<i>XYZ</i></code> method applicable to that value is 45 * invoked. 46 * 47 * <p> Classes implementing this interface may or may not throw a 48 * {@code NullPointerException} if the additional parameter {@code p} 49 * is {@code null}; see documentation of the implementing class for 50 * details. 51 * 52 * <p> <b>WARNING:</b> It is possible that methods will be added to 53 * this interface to accommodate new, currently unknown, language 54 * structures added to future versions of the Java™ programming 55 * language. Therefore, visitor classes directly implementing this 56 * interface may be source incompatible with future versions of the 57 * platform. To avoid this source incompatibility, visitor 58 * implementations are encouraged to instead extend the appropriate 59 * abstract visitor class that implements this interface. However, an 60 * API should generally use this visitor interface as the type for 61 * parameters, return type, etc. rather than one of the abstract 62 * classes. 63 * 64 * <p>Note that methods to accommodate new language constructs could 65 * be added in a source <em>compatible</em> way if they were added as 66 * <em>default methods</em>. However, default methods are only 67 * available on Java SE 8 and higher releases and the {@code 68 * javax.lang.model.*} packages bundled in Java SE 8 are required to 69 * also be runnable on Java SE 7. Therefore, default methods 70 * <em>cannot</em> be used when extending {@code javax.lang.model.*} 71 * to cover Java SE 8 language features. However, default methods may 72 * be used in subsequent revisions of the {@code javax.lang.model.*} 73 * packages that are only required to run on Java SE 8 and higher 74 * platform versions. 75 * 76 * @param <R> the return type of this visitor's methods 77 * @param <P> the type of the additional parameter to this visitor's methods. 78 * @author Joseph D. Darcy 79 * @author Scott Seligman 80 * @author Peter von der Ahé 81 * @since 1.6 82 */ 83 public interface AnnotationValueVisitor<R, P> { 84 /** 85 * Visits an annotation value. 86 * @param av the value to visit 87 * @param p a visitor-specified parameter 88 * @return a visitor-specified result 89 */ 90 R visit(AnnotationValue av, P p); 91 92 /** 93 * A convenience method equivalent to {@code v.visit(av, null)}. 94 * @param av the value to visit 95 * @return a visitor-specified result 96 */ 97 R visit(AnnotationValue av); 98 99 /** 100 * Visits a {@code boolean} value in an annotation. 101 * @param b the value being visited 102 * @param p a visitor-specified parameter 103 * @return the result of the visit 104 */ 105 R visitBoolean(boolean b, P p); 106 107 /** 108 * Visits a {@code byte} value in an annotation. 109 * @param b the value being visited 110 * @param p a visitor-specified parameter 111 * @return the result of the visit 112 */ 113 R visitByte(byte b, P p); 114 115 /** 116 * Visits a {@code char} value in an annotation. 117 * @param c the value being visited 118 * @param p a visitor-specified parameter 119 * @return the result of the visit 120 */ 121 R visitChar(char c, P p); 122 123 /** 124 * Visits a {@code double} value in an annotation. 125 * @param d the value being visited 126 * @param p a visitor-specified parameter 127 * @return the result of the visit 128 */ 129 R visitDouble(double d, P p); 130 131 /** 132 * Visits a {@code float} value in an annotation. 133 * @param f the value being visited 134 * @param p a visitor-specified parameter 135 * @return the result of the visit 136 */ 137 R visitFloat(float f, P p); 138 139 /** 140 * Visits an {@code int} value in an annotation. 141 * @param i the value being visited 142 * @param p a visitor-specified parameter 143 * @return the result of the visit 144 */ 145 R visitInt(int i, P p); 146 147 /** 148 * Visits a {@code long} value in an annotation. 149 * @param i the value being visited 150 * @param p a visitor-specified parameter 151 * @return the result of the visit 152 */ 153 R visitLong(long i, P p); 154 155 /** 156 * Visits a {@code short} value in an annotation. 157 * @param s the value being visited 158 * @param p a visitor-specified parameter 159 * @return the result of the visit 160 */ 161 R visitShort(short s, P p); 162 163 /** 164 * Visits a string value in an annotation. 165 * @param s the value being visited 166 * @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 }