001    /*
002     * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package javax.lang.model.element;
027    
028    
029    import java.util.List;
030    
031    import javax.lang.model.type.TypeMirror;
032    
033    
034    /**
035     * A visitor of the values of annotation type elements, using a
036     * variant of the visitor design pattern.  Unlike a standard visitor
037     * which dispatches based on the concrete type of a member of a type
038     * hierarchy, this visitor dispatches based on the type of data
039     * stored; there are no distinct subclasses for storing, for example,
040     * {@code boolean} values versus {@code int} values.  Classes
041     * implementing this interface are used to operate on a value when the
042     * type of that value is unknown at compile time.  When a visitor is
043     * passed to a value's {@link AnnotationValue#accept accept} method,
044     * the <tt>visit<i>XYZ</i></tt> method applicable to that value is
045     * invoked.
046     *
047     * <p> Classes implementing this interface may or may not throw a
048     * {@code NullPointerException} if the additional parameter {@code p}
049     * is {@code null}; see documentation of the implementing class for
050     * details.
051     *
052     * <p> <b>WARNING:</b> It is possible that methods will be added to
053     * this interface to accommodate new, currently unknown, language
054     * structures added to future versions of the Java&trade; programming
055     * language.  Therefore, visitor classes directly implementing this
056     * interface may be source incompatible with future versions of the
057     * platform.  To avoid this source incompatibility, visitor
058     * implementations are encouraged to instead extend the appropriate
059     * abstract visitor class that implements this interface.  However, an
060     * API should generally use this visitor interface as the type for
061     * parameters, return type, etc. rather than one of the abstract
062     * classes.
063     *
064     * @param <R> the return type of this visitor's methods
065     * @param <P> the type of the additional parameter to this visitor's methods.
066     * @author Joseph D. Darcy
067     * @author Scott Seligman
068     * @author Peter von der Ah&eacute;
069     * @since 1.6
070     */
071    public interface AnnotationValueVisitor<R, P> {
072        /**
073         * Visits an annotation value.
074         * @param av the value to visit
075         * @param p a visitor-specified parameter
076         * @return  a visitor-specified result
077         */
078        R visit(AnnotationValue av, P p);
079    
080        /**
081         * A convenience method equivalent to {@code v.visit(av, null)}.
082         * @param av the value to visit
083         * @return  a visitor-specified result
084         */
085        R visit(AnnotationValue av);
086    
087        /**
088         * Visits a {@code boolean} value in an annotation.
089         * @param b the value being visited
090         * @param p a visitor-specified parameter
091         * @return the result of the visit
092         */
093        R visitBoolean(boolean b, P p);
094    
095        /**
096         * Visits a {@code byte} value in an annotation.
097         * @param  b the value being visited
098         * @param  p a visitor-specified parameter
099         * @return the result of the visit
100         */
101        R visitByte(byte b, P p);
102    
103        /**
104         * Visits a {@code char} value in an annotation.
105         * @param  c the value being visited
106         * @param  p a visitor-specified parameter
107         * @return the result of the visit
108         */
109        R visitChar(char c, P p);
110    
111        /**
112         * Visits a {@code double} value in an annotation.
113         * @param  d the value being visited
114         * @param  p a visitor-specified parameter
115         * @return the result of the visit
116         */
117        R visitDouble(double d, P p);
118    
119        /**
120         * Visits a {@code float} value in an annotation.
121         * @param  f the value being visited
122         * @param  p a visitor-specified parameter
123         * @return the result of the visit
124         */
125        R visitFloat(float f, P p);
126    
127        /**
128         * Visits an {@code int} value in an annotation.
129         * @param  i the value being visited
130         * @param  p a visitor-specified parameter
131         * @return the result of the visit
132         */
133        R visitInt(int i, P p);
134    
135        /**
136         * Visits a {@code long} value in an annotation.
137         * @param  i the value being visited
138         * @param  p a visitor-specified parameter
139         * @return the result of the visit
140         */
141        R visitLong(long i, P p);
142    
143        /**
144         * Visits a {@code short} value in an annotation.
145         * @param  s the value being visited
146         * @param  p a visitor-specified parameter
147         * @return the result of the visit
148         */
149        R visitShort(short s, P p);
150    
151        /**
152         * Visits a string value in an annotation.
153         * @param  s the value being visited
154         * @param  p a visitor-specified parameter
155         * @return the result of the visit
156         */
157        R visitString(String s, P p);
158    
159        /**
160         * Visits a type value in an annotation.
161         * @param  t the value being visited
162         * @param  p a visitor-specified parameter
163         * @return the result of the visit
164         */
165        R visitType(TypeMirror t, P p);
166    
167        /**
168         * Visits an {@code enum} value in an annotation.
169         * @param  c the value being visited
170         * @param  p a visitor-specified parameter
171         * @return the result of the visit
172         */
173        R visitEnumConstant(VariableElement c, P p);
174    
175        /**
176         * Visits an annotation value in an annotation.
177         * @param  a the value being visited
178         * @param  p a visitor-specified parameter
179         * @return the result of the visit
180         */
181        R visitAnnotation(AnnotationMirror a, P p);
182    
183        /**
184         * Visits an array value in an annotation.
185         * @param  vals the value being visited
186         * @param  p a visitor-specified parameter
187         * @return the result of the visit
188         */
189        R visitArray(List<? extends AnnotationValue> vals, P p);
190    
191        /**
192         * Visits an unknown kind of annotation value.
193         * This can occur if the language evolves and new kinds
194         * of value can be stored in an annotation.
195         * @param  av the unknown value being visited
196         * @param  p a visitor-specified parameter
197         * @return the result of the visit
198         * @throws UnknownAnnotationValueException
199         *  a visitor implementation may optionally throw this exception
200         */
201        R visitUnknown(AnnotationValue av, P p);
202    }