duke@1: /*
darcy@1522: * Copyright (c) 2005, 2013, 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:
jjg@1357: import javax.annotation.processing.SupportedSourceVersion;
jjg@1357: import javax.lang.model.SourceVersion;
duke@1: import javax.lang.model.type.*;
duke@1: import static javax.lang.model.SourceVersion.*;
duke@1:
duke@1: /**
duke@1: * A visitor of types based on their {@linkplain TypeKind kind} with
duke@1: * default behavior appropriate for the {@link SourceVersion#RELEASE_6
duke@1: * RELEASE_6} source version. For {@linkplain
duke@1: * TypeMirror types} XYZ that may have more than one
duke@1: * kind, the visitXYZ methods in this class delegate
duke@1: * to the visitXYZKind method corresponding to the
duke@1: * first argument's kind. The visitXYZKind methods
duke@1: * call {@link #defaultAction defaultAction}, passing their arguments
duke@1: * to {@code defaultAction}'s 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 TypeVisitor} interface implemented
duke@1: * by this class may have methods added to it in the future to
duke@1: * accommodate new, currently unknown, language structures added to
duke@1: * 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 type kind visitor class
duke@1: * will also be introduced to correspond to the new language level;
duke@1: * this visitor will have different default behavior for the visit
duke@1: * method in question. When the new visitor is introduced, all or
duke@1: * portions of this visitor may be deprecated.
duke@1: *
darcy@1522: *
Note that adding a default implementation of a new visit method
darcy@1522: * in a visitor class will occur instead of adding a default
darcy@1522: * method directly in the visitor interface since a Java SE 8
darcy@1522: * language feature cannot be used to this version of the API since
darcy@1522: * this version is required to be runnable on Java SE 7
darcy@1522: * implementations. Future versions of the API that are only required
darcy@1522: * to run on Java SE 8 and later may take advantage of default methods
darcy@1522: * in this situation.
darcy@1522: *
duke@1: * @param the return type of this visitor's methods. Use {@link
duke@1: * Void} for visitors that do not need to return results.
duke@1: * @param the type of the additional parameter to this visitor's
duke@1: * methods. Use {@code Void} for visitors that do not need an
duke@1: * additional parameter.
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 TypeKindVisitor7
darcy@1054: * @see TypeKindVisitor8
duke@1: * @since 1.6
duke@1: */
duke@1: @SupportedSourceVersion(RELEASE_6)
duke@1: public class TypeKindVisitor6 extends SimpleTypeVisitor6 {
duke@1: /**
duke@1: * Constructor for concrete subclasses to call; uses {@code null}
duke@1: * for the default value.
duke@1: */
duke@1: protected TypeKindVisitor6() {
duke@1: super(null);
duke@1: }
duke@1:
duke@1:
duke@1: /**
duke@1: * Constructor for concrete subclasses to call; uses the argument
duke@1: * for the default value.
duke@1: *
duke@1: * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
duke@1: */
duke@1: protected TypeKindVisitor6(R defaultValue) {
duke@1: super(defaultValue);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a primitive type, dispatching to the visit method for
duke@1: * the specific {@linkplain TypeKind kind} of primitive type:
duke@1: * {@code BOOLEAN}, {@code BYTE}, etc.
duke@1: *
duke@1: * @param t {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of the kind-specific visit method
duke@1: */
duke@1: @Override
duke@1: public R visitPrimitive(PrimitiveType t, P p) {
duke@1: TypeKind k = t.getKind();
duke@1: switch (k) {
duke@1: case BOOLEAN:
duke@1: return visitPrimitiveAsBoolean(t, p);
duke@1:
duke@1: case BYTE:
duke@1: return visitPrimitiveAsByte(t, p);
duke@1:
duke@1: case SHORT:
duke@1: return visitPrimitiveAsShort(t, p);
duke@1:
duke@1: case INT:
duke@1: return visitPrimitiveAsInt(t, p);
duke@1:
duke@1: case LONG:
duke@1: return visitPrimitiveAsLong(t, p);
duke@1:
duke@1: case CHAR:
duke@1: return visitPrimitiveAsChar(t, p);
duke@1:
duke@1: case FLOAT:
duke@1: return visitPrimitiveAsFloat(t, p);
duke@1:
duke@1: case DOUBLE:
duke@1: return visitPrimitiveAsDouble(t, p);
duke@1:
duke@1: default:
duke@1: throw new AssertionError("Bad kind " + k + " for PrimitiveType" + t);
duke@1: }
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code BOOLEAN} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsBoolean(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code BYTE} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsByte(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code SHORT} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsShort(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits an {@code INT} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsInt(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code LONG} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsLong(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code CHAR} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsChar(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code FLOAT} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsFloat(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@code DOUBLE} primitive type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitPrimitiveAsDouble(PrimitiveType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@link NoType} instance, dispatching to the visit method for
duke@1: * the specific {@linkplain TypeKind kind} of pseudo-type:
duke@1: * {@code VOID}, {@code PACKAGE}, or {@code NONE}.
duke@1: *
duke@1: * @param t {@inheritDoc}
duke@1: * @param p {@inheritDoc}
duke@1: * @return the result of the kind-specific visit method
duke@1: */
duke@1: @Override
duke@1: public R visitNoType(NoType t, P p) {
duke@1: TypeKind k = t.getKind();
duke@1: switch (k) {
duke@1: case VOID:
duke@1: return visitNoTypeAsVoid(t, p);
duke@1:
duke@1: case PACKAGE:
duke@1: return visitNoTypeAsPackage(t, p);
duke@1:
duke@1: case NONE:
duke@1: return visitNoTypeAsNone(t, p);
duke@1:
duke@1: default:
duke@1: throw new AssertionError("Bad kind " + k + " for NoType" + t);
duke@1: }
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@link TypeKind#VOID VOID} pseudo-type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitNoTypeAsVoid(NoType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@link TypeKind#PACKAGE PACKAGE} pseudo-type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitNoTypeAsPackage(NoType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Visits a {@link TypeKind#NONE NONE} pseudo-type by calling
duke@1: * {@code defaultAction}.
duke@1: *
duke@1: * @param t the type to visit
duke@1: * @param p a visitor-specified parameter
duke@1: * @return the result of {@code defaultAction}
duke@1: */
duke@1: public R visitNoTypeAsNone(NoType t, P p) {
duke@1: return defaultAction(t, p);
duke@1: }
duke@1: }