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

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

mercurial