1 /*
   2  * Copyright 2010 Sun Microsystems, Inc.  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.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any 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  * Shared package private class to avoid code bloat.
  35  *
  36  * @param <R> the return type of this visitor's methods.  Use {@link
  37  *            Void} for visitors that do not need to return results.
  38  * @param <P> the type of the additional parameter to this visitor's
  39  *            methods.  Use {@code Void} for visitors that do not need an
  40  *            additional parameter.
  41  *
  42  * @author Joseph D. Darcy
  43  * @author Scott Seligman
  44  * @author Peter von der Ah&eacute;
  45  *
  46  * @since 1.7
  47  */
  48 class SharedSimpleTypeVisitor<R, P> extends AbstractTypeVisitor6<R, P> {
  49     /**
  50      * Default value to be returned; {@link #defaultAction
  51      * defaultAction} returns this value unless the method is
  52      * overridden.
  53      */
  54     protected final R DEFAULT_VALUE;
  55 
  56     /**
  57      * Constructor for concrete subclasses; uses {@code null} for the
  58      * default value.
  59      */
  60     protected SharedSimpleTypeVisitor() {
  61         DEFAULT_VALUE = null;
  62     }
  63 
  64     /**
  65      * Constructor for concrete subclasses; uses the argument for the
  66      * default value.
  67      *
  68      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
  69      */
  70     protected SharedSimpleTypeVisitor(R defaultValue) {
  71         DEFAULT_VALUE = defaultValue;
  72     }
  73 
  74     /**
  75      * The default action for visit methods.  The implementation in
  76      * this class just returns {@link #DEFAULT_VALUE}; subclasses will
  77      * commonly override this method.
  78      */
  79     protected R defaultAction(TypeMirror e, P p) {
  80         return DEFAULT_VALUE;
  81     }
  82 
  83     /**
  84      * {@inheritDoc} This implementation calls {@code defaultAction}.
  85      *
  86      * @param t {@inheritDoc}
  87      * @param p {@inheritDoc}
  88      * @return  the result of {@code defaultAction}
  89      */
  90     public R visitPrimitive(PrimitiveType t, P p) {
  91         return defaultAction(t, p);
  92     }
  93 
  94     /**
  95      * {@inheritDoc} This implementation calls {@code defaultAction}.
  96      *
  97      * @param t {@inheritDoc}
  98      * @param p {@inheritDoc}
  99      * @return  the result of {@code defaultAction}
 100      */
 101     public R visitNull(NullType t, P p){
 102         return defaultAction(t, p);
 103     }
 104 
 105     /**
 106      * {@inheritDoc} This implementation calls {@code defaultAction}.
 107      *
 108      * @param t {@inheritDoc}
 109      * @param p {@inheritDoc}
 110      * @return  the result of {@code defaultAction}
 111      */
 112     public R visitArray(ArrayType t, P p){
 113         return defaultAction(t, p);
 114     }
 115 
 116     /**
 117      * {@inheritDoc} This implementation calls {@code defaultAction}.
 118      *
 119      * @param t {@inheritDoc}
 120      * @param p {@inheritDoc}
 121      * @return  the result of {@code defaultAction}
 122      */
 123     public R visitDeclared(DeclaredType t, P p){
 124         return defaultAction(t, p);
 125     }
 126 
 127     /**
 128      * {@inheritDoc} This implementation calls {@code defaultAction}.
 129      *
 130      * @param t {@inheritDoc}
 131      * @param p {@inheritDoc}
 132      * @return  the result of {@code defaultAction}
 133      */
 134     public R visitError(ErrorType t, P p){
 135         return defaultAction(t, p);
 136     }
 137 
 138     /**
 139      * {@inheritDoc} This implementation calls {@code defaultAction}.
 140      *
 141      * @param t {@inheritDoc}
 142      * @param p {@inheritDoc}
 143      * @return  the result of {@code defaultAction}
 144      */
 145     public R visitTypeVariable(TypeVariable t, P p){
 146         return defaultAction(t, p);
 147     }
 148 
 149     /**
 150      * {@inheritDoc} This implementation calls {@code defaultAction}.
 151      *
 152      * @param t {@inheritDoc}
 153      * @param p {@inheritDoc}
 154      * @return  the result of {@code defaultAction}
 155      */
 156     public R visitWildcard(WildcardType t, P p){
 157         return defaultAction(t, p);
 158     }
 159 
 160     /**
 161      * {@inheritDoc} 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 visitExecutable(ExecutableType t, P p) {
 168         return defaultAction(t, p);
 169     }
 170 
 171     /**
 172      * {@inheritDoc} This implementation calls {@code defaultAction}.
 173      *
 174      * @param t {@inheritDoc}
 175      * @param p {@inheritDoc}
 176      * @return  the result of {@code defaultAction}
 177      */
 178     public R visitNoType(NoType t, P p){
 179         return defaultAction(t, p);
 180     }
 181 }