src/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitor6.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.lang.model.util;
aoqi@0 27
aoqi@0 28
aoqi@0 29 import java.util.List;
aoqi@0 30 import javax.lang.model.element.*;
aoqi@0 31
aoqi@0 32 import javax.lang.model.type.TypeMirror;
aoqi@0 33 import static javax.lang.model.SourceVersion.*;
aoqi@0 34 import javax.lang.model.SourceVersion;
aoqi@0 35 import javax.annotation.processing.SupportedSourceVersion;
aoqi@0 36
aoqi@0 37 /**
aoqi@0 38 * A simple visitor for annotation values with default behavior
aoqi@0 39 * appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
aoqi@0 40 * source version. Visit methods call {@link
aoqi@0 41 * #defaultAction} passing their arguments to {@code defaultAction}'s
aoqi@0 42 * corresponding parameters.
aoqi@0 43 *
aoqi@0 44 * <p> Methods in this class may be overridden subject to their
aoqi@0 45 * general contract. Note that annotating methods in concrete
aoqi@0 46 * subclasses with {@link java.lang.Override @Override} will help
aoqi@0 47 * ensure that methods are overridden as intended.
aoqi@0 48 *
aoqi@0 49 * <p> <b>WARNING:</b> The {@code AnnotationValueVisitor} interface
aoqi@0 50 * implemented by this class may have methods added to it in the
aoqi@0 51 * future to accommodate new, currently unknown, language structures
aoqi@0 52 * added to future versions of the Java&trade; programming language.
aoqi@0 53 * Therefore, methods whose names begin with {@code "visit"} may be
aoqi@0 54 * added to this class in the future; to avoid incompatibilities,
aoqi@0 55 * classes which extend this class should not declare any instance
aoqi@0 56 * methods with names beginning with {@code "visit"}.
aoqi@0 57 *
aoqi@0 58 * <p>When such a new visit method is added, the default
aoqi@0 59 * implementation in this class will be to call the {@link
aoqi@0 60 * #visitUnknown visitUnknown} method. A new simple annotation
aoqi@0 61 * value visitor class will also be introduced to correspond to the
aoqi@0 62 * new language level; this visitor will have different default
aoqi@0 63 * behavior for the visit method in question. When the new visitor is
aoqi@0 64 * introduced, all or portions of this visitor may be deprecated.
aoqi@0 65 *
aoqi@0 66 * <p>Note that adding a default implementation of a new visit method
aoqi@0 67 * in a visitor class will occur instead of adding a <em>default
aoqi@0 68 * method</em> directly in the visitor interface since a Java SE 8
aoqi@0 69 * language feature cannot be used to this version of the API since
aoqi@0 70 * this version is required to be runnable on Java SE 7
aoqi@0 71 * implementations. Future versions of the API that are only required
aoqi@0 72 * to run on Java SE 8 and later may take advantage of default methods
aoqi@0 73 * in this situation.
aoqi@0 74 *
aoqi@0 75 * @param <R> the return type of this visitor's methods
aoqi@0 76 * @param <P> the type of the additional parameter to this visitor's methods.
aoqi@0 77 *
aoqi@0 78 * @author Joseph D. Darcy
aoqi@0 79 * @author Scott Seligman
aoqi@0 80 * @author Peter von der Ah&eacute;
aoqi@0 81 *
aoqi@0 82 * @see SimpleAnnotationValueVisitor7
aoqi@0 83 * @see SimpleAnnotationValueVisitor8
aoqi@0 84 * @since 1.6
aoqi@0 85 */
aoqi@0 86 @SupportedSourceVersion(RELEASE_6)
aoqi@0 87 public class SimpleAnnotationValueVisitor6<R, P>
aoqi@0 88 extends AbstractAnnotationValueVisitor6<R, P> {
aoqi@0 89
aoqi@0 90 /**
aoqi@0 91 * Default value to be returned; {@link #defaultAction
aoqi@0 92 * defaultAction} returns this value unless the method is
aoqi@0 93 * overridden.
aoqi@0 94 */
aoqi@0 95 protected final R DEFAULT_VALUE;
aoqi@0 96
aoqi@0 97 /**
aoqi@0 98 * Constructor for concrete subclasses; uses {@code null} for the
aoqi@0 99 * default value.
aoqi@0 100 */
aoqi@0 101 protected SimpleAnnotationValueVisitor6() {
aoqi@0 102 super();
aoqi@0 103 DEFAULT_VALUE = null;
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 /**
aoqi@0 107 * Constructor for concrete subclasses; uses the argument for the
aoqi@0 108 * default value.
aoqi@0 109 *
aoqi@0 110 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
aoqi@0 111 */
aoqi@0 112 protected SimpleAnnotationValueVisitor6(R defaultValue) {
aoqi@0 113 super();
aoqi@0 114 DEFAULT_VALUE = defaultValue;
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 /**
aoqi@0 118 * The default action for visit methods. The implementation in
aoqi@0 119 * this class just returns {@link #DEFAULT_VALUE}; subclasses will
aoqi@0 120 * commonly override this method.
aoqi@0 121 *
aoqi@0 122 * @param o the value of the annotation
aoqi@0 123 * @param p a visitor-specified parameter
aoqi@0 124 * @return {@code DEFAULT_VALUE} unless overridden
aoqi@0 125 */
aoqi@0 126 protected R defaultAction(Object o, P p) {
aoqi@0 127 return DEFAULT_VALUE;
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 /**
aoqi@0 131 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 132 *
aoqi@0 133 * @param b {@inheritDoc}
aoqi@0 134 * @param p {@inheritDoc}
aoqi@0 135 * @return the result of {@code defaultAction}
aoqi@0 136 */
aoqi@0 137 public R visitBoolean(boolean b, P p) {
aoqi@0 138 return defaultAction(b, p);
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 /**
aoqi@0 142 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 143 *
aoqi@0 144 * @param b {@inheritDoc}
aoqi@0 145 * @param p {@inheritDoc}
aoqi@0 146 * @return the result of {@code defaultAction}
aoqi@0 147 */
aoqi@0 148 public R visitByte(byte b, P p) {
aoqi@0 149 return defaultAction(b, p);
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 /**
aoqi@0 153 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 154 *
aoqi@0 155 * @param c {@inheritDoc}
aoqi@0 156 * @param p {@inheritDoc}
aoqi@0 157 * @return the result of {@code defaultAction}
aoqi@0 158 */
aoqi@0 159 public R visitChar(char c, P p) {
aoqi@0 160 return defaultAction(c, p);
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 /**
aoqi@0 164 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 165 *
aoqi@0 166 * @param d {@inheritDoc}
aoqi@0 167 * @param p {@inheritDoc}
aoqi@0 168 * @return the result of {@code defaultAction}
aoqi@0 169 */
aoqi@0 170 public R visitDouble(double d, P p) {
aoqi@0 171 return defaultAction(d, p);
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 /**
aoqi@0 175 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 176 *
aoqi@0 177 * @param f {@inheritDoc}
aoqi@0 178 * @param p {@inheritDoc}
aoqi@0 179 * @return the result of {@code defaultAction}
aoqi@0 180 */
aoqi@0 181 public R visitFloat(float f, P p) {
aoqi@0 182 return defaultAction(f, p);
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 /**
aoqi@0 186 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 187 *
aoqi@0 188 * @param i {@inheritDoc}
aoqi@0 189 * @param p {@inheritDoc}
aoqi@0 190 * @return the result of {@code defaultAction}
aoqi@0 191 */
aoqi@0 192 public R visitInt(int i, P p) {
aoqi@0 193 return defaultAction(i, p);
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 /**
aoqi@0 197 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 198 *
aoqi@0 199 * @param i {@inheritDoc}
aoqi@0 200 * @param p {@inheritDoc}
aoqi@0 201 * @return the result of {@code defaultAction}
aoqi@0 202 */
aoqi@0 203 public R visitLong(long i, P p) {
aoqi@0 204 return defaultAction(i, p);
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 /**
aoqi@0 208 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 209 *
aoqi@0 210 * @param s {@inheritDoc}
aoqi@0 211 * @param p {@inheritDoc}
aoqi@0 212 * @return the result of {@code defaultAction}
aoqi@0 213 */
aoqi@0 214 public R visitShort(short s, P p) {
aoqi@0 215 return defaultAction(s, p);
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 /**
aoqi@0 219 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 220 *
aoqi@0 221 * @param s {@inheritDoc}
aoqi@0 222 * @param p {@inheritDoc}
aoqi@0 223 * @return the result of {@code defaultAction}
aoqi@0 224 */
aoqi@0 225 public R visitString(String s, P p) {
aoqi@0 226 return defaultAction(s, p);
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 /**
aoqi@0 230 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 231 *
aoqi@0 232 * @param t {@inheritDoc}
aoqi@0 233 * @param p {@inheritDoc}
aoqi@0 234 * @return the result of {@code defaultAction}
aoqi@0 235 */
aoqi@0 236 public R visitType(TypeMirror t, P p) {
aoqi@0 237 return defaultAction(t, p);
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 /**
aoqi@0 241 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 242 *
aoqi@0 243 * @param c {@inheritDoc}
aoqi@0 244 * @param p {@inheritDoc}
aoqi@0 245 * @return the result of {@code defaultAction}
aoqi@0 246 */
aoqi@0 247 public R visitEnumConstant(VariableElement c, P p) {
aoqi@0 248 return defaultAction(c, p);
aoqi@0 249 }
aoqi@0 250
aoqi@0 251 /**
aoqi@0 252 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 253 *
aoqi@0 254 * @param a {@inheritDoc}
aoqi@0 255 * @param p {@inheritDoc}
aoqi@0 256 * @return the result of {@code defaultAction}
aoqi@0 257 */
aoqi@0 258 public R visitAnnotation(AnnotationMirror a, P p) {
aoqi@0 259 return defaultAction(a, p);
aoqi@0 260 }
aoqi@0 261
aoqi@0 262 /**
aoqi@0 263 * {@inheritDoc} This implementation calls {@code defaultAction}.
aoqi@0 264 *
aoqi@0 265 * @param vals {@inheritDoc}
aoqi@0 266 * @param p {@inheritDoc}
aoqi@0 267 * @return the result of {@code defaultAction}
aoqi@0 268 */
aoqi@0 269 public R visitArray(List<? extends AnnotationValue> vals, P p) {
aoqi@0 270 return defaultAction(vals, p);
aoqi@0 271 }
aoqi@0 272 }

mercurial