langtools/src/share/classes/javax/lang/model/element/AnnotationValueVisitor.java
author darcy
Wed, 23 Jan 2013 20:11:07 -0800
changeset 15386 92bc08d96f0c
parent 5520 86e4b9a9da40
permissions -rw-r--r--
8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15386
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.lang.model.element;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.lang.model.type.TypeMirror;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * A visitor of the values of annotation type elements, using a
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * variant of the visitor design pattern.  Unlike a standard visitor
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * which dispatches based on the concrete type of a member of a type
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * hierarchy, this visitor dispatches based on the type of data
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * stored; there are no distinct subclasses for storing, for example,
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * {@code boolean} values versus {@code int} values.  Classes
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * implementing this interface are used to operate on a value when the
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * type of that value is unknown at compile time.  When a visitor is
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * passed to a value's {@link AnnotationValue#accept accept} method,
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * the <tt>visit<i>XYZ</i></tt> method applicable to that value is
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * invoked.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * <p> Classes implementing this interface may or may not throw a
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * {@code NullPointerException} if the additional parameter {@code p}
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * is {@code null}; see documentation of the implementing class for
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * details.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * <p> <b>WARNING:</b> It is possible that methods will be added to
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * this interface to accommodate new, currently unknown, language
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * structures added to future versions of the Java&trade; programming
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * language.  Therefore, visitor classes directly implementing this
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * interface may be source incompatible with future versions of the
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * platform.  To avoid this source incompatibility, visitor
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 * implementations are encouraged to instead extend the appropriate
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 * abstract visitor class that implements this interface.  However, an
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * API should generally use this visitor interface as the type for
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * parameters, return type, etc. rather than one of the abstract
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *
15386
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    64
 * <p>Note that methods to accommodate new language constructs could
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    65
 * be added in a source <em>compatible</em> way if they were added as
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    66
 * <em>default methods</em>.  However, default methods are only
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    67
 * available on Java SE 8 and higher releases and the {@code
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    68
 * javax.lang.model.*} packages bundled in Java SE 8 are required to
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    69
 * also be runnable on Java SE 7.  Therefore, default methods
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    70
 * <em>cannot</em> be used when extending {@code javax.lang.model.*}
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    71
 * to cover Java SE 8 language features.  However, default methods may
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    72
 * be used in subsequent revisions of the {@code javax.lang.model.*}
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    73
 * packages that are only required to run on Java SE 8 and higher
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    74
 * platform versions.
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 5520
diff changeset
    75
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * @param <R> the return type of this visitor's methods
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 * @param <P> the type of the additional parameter to this visitor's methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
public interface AnnotationValueVisitor<R, P> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * Visits an annotation value.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * @param av the value to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * @param p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * @return  a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    R visit(AnnotationValue av, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * A convenience method equivalent to {@code v.visit(av, null)}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * @param av the value to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * @return  a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    R visit(AnnotationValue av);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * Visits a {@code boolean} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * @param b the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * @param p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    R visitBoolean(boolean b, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * Visits a {@code byte} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @param  b the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    R visitByte(byte b, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * Visits a {@code char} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * @param  c the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    R visitChar(char c, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * Visits a {@code double} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * @param  d the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    R visitDouble(double d, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * Visits a {@code float} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * @param  f the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    R visitFloat(float f, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * Visits an {@code int} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * @param  i the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    R visitInt(int i, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * Visits a {@code long} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * @param  i the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    R visitLong(long i, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * Visits a {@code short} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * @param  s the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    R visitShort(short s, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * Visits a string value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     * @param  s the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    R visitString(String s, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * Visits a type value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * @param  t the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    R visitType(TypeMirror t, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * Visits an {@code enum} value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * @param  c the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    R visitEnumConstant(VariableElement c, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * Visits an annotation value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * @param  a the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    R visitAnnotation(AnnotationMirror a, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * Visits an array value in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * @param  vals the value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    R visitArray(List<? extends AnnotationValue> vals, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * Visits an unknown kind of annotation value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * This can occur if the language evolves and new kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * of value can be stored in an annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * @param  av the unknown value being visited
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * @param  p a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * @return the result of the visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * @throws UnknownAnnotationValueException
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     *  a visitor implementation may optionally throw this exception
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    R visitUnknown(AnnotationValue av, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
}