src/share/classes/javax/lang/model/element/AnnotationValueVisitor.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/javax/lang/model/element/AnnotationValueVisitor.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,214 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.lang.model.element;
    1.30 +
    1.31 +
    1.32 +import java.util.List;
    1.33 +
    1.34 +import javax.lang.model.type.TypeMirror;
    1.35 +
    1.36 +
    1.37 +/**
    1.38 + * A visitor of the values of annotation type elements, using a
    1.39 + * variant of the visitor design pattern.  Unlike a standard visitor
    1.40 + * which dispatches based on the concrete type of a member of a type
    1.41 + * hierarchy, this visitor dispatches based on the type of data
    1.42 + * stored; there are no distinct subclasses for storing, for example,
    1.43 + * {@code boolean} values versus {@code int} values.  Classes
    1.44 + * implementing this interface are used to operate on a value when the
    1.45 + * type of that value is unknown at compile time.  When a visitor is
    1.46 + * passed to a value's {@link AnnotationValue#accept accept} method,
    1.47 + * the <tt>visit<i>XYZ</i></tt> method applicable to that value is
    1.48 + * invoked.
    1.49 + *
    1.50 + * <p> Classes implementing this interface may or may not throw a
    1.51 + * {@code NullPointerException} if the additional parameter {@code p}
    1.52 + * is {@code null}; see documentation of the implementing class for
    1.53 + * details.
    1.54 + *
    1.55 + * <p> <b>WARNING:</b> It is possible that methods will be added to
    1.56 + * this interface to accommodate new, currently unknown, language
    1.57 + * structures added to future versions of the Java&trade; programming
    1.58 + * language.  Therefore, visitor classes directly implementing this
    1.59 + * interface may be source incompatible with future versions of the
    1.60 + * platform.  To avoid this source incompatibility, visitor
    1.61 + * implementations are encouraged to instead extend the appropriate
    1.62 + * abstract visitor class that implements this interface.  However, an
    1.63 + * API should generally use this visitor interface as the type for
    1.64 + * parameters, return type, etc. rather than one of the abstract
    1.65 + * classes.
    1.66 + *
    1.67 + * <p>Note that methods to accommodate new language constructs could
    1.68 + * be added in a source <em>compatible</em> way if they were added as
    1.69 + * <em>default methods</em>.  However, default methods are only
    1.70 + * available on Java SE 8 and higher releases and the {@code
    1.71 + * javax.lang.model.*} packages bundled in Java SE 8 are required to
    1.72 + * also be runnable on Java SE 7.  Therefore, default methods
    1.73 + * <em>cannot</em> be used when extending {@code javax.lang.model.*}
    1.74 + * to cover Java SE 8 language features.  However, default methods may
    1.75 + * be used in subsequent revisions of the {@code javax.lang.model.*}
    1.76 + * packages that are only required to run on Java SE 8 and higher
    1.77 + * platform versions.
    1.78 + *
    1.79 + * @param <R> the return type of this visitor's methods
    1.80 + * @param <P> the type of the additional parameter to this visitor's methods.
    1.81 + * @author Joseph D. Darcy
    1.82 + * @author Scott Seligman
    1.83 + * @author Peter von der Ah&eacute;
    1.84 + * @since 1.6
    1.85 + */
    1.86 +public interface AnnotationValueVisitor<R, P> {
    1.87 +    /**
    1.88 +     * Visits an annotation value.
    1.89 +     * @param av the value to visit
    1.90 +     * @param p a visitor-specified parameter
    1.91 +     * @return  a visitor-specified result
    1.92 +     */
    1.93 +    R visit(AnnotationValue av, P p);
    1.94 +
    1.95 +    /**
    1.96 +     * A convenience method equivalent to {@code v.visit(av, null)}.
    1.97 +     * @param av the value to visit
    1.98 +     * @return  a visitor-specified result
    1.99 +     */
   1.100 +    R visit(AnnotationValue av);
   1.101 +
   1.102 +    /**
   1.103 +     * Visits a {@code boolean} value in an annotation.
   1.104 +     * @param b the value being visited
   1.105 +     * @param p a visitor-specified parameter
   1.106 +     * @return the result of the visit
   1.107 +     */
   1.108 +    R visitBoolean(boolean b, P p);
   1.109 +
   1.110 +    /**
   1.111 +     * Visits a {@code byte} value in an annotation.
   1.112 +     * @param  b the value being visited
   1.113 +     * @param  p a visitor-specified parameter
   1.114 +     * @return the result of the visit
   1.115 +     */
   1.116 +    R visitByte(byte b, P p);
   1.117 +
   1.118 +    /**
   1.119 +     * Visits a {@code char} value in an annotation.
   1.120 +     * @param  c the value being visited
   1.121 +     * @param  p a visitor-specified parameter
   1.122 +     * @return the result of the visit
   1.123 +     */
   1.124 +    R visitChar(char c, P p);
   1.125 +
   1.126 +    /**
   1.127 +     * Visits a {@code double} value in an annotation.
   1.128 +     * @param  d the value being visited
   1.129 +     * @param  p a visitor-specified parameter
   1.130 +     * @return the result of the visit
   1.131 +     */
   1.132 +    R visitDouble(double d, P p);
   1.133 +
   1.134 +    /**
   1.135 +     * Visits a {@code float} value in an annotation.
   1.136 +     * @param  f the value being visited
   1.137 +     * @param  p a visitor-specified parameter
   1.138 +     * @return the result of the visit
   1.139 +     */
   1.140 +    R visitFloat(float f, P p);
   1.141 +
   1.142 +    /**
   1.143 +     * Visits an {@code int} value in an annotation.
   1.144 +     * @param  i the value being visited
   1.145 +     * @param  p a visitor-specified parameter
   1.146 +     * @return the result of the visit
   1.147 +     */
   1.148 +    R visitInt(int i, P p);
   1.149 +
   1.150 +    /**
   1.151 +     * Visits a {@code long} value in an annotation.
   1.152 +     * @param  i the value being visited
   1.153 +     * @param  p a visitor-specified parameter
   1.154 +     * @return the result of the visit
   1.155 +     */
   1.156 +    R visitLong(long i, P p);
   1.157 +
   1.158 +    /**
   1.159 +     * Visits a {@code short} value in an annotation.
   1.160 +     * @param  s the value being visited
   1.161 +     * @param  p a visitor-specified parameter
   1.162 +     * @return the result of the visit
   1.163 +     */
   1.164 +    R visitShort(short s, P p);
   1.165 +
   1.166 +    /**
   1.167 +     * Visits a string value in an annotation.
   1.168 +     * @param  s the value being visited
   1.169 +     * @param  p a visitor-specified parameter
   1.170 +     * @return the result of the visit
   1.171 +     */
   1.172 +    R visitString(String s, P p);
   1.173 +
   1.174 +    /**
   1.175 +     * Visits a type value in an annotation.
   1.176 +     * @param  t the value being visited
   1.177 +     * @param  p a visitor-specified parameter
   1.178 +     * @return the result of the visit
   1.179 +     */
   1.180 +    R visitType(TypeMirror t, P p);
   1.181 +
   1.182 +    /**
   1.183 +     * Visits an {@code enum} value in an annotation.
   1.184 +     * @param  c the value being visited
   1.185 +     * @param  p a visitor-specified parameter
   1.186 +     * @return the result of the visit
   1.187 +     */
   1.188 +    R visitEnumConstant(VariableElement c, P p);
   1.189 +
   1.190 +    /**
   1.191 +     * Visits an annotation value in an annotation.
   1.192 +     * @param  a the value being visited
   1.193 +     * @param  p a visitor-specified parameter
   1.194 +     * @return the result of the visit
   1.195 +     */
   1.196 +    R visitAnnotation(AnnotationMirror a, P p);
   1.197 +
   1.198 +    /**
   1.199 +     * Visits an array value in an annotation.
   1.200 +     * @param  vals the value being visited
   1.201 +     * @param  p a visitor-specified parameter
   1.202 +     * @return the result of the visit
   1.203 +     */
   1.204 +    R visitArray(List<? extends AnnotationValue> vals, P p);
   1.205 +
   1.206 +    /**
   1.207 +     * Visits an unknown kind of annotation value.
   1.208 +     * This can occur if the language evolves and new kinds
   1.209 +     * of value can be stored in an annotation.
   1.210 +     * @param  av the unknown value being visited
   1.211 +     * @param  p a visitor-specified parameter
   1.212 +     * @return the result of the visit
   1.213 +     * @throws UnknownAnnotationValueException
   1.214 +     *  a visitor implementation may optionally throw this exception
   1.215 +     */
   1.216 +    R visitUnknown(AnnotationValue av, P p);
   1.217 +}

mercurial