1 /* 2 * Copyright (c) 2005, 2017, 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 were required to 69 * also be runnable on Java SE 7. Therefore, default methods 70 * were <em>not</em> used when extending {@code javax.lang.model.*} 71 * to cover Java SE 8 language features. However, default methods 72 * are 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 visit(av, null)}. 94 * 95 * @implSpec The default implementation is {@code visit(av, null)}. 96 * 97 * @param av the value to visit 98 * @return a visitor-specified result 99 */ 100 default R visit(AnnotationValue av) { 101 return visit(av, null); 102 } 103 104 /** 105 * Visits a {@code boolean} value in an annotation. 106 * @param b the value being visited 107 * @param p a visitor-specified parameter 108 * @return the result of the visit 109 */ 110 R visitBoolean(boolean b, P p); 111 112 /** 113 * Visits a {@code byte} value in an annotation. 114 * @param b the value being visited 115 * @param p a visitor-specified parameter 116 * @return the result of the visit 117 */ 118 R visitByte(byte b, P p); 119 120 /** 121 * Visits a {@code char} value in an annotation. 122 * @param c the value being visited 123 * @param p a visitor-specified parameter 124 * @return the result of the visit 125 */ 126 R visitChar(char c, P p); 127 128 /** 129 * Visits a {@code double} value in an annotation. 130 * @param d the value being visited 131 * @param p a visitor-specified parameter 132 * @return the result of the visit 133 */ 134 R visitDouble(double d, P p); 135 136 /** 137 * Visits a {@code float} value in an annotation. 138 * @param f the value being visited 139 * @param p a visitor-specified parameter 140 * @return the result of the visit 141 */ 142 R visitFloat(float f, P p); 143 144 /** 145 * Visits an {@code int} value in an annotation. 146 * @param i the value being visited 147 * @param p a visitor-specified parameter 148 * @return the result of the visit 149 */ 150 R visitInt(int i, P p); 151 152 /** 153 * Visits a {@code long} value in an annotation. 154 * @param i the value being visited 155 * @param p a visitor-specified parameter 156 * @return the result of the visit 157 */ 158 R visitLong(long i, P p); 159 160 /** 161 * Visits a {@code short} value in an annotation. 162 * @param s the value being visited 163 * @param p a visitor-specified parameter 164 * @return the result of the visit 165 */ 166 R visitShort(short s, P p); 167 168 /** 169 * Visits a string value in an annotation. 170 * @param s the value being visited 171 * @param p a visitor-specified parameter 172 * @return the result of the visit 173 */ 174 R visitString(String s, P p); 175 176 /** 177 * Visits a type value in an annotation. 178 * @param t the value being visited 179 * @param p a visitor-specified parameter 180 * @return the result of the visit 181 */ 182 R visitType(TypeMirror t, P p); 183 184 /** 185 * Visits an {@code enum} value in an annotation. 186 * @param c the value being visited 187 * @param p a visitor-specified parameter 188 * @return the result of the visit 189 */ 190 R visitEnumConstant(VariableElement c, P p); 191 192 /** 193 * Visits an annotation value in an annotation. 194 * @param a the value being visited 195 * @param p a visitor-specified parameter 196 * @return the result of the visit 197 */ 198 R visitAnnotation(AnnotationMirror a, P p); 199 200 /** 201 * Visits an array value in an annotation. 202 * @param vals the value being visited 203 * @param p a visitor-specified parameter 204 * @return the result of the visit 205 */ 206 R visitArray(List<? extends AnnotationValue> vals, P p); 207 208 /** 209 * Visits an unknown kind of annotation value. 210 * This can occur if the language evolves and new kinds 211 * of value can be stored in an annotation. 212 * @param av the unknown value being visited 213 * @param p a visitor-specified parameter 214 * @return the result of the visit 215 * @throws UnknownAnnotationValueException 216 * a visitor implementation may optionally throw this exception 217 */ 218 R visitUnknown(AnnotationValue av, P p); 219 }