src/share/classes/javax/lang/model/util/TypeKindVisitor6.java

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 1054
111bbf1ad913
child 1522
09f65aad4759
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package javax.lang.model.util;
    28 import javax.annotation.processing.SupportedSourceVersion;
    29 import javax.lang.model.SourceVersion;
    30 import javax.lang.model.type.*;
    31 import static javax.lang.model.SourceVersion.*;
    33 /**
    34  * A visitor of types based on their {@linkplain TypeKind kind} with
    35  * default behavior appropriate for the {@link SourceVersion#RELEASE_6
    36  * RELEASE_6} source version.  For {@linkplain
    37  * TypeMirror types} <tt><i>XYZ</i></tt> that may have more than one
    38  * kind, the <tt>visit<i>XYZ</i></tt> methods in this class delegate
    39  * to the <tt>visit<i>XYZKind</i></tt> method corresponding to the
    40  * first argument's kind.  The <tt>visit<i>XYZKind</i></tt> methods
    41  * call {@link #defaultAction defaultAction}, passing their arguments
    42  * to {@code defaultAction}'s corresponding parameters.
    43  *
    44  * <p> Methods in this class may be overridden subject to their
    45  * general contract.  Note that annotating methods in concrete
    46  * subclasses with {@link java.lang.Override @Override} will help
    47  * ensure that methods are overridden as intended.
    48  *
    49  * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented
    50  * by this class may have methods added to it in the future to
    51  * accommodate new, currently unknown, language structures added to
    52  * future versions of the Java&trade; programming language.
    53  * Therefore, methods whose names begin with {@code "visit"} may be
    54  * added to this class in the future; to avoid incompatibilities,
    55  * classes which extend this class should not declare any instance
    56  * methods with names beginning with {@code "visit"}.
    57  *
    58  * <p>When such a new visit method is added, the default
    59  * implementation in this class will be to call the {@link
    60  * #visitUnknown visitUnknown} method.  A new type kind visitor class
    61  * will also be introduced to correspond to the new language level;
    62  * this visitor will have different default behavior for the visit
    63  * method in question.  When the new visitor is introduced, all or
    64  * portions of this visitor may be deprecated.
    65  *
    66  * @param <R> the return type of this visitor's methods.  Use {@link
    67  *            Void} for visitors that do not need to return results.
    68  * @param <P> the type of the additional parameter to this visitor's
    69  *            methods.  Use {@code Void} for visitors that do not need an
    70  *            additional parameter.
    71  *
    72  * @author Joseph D. Darcy
    73  * @author Scott Seligman
    74  * @author Peter von der Ah&eacute;
    75  *
    76  * @see TypeKindVisitor7
    77  * @see TypeKindVisitor8
    78  * @since 1.6
    79  */
    80 @SupportedSourceVersion(RELEASE_6)
    81 public class TypeKindVisitor6<R, P> extends SimpleTypeVisitor6<R, P> {
    82     /**
    83      * Constructor for concrete subclasses to call; uses {@code null}
    84      * for the default value.
    85      */
    86     protected TypeKindVisitor6() {
    87         super(null);
    88     }
    91     /**
    92      * Constructor for concrete subclasses to call; uses the argument
    93      * for the default value.
    94      *
    95      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
    96      */
    97     protected TypeKindVisitor6(R defaultValue) {
    98         super(defaultValue);
    99     }
   101     /**
   102      * Visits a primitive type, dispatching to the visit method for
   103      * the specific {@linkplain TypeKind kind} of primitive type:
   104      * {@code BOOLEAN}, {@code BYTE}, etc.
   105      *
   106      * @param t {@inheritDoc}
   107      * @param p {@inheritDoc}
   108      * @return  the result of the kind-specific visit method
   109      */
   110     @Override
   111     public R visitPrimitive(PrimitiveType t, P p) {
   112         TypeKind k = t.getKind();
   113         switch (k) {
   114         case BOOLEAN:
   115             return visitPrimitiveAsBoolean(t, p);
   117         case BYTE:
   118             return visitPrimitiveAsByte(t, p);
   120         case SHORT:
   121             return visitPrimitiveAsShort(t, p);
   123         case INT:
   124             return visitPrimitiveAsInt(t, p);
   126         case LONG:
   127             return visitPrimitiveAsLong(t, p);
   129         case CHAR:
   130             return visitPrimitiveAsChar(t, p);
   132         case FLOAT:
   133             return visitPrimitiveAsFloat(t, p);
   135         case DOUBLE:
   136             return visitPrimitiveAsDouble(t, p);
   138         default:
   139             throw new AssertionError("Bad kind " + k + " for PrimitiveType" + t);
   140         }
   141     }
   143     /**
   144      * Visits a {@code BOOLEAN} primitive type by calling
   145      * {@code defaultAction}.
   146      *
   147      * @param t the type to visit
   148      * @param p a visitor-specified parameter
   149      * @return  the result of {@code defaultAction}
   150      */
   151     public R visitPrimitiveAsBoolean(PrimitiveType t, P p) {
   152         return defaultAction(t, p);
   153     }
   155     /**
   156      * Visits a {@code BYTE} primitive type by calling
   157      * {@code defaultAction}.
   158      *
   159      * @param t the type to visit
   160      * @param p a visitor-specified parameter
   161      * @return  the result of {@code defaultAction}
   162      */
   163     public R visitPrimitiveAsByte(PrimitiveType t, P p) {
   164         return defaultAction(t, p);
   165     }
   167     /**
   168      * Visits a {@code SHORT} primitive type by calling
   169      * {@code defaultAction}.
   170      *
   171      * @param t the type to visit
   172      * @param p a visitor-specified parameter
   173      * @return  the result of {@code defaultAction}
   174      */
   175     public R visitPrimitiveAsShort(PrimitiveType t, P p) {
   176         return defaultAction(t, p);
   177     }
   179     /**
   180      * Visits an {@code INT} primitive type by calling
   181      * {@code defaultAction}.
   182      *
   183      * @param t the type to visit
   184      * @param p a visitor-specified parameter
   185      * @return  the result of {@code defaultAction}
   186      */
   187     public R visitPrimitiveAsInt(PrimitiveType t, P p) {
   188         return defaultAction(t, p);
   189     }
   191     /**
   192      * Visits a {@code LONG} primitive type by calling
   193      * {@code defaultAction}.
   194      *
   195      * @param t the type to visit
   196      * @param p a visitor-specified parameter
   197      * @return  the result of {@code defaultAction}
   198      */
   199     public R visitPrimitiveAsLong(PrimitiveType t, P p) {
   200         return defaultAction(t, p);
   201     }
   203     /**
   204      * Visits a {@code CHAR} primitive type by calling
   205      * {@code defaultAction}.
   206      *
   207      * @param t the type to visit
   208      * @param p a visitor-specified parameter
   209      * @return  the result of {@code defaultAction}
   210      */
   211     public R visitPrimitiveAsChar(PrimitiveType t, P p) {
   212         return defaultAction(t, p);
   213     }
   215     /**
   216      * Visits a {@code FLOAT} primitive type by calling
   217      * {@code defaultAction}.
   218      *
   219      * @param t the type to visit
   220      * @param p a visitor-specified parameter
   221      * @return  the result of {@code defaultAction}
   222      */
   223     public R visitPrimitiveAsFloat(PrimitiveType t, P p) {
   224         return defaultAction(t, p);
   225     }
   227     /**
   228      * Visits a {@code DOUBLE} primitive type by calling
   229      * {@code defaultAction}.
   230      *
   231      * @param t the type to visit
   232      * @param p a visitor-specified parameter
   233      * @return  the result of {@code defaultAction}
   234      */
   235     public R visitPrimitiveAsDouble(PrimitiveType t, P p) {
   236         return defaultAction(t, p);
   237     }
   239     /**
   240      * Visits a {@link NoType} instance, dispatching to the visit method for
   241      * the specific {@linkplain TypeKind kind} of pseudo-type:
   242      * {@code VOID}, {@code PACKAGE}, or {@code NONE}.
   243      *
   244      * @param t {@inheritDoc}
   245      * @param p {@inheritDoc}
   246      * @return  the result of the kind-specific visit method
   247      */
   248     @Override
   249     public R visitNoType(NoType t, P p) {
   250         TypeKind k = t.getKind();
   251         switch (k) {
   252         case VOID:
   253             return visitNoTypeAsVoid(t, p);
   255         case PACKAGE:
   256             return visitNoTypeAsPackage(t, p);
   258         case NONE:
   259             return visitNoTypeAsNone(t, p);
   261         default:
   262             throw new AssertionError("Bad kind " + k + " for NoType" + t);
   263         }
   264     }
   266     /**
   267      * Visits a {@link TypeKind#VOID VOID} pseudo-type by calling
   268      * {@code defaultAction}.
   269      *
   270      * @param t the type to visit
   271      * @param p a visitor-specified parameter
   272      * @return  the result of {@code defaultAction}
   273      */
   274     public R visitNoTypeAsVoid(NoType t, P p) {
   275         return defaultAction(t, p);
   276     }
   278     /**
   279      * Visits a {@link TypeKind#PACKAGE PACKAGE} pseudo-type by calling
   280      * {@code defaultAction}.
   281      *
   282      * @param t the type to visit
   283      * @param p a visitor-specified parameter
   284      * @return  the result of {@code defaultAction}
   285      */
   286     public R visitNoTypeAsPackage(NoType t, P p) {
   287         return defaultAction(t, p);
   288     }
   290     /**
   291      * Visits a {@link TypeKind#NONE NONE} pseudo-type by calling
   292      * {@code defaultAction}.
   293      *
   294      * @param t the type to visit
   295      * @param p a visitor-specified parameter
   296      * @return  the result of {@code defaultAction}
   297      */
   298     public R visitNoTypeAsNone(NoType t, P p) {
   299         return defaultAction(t, p);
   300     }
   301 }

mercurial