1 /*
   2  * Copyright (c) 2005, 2020, 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  */
  25 
  26 package javax.lang.model.util;
  27 
  28 import javax.lang.model.type.*;
  29 import javax.annotation.processing.SupportedSourceVersion;
  30 import javax.lang.model.SourceVersion;
  31 import static javax.lang.model.SourceVersion.*;
  32 
  33 
  34 /**
  35  * A simple visitor of types with default behavior appropriate for the
  36  * {@link SourceVersion#RELEASE_6 RELEASE_6} source version.
  37  *
  38  * Visit methods corresponding to {@code RELEASE_6} language
  39  * constructs call {@link #defaultAction defaultAction}, passing their
  40  * arguments to {@code defaultAction}'s corresponding parameters.
  41  *
  42  * For constructs introduced in {@code RELEASE_7} and later, {@code
  43  * visitUnknown} is called instead.
  44  *
  45  *
  46  * @apiNote
  47  * Methods in this class may be overridden subject to their general
  48  * contract.
  49  *
  50  * <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
  51  * TypeVisitor} interface implemented by this class may have methods
  52  * added to it in the future to accommodate new, currently unknown,
  53  * language structures added to future versions of the Java
  54  * programming language.  Therefore, methods whose names begin with
  55  * {@code "visit"} may be added to this class in the future; to avoid
  56  * incompatibilities, classes and subclasses which extend this class
  57  * should not declare any instance methods with names beginning with
  58  * {@code "visit"}.</p>
  59  *
  60  * <p>When such a new visit method is added, the default
  61  * implementation in this class will be to directly or indirectly call
  62  * the {@link #visitUnknown visitUnknown} method.  A new simple type
  63  * visitor class will also be introduced to correspond to the new
  64  * language level; this visitor will have different default behavior
  65  * for the visit method in question.  When a new visitor is
  66  * introduced, portions of this visitor class may be deprecated,
  67  * including its constructors.
  68  *
  69  * @param <R> the return type of this visitor's methods.  Use {@link
  70  *            Void} for visitors that do not need to return results.
  71  * @param <P> the type of the additional parameter to this visitor's
  72  *            methods.  Use {@code Void} for visitors that do not need an
  73  *            additional parameter.
  74  *
  75  * @author Joseph D. Darcy
  76  * @author Scott Seligman
  77  * @author Peter von der Ah&eacute;
  78  *
  79  * @see SimpleTypeVisitor7
  80  * @see SimpleTypeVisitor8
  81  * @see SimpleTypeVisitor9
  82  * @see SimpleTypeVisitor14
  83  * @since 1.6
  84  */
  85 @SupportedSourceVersion(RELEASE_6)
  86 public class SimpleTypeVisitor6<R, P> extends AbstractTypeVisitor6<R, P> {
  87     /**
  88      * Default value to be returned; {@link #defaultAction
  89      * defaultAction} returns this value unless the method is
  90      * overridden.
  91      */
  92     protected final R DEFAULT_VALUE;
  93 
  94     /**
  95      * Constructor for concrete subclasses; uses {@code null} for the
  96      * default value.
  97      * @deprecated Release 6 is obsolete; update to a visitor for a newer
  98      * release level.
  99      */
 100     @Deprecated(since="9")
 101     protected SimpleTypeVisitor6(){
 102         DEFAULT_VALUE = null;
 103     }
 104 
 105     /**
 106      * Constructor for concrete subclasses; uses the argument for the
 107      * default value.
 108      *
 109      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
 110      * @deprecated Release 6 is obsolete; update to a visitor for a newer
 111      * release level.
 112      */
 113     @Deprecated(since="9")
 114     protected SimpleTypeVisitor6(R defaultValue){
 115         DEFAULT_VALUE = defaultValue;
 116     }
 117 
 118     /**
 119      * The default action for visit methods.
 120      *
 121      * @implSpec The implementation in this class just returns {@link
 122      * #DEFAULT_VALUE}; subclasses will commonly override this method.
 123      *
 124      * @param e the type to process
 125      * @param p a visitor-specified parameter
 126      * @return {@code DEFAULT_VALUE} unless overridden
 127      */
 128     protected R defaultAction(TypeMirror e, P p) {
 129         return DEFAULT_VALUE;
 130     }
 131 
 132     /**
 133      * {@inheritDoc}
 134      *
 135      * @implSpec This implementation calls {@code defaultAction}.
 136      *
 137      * @param t {@inheritDoc}
 138      * @param p {@inheritDoc}
 139      * @return  the result of {@code defaultAction}
 140      */
 141     public R visitPrimitive(PrimitiveType t, P p) {
 142         return defaultAction(t, p);
 143     }
 144 
 145     /**
 146      * {@inheritDoc} This implementation calls {@code defaultAction}.
 147      *
 148      * @implSpec This implementation calls {@code defaultAction}.
 149      *
 150      * @param t {@inheritDoc}
 151      * @param p {@inheritDoc}
 152      * @return  the result of {@code defaultAction}
 153      */
 154     public R visitNull(NullType t, P p){
 155         return defaultAction(t, p);
 156     }
 157 
 158     /**
 159      * {@inheritDoc}
 160      *
 161      * @implSpec This implementation calls {@code defaultAction}.
 162      *
 163      * @param t {@inheritDoc}
 164      * @param p {@inheritDoc}
 165      * @return  the result of {@code defaultAction}
 166      */
 167     public R visitArray(ArrayType t, P p){
 168         return defaultAction(t, p);
 169     }
 170 
 171     /**
 172      * {@inheritDoc}
 173      *
 174      * @implSpec This implementation calls {@code defaultAction}.
 175      *
 176      * @param t {@inheritDoc}
 177      * @param p {@inheritDoc}
 178      * @return  the result of {@code defaultAction}
 179      */
 180     public R visitDeclared(DeclaredType t, P p){
 181         return defaultAction(t, p);
 182     }
 183 
 184     /**
 185      * {@inheritDoc}
 186      *
 187      * @implSpec This implementation calls {@code defaultAction}.
 188      *
 189      * @param t {@inheritDoc}
 190      * @param p {@inheritDoc}
 191      * @return  the result of {@code defaultAction}
 192      */
 193     public R visitError(ErrorType t, P p){
 194         return defaultAction(t, p);
 195     }
 196 
 197     /**
 198      * {@inheritDoc}
 199      *
 200      * @implSpec This implementation calls {@code defaultAction}.
 201      *
 202      * @param t {@inheritDoc}
 203      * @param p {@inheritDoc}
 204      * @return  the result of {@code defaultAction}
 205      */
 206     public R visitTypeVariable(TypeVariable t, P p){
 207         return defaultAction(t, p);
 208     }
 209 
 210     /**
 211      * {@inheritDoc}
 212      *
 213      * @implSpec This implementation calls {@code defaultAction}.
 214      *
 215      * @param t {@inheritDoc}
 216      * @param p {@inheritDoc}
 217      * @return  the result of {@code defaultAction}
 218      */
 219     public R visitWildcard(WildcardType t, P p){
 220         return defaultAction(t, p);
 221     }
 222 
 223     /**
 224      * {@inheritDoc}
 225      *
 226      * @implSpec This implementation calls {@code defaultAction}.
 227      *
 228      * @param t {@inheritDoc}
 229      * @param p {@inheritDoc}
 230      * @return  the result of {@code defaultAction}
 231      */
 232     public R visitExecutable(ExecutableType t, P p) {
 233         return defaultAction(t, p);
 234     }
 235 
 236     /**
 237      * {@inheritDoc}
 238      *
 239      * @implSpec This implementation calls {@code defaultAction}.
 240      *
 241      * @param t {@inheritDoc}
 242      * @param p {@inheritDoc}
 243      * @return  the result of {@code defaultAction}
 244      */
 245     public R visitNoType(NoType t, P p){
 246         return defaultAction(t, p);
 247     }
 248 }