duke@1: /*
darcy@1054: * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1: *
duke@1: * This code is free software; you can redistribute it and/or modify it
duke@1: * under the terms of the GNU General Public License version 2 only, as
ohair@554: * published by the Free Software Foundation. Oracle designates this
duke@1: * particular file as subject to the "Classpath" exception as provided
ohair@554: * by Oracle in the LICENSE file that accompanied this code.
duke@1: *
duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1: * version 2 for more details (a copy is included in the LICENSE file that
duke@1: * accompanied this code).
duke@1: *
duke@1: * You should have received a copy of the GNU General Public License version
duke@1: * 2 along with this work; if not, write to the Free Software Foundation,
duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1: *
ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554: * or visit www.oracle.com if you need additional information or have any
ohair@554: * questions.
duke@1: */
duke@1:
duke@1: package javax.lang.model.util;
duke@1:
duke@1:
duke@1: import java.util.List;
duke@1: import javax.lang.model.element.*;
duke@1:
duke@1: import javax.lang.model.type.TypeMirror;
duke@1: import static javax.lang.model.SourceVersion.*;
duke@1: import javax.lang.model.SourceVersion;
duke@1: import javax.annotation.processing.SupportedSourceVersion;
duke@1:
duke@1: /**
duke@1: * A simple visitor for annotation values with default behavior
duke@1: * appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
duke@1: * source version. Visit methods call {@link
duke@1: * #defaultAction} passing their arguments to {@code defaultAction}'s
duke@1: * corresponding parameters.
duke@1: *
duke@1: *
Methods in this class may be overridden subject to their
duke@1: * general contract. Note that annotating methods in concrete
duke@1: * subclasses with {@link java.lang.Override @Override} will help
duke@1: * ensure that methods are overridden as intended.
duke@1: *
duke@1: *
WARNING: The {@code AnnotationValueVisitor} interface
duke@1: * implemented by this class may have methods added to it in the
duke@1: * future to accommodate new, currently unknown, language structures
duke@1: * added to future versions of the Java™ programming language.
duke@1: * Therefore, methods whose names begin with {@code "visit"} may be
duke@1: * added to this class in the future; to avoid incompatibilities,
duke@1: * classes which extend this class should not declare any instance
duke@1: * methods with names beginning with {@code "visit"}.
duke@1: *
duke@1: *
When such a new visit method is added, the default
duke@1: * implementation in this class will be to call the {@link
duke@1: * #visitUnknown visitUnknown} method. A new simple annotation
duke@1: * value visitor class will also be introduced to correspond to the
duke@1: * new language level; this visitor will have different default
duke@1: * behavior for the visit method in question. When the new visitor is
duke@1: * introduced, all or portions of this visitor may be deprecated.
duke@1: *
duke@1: * @param the return type of this visitor's methods
duke@1: * @param the type of the additional parameter to this visitor's methods.
duke@1: *
duke@1: * @author Joseph D. Darcy
duke@1: * @author Scott Seligman
duke@1: * @author Peter von der Ahé
darcy@575: *
darcy@575: * @see SimpleAnnotationValueVisitor7
darcy@1054: * @see SimpleAnnotationValueVisitor8
duke@1: * @since 1.6
duke@1: */
duke@1: @SupportedSourceVersion(RELEASE_6)
duke@1: public class SimpleAnnotationValueVisitor6
duke@1: extends AbstractAnnotationValueVisitor6 {
duke@1:
duke@1: /**
duke@1: * Default value to be returned; {@link #defaultAction
duke@1: * defaultAction} returns this value unless the method is
duke@1: * overridden.
duke@1: */
duke@1: protected final R DEFAULT_VALUE;
duke@1:
duke@1: /**
duke@1: * Constructor for concrete subclasses; uses {@code null} for the
duke@1: * default value.
duke@1: */
duke@1: protected SimpleAnnotationValueVisitor6() {
duke@1: super();
duke@1: DEFAULT_VALUE = null;
duke@1: }
duke@1:
duke@1: /**
duke@1: * Constructor for concrete subclasses; uses the argument for the
duke@1: * default value.
duke@1: *
duke@1: * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
duke@1: */
duke@1: protected SimpleAnnotationValueVisitor6(R defaultValue) {
duke@1: super();
duke@1: DEFAULT_VALUE = defaultValue;
duke@1: }
duke@1:
duke@1: /**
duke@1: * The default action for visit methods. The implementation in
duke@1: * this class just returns {@link #DEFAULT_VALUE}; subclasses will
duke@1: * commonly override this method.
duke@1: *
duke@1: * @param o the value of the annotation
duke@1: * @param p a visitor-specified parameter
duke@1: * @return {@code DEFAULT_VALUE} unless overridden
duke@1: */
duke@1: protected R defaultAction(Object o, P p) {
duke@1: return DEFAULT_VALUE;
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param b {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitBoolean(boolean b, P p) {
duke@1: return defaultAction(b, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param b {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitByte(byte b, P p) {
duke@1: return defaultAction(b, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param c {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitChar(char c, P p) {
duke@1: return defaultAction(c, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param d {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitDouble(double d, P p) {
duke@1: return defaultAction(d, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param f {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitFloat(float f, P p) {
duke@1: return defaultAction(f, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param i {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitInt(int i, P p) {
duke@1: return defaultAction(i, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param i {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitLong(long i, P p) {
duke@1: return defaultAction(i, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param s {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitShort(short s, P p) {
duke@1: return defaultAction(s, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param s {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitString(String s, P p) {
duke@1: return defaultAction(s, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param t {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitType(TypeMirror t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param c {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitEnumConstant(VariableElement c, P p) {
duke@1: return defaultAction(c, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param a {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitAnnotation(AnnotationMirror a, P p) {
duke@1: return defaultAction(a, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc} This implementation calls {@code defaultAction}.
duke@1: *
duke@1: * @param vals {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitArray(List extends AnnotationValue> vals, P p) {
duke@1: return defaultAction(vals, p);
duke@1: }
duke@1: }