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

Mon, 17 Jun 2013 14:46:01 -0700

author
darcy
date
Mon, 17 Jun 2013 14:46:01 -0700
changeset 1823
b7a10bc02e7a
parent 1522
09f65aad4759
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8016779: Fix doclint warnings in javax.lang.model
Reviewed-by: jjg

duke@1 1 /*
darcy@1522 2 * Copyright (c) 2005, 2013, 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 *
darcy@1522 66 * <p>Note that adding a default implementation of a new visit method
darcy@1522 67 * in a visitor class will occur instead of adding a <em>default
darcy@1522 68 * method</em> directly in the visitor interface since a Java SE 8
darcy@1522 69 * language feature cannot be used to this version of the API since
darcy@1522 70 * this version is required to be runnable on Java SE 7
darcy@1522 71 * implementations. Future versions of the API that are only required
darcy@1522 72 * to run on Java SE 8 and later may take advantage of default methods
darcy@1522 73 * in this situation.
darcy@1522 74 *
duke@1 75 * @param <R> the return type of this visitor's methods. Use {@link
duke@1 76 * Void} for visitors that do not need to return results.
duke@1 77 * @param <P> the type of the additional parameter to this visitor's
duke@1 78 * methods. Use {@code Void} for visitors that do not need an
duke@1 79 * additional parameter.
duke@1 80 *
duke@1 81 * @author Joseph D. Darcy
duke@1 82 * @author Scott Seligman
duke@1 83 * @author Peter von der Ah&eacute;
darcy@575 84 *
darcy@575 85 * @see TypeKindVisitor7
darcy@1054 86 * @see TypeKindVisitor8
duke@1 87 * @since 1.6
duke@1 88 */
duke@1 89 @SupportedSourceVersion(RELEASE_6)
duke@1 90 public class TypeKindVisitor6<R, P> extends SimpleTypeVisitor6<R, P> {
duke@1 91 /**
duke@1 92 * Constructor for concrete subclasses to call; uses {@code null}
duke@1 93 * for the default value.
duke@1 94 */
duke@1 95 protected TypeKindVisitor6() {
duke@1 96 super(null);
duke@1 97 }
duke@1 98
duke@1 99
duke@1 100 /**
duke@1 101 * Constructor for concrete subclasses to call; uses the argument
duke@1 102 * for the default value.
duke@1 103 *
duke@1 104 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
duke@1 105 */
duke@1 106 protected TypeKindVisitor6(R defaultValue) {
duke@1 107 super(defaultValue);
duke@1 108 }
duke@1 109
duke@1 110 /**
duke@1 111 * Visits a primitive type, dispatching to the visit method for
duke@1 112 * the specific {@linkplain TypeKind kind} of primitive type:
duke@1 113 * {@code BOOLEAN}, {@code BYTE}, etc.
duke@1 114 *
duke@1 115 * @param t {@inheritDoc}
duke@1 116 * @param p {@inheritDoc}
duke@1 117 * @return the result of the kind-specific visit method
duke@1 118 */
duke@1 119 @Override
duke@1 120 public R visitPrimitive(PrimitiveType t, P p) {
duke@1 121 TypeKind k = t.getKind();
duke@1 122 switch (k) {
duke@1 123 case BOOLEAN:
duke@1 124 return visitPrimitiveAsBoolean(t, p);
duke@1 125
duke@1 126 case BYTE:
duke@1 127 return visitPrimitiveAsByte(t, p);
duke@1 128
duke@1 129 case SHORT:
duke@1 130 return visitPrimitiveAsShort(t, p);
duke@1 131
duke@1 132 case INT:
duke@1 133 return visitPrimitiveAsInt(t, p);
duke@1 134
duke@1 135 case LONG:
duke@1 136 return visitPrimitiveAsLong(t, p);
duke@1 137
duke@1 138 case CHAR:
duke@1 139 return visitPrimitiveAsChar(t, p);
duke@1 140
duke@1 141 case FLOAT:
duke@1 142 return visitPrimitiveAsFloat(t, p);
duke@1 143
duke@1 144 case DOUBLE:
duke@1 145 return visitPrimitiveAsDouble(t, p);
duke@1 146
duke@1 147 default:
duke@1 148 throw new AssertionError("Bad kind " + k + " for PrimitiveType" + t);
duke@1 149 }
duke@1 150 }
duke@1 151
duke@1 152 /**
duke@1 153 * Visits a {@code BOOLEAN} primitive type by calling
duke@1 154 * {@code defaultAction}.
duke@1 155 *
duke@1 156 * @param t the type to visit
duke@1 157 * @param p a visitor-specified parameter
duke@1 158 * @return the result of {@code defaultAction}
duke@1 159 */
duke@1 160 public R visitPrimitiveAsBoolean(PrimitiveType t, P p) {
duke@1 161 return defaultAction(t, p);
duke@1 162 }
duke@1 163
duke@1 164 /**
duke@1 165 * Visits a {@code BYTE} primitive type by calling
duke@1 166 * {@code defaultAction}.
duke@1 167 *
duke@1 168 * @param t the type to visit
duke@1 169 * @param p a visitor-specified parameter
duke@1 170 * @return the result of {@code defaultAction}
duke@1 171 */
duke@1 172 public R visitPrimitiveAsByte(PrimitiveType t, P p) {
duke@1 173 return defaultAction(t, p);
duke@1 174 }
duke@1 175
duke@1 176 /**
duke@1 177 * Visits a {@code SHORT} primitive type by calling
duke@1 178 * {@code defaultAction}.
duke@1 179 *
duke@1 180 * @param t the type to visit
duke@1 181 * @param p a visitor-specified parameter
duke@1 182 * @return the result of {@code defaultAction}
duke@1 183 */
duke@1 184 public R visitPrimitiveAsShort(PrimitiveType t, P p) {
duke@1 185 return defaultAction(t, p);
duke@1 186 }
duke@1 187
duke@1 188 /**
duke@1 189 * Visits an {@code INT} primitive type by calling
duke@1 190 * {@code defaultAction}.
duke@1 191 *
duke@1 192 * @param t the type to visit
duke@1 193 * @param p a visitor-specified parameter
duke@1 194 * @return the result of {@code defaultAction}
duke@1 195 */
duke@1 196 public R visitPrimitiveAsInt(PrimitiveType t, P p) {
duke@1 197 return defaultAction(t, p);
duke@1 198 }
duke@1 199
duke@1 200 /**
duke@1 201 * Visits a {@code LONG} primitive type by calling
duke@1 202 * {@code defaultAction}.
duke@1 203 *
duke@1 204 * @param t the type to visit
duke@1 205 * @param p a visitor-specified parameter
duke@1 206 * @return the result of {@code defaultAction}
duke@1 207 */
duke@1 208 public R visitPrimitiveAsLong(PrimitiveType t, P p) {
duke@1 209 return defaultAction(t, p);
duke@1 210 }
duke@1 211
duke@1 212 /**
duke@1 213 * Visits a {@code CHAR} primitive type by calling
duke@1 214 * {@code defaultAction}.
duke@1 215 *
duke@1 216 * @param t the type to visit
duke@1 217 * @param p a visitor-specified parameter
duke@1 218 * @return the result of {@code defaultAction}
duke@1 219 */
duke@1 220 public R visitPrimitiveAsChar(PrimitiveType t, P p) {
duke@1 221 return defaultAction(t, p);
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * Visits a {@code FLOAT} primitive type by calling
duke@1 226 * {@code defaultAction}.
duke@1 227 *
duke@1 228 * @param t the type to visit
duke@1 229 * @param p a visitor-specified parameter
duke@1 230 * @return the result of {@code defaultAction}
duke@1 231 */
duke@1 232 public R visitPrimitiveAsFloat(PrimitiveType t, P p) {
duke@1 233 return defaultAction(t, p);
duke@1 234 }
duke@1 235
duke@1 236 /**
duke@1 237 * Visits a {@code DOUBLE} primitive type by calling
duke@1 238 * {@code defaultAction}.
duke@1 239 *
duke@1 240 * @param t the type to visit
duke@1 241 * @param p a visitor-specified parameter
duke@1 242 * @return the result of {@code defaultAction}
duke@1 243 */
duke@1 244 public R visitPrimitiveAsDouble(PrimitiveType t, P p) {
duke@1 245 return defaultAction(t, p);
duke@1 246 }
duke@1 247
duke@1 248 /**
duke@1 249 * Visits a {@link NoType} instance, dispatching to the visit method for
duke@1 250 * the specific {@linkplain TypeKind kind} of pseudo-type:
duke@1 251 * {@code VOID}, {@code PACKAGE}, or {@code NONE}.
duke@1 252 *
duke@1 253 * @param t {@inheritDoc}
duke@1 254 * @param p {@inheritDoc}
duke@1 255 * @return the result of the kind-specific visit method
duke@1 256 */
duke@1 257 @Override
duke@1 258 public R visitNoType(NoType t, P p) {
duke@1 259 TypeKind k = t.getKind();
duke@1 260 switch (k) {
duke@1 261 case VOID:
duke@1 262 return visitNoTypeAsVoid(t, p);
duke@1 263
duke@1 264 case PACKAGE:
duke@1 265 return visitNoTypeAsPackage(t, p);
duke@1 266
duke@1 267 case NONE:
duke@1 268 return visitNoTypeAsNone(t, p);
duke@1 269
duke@1 270 default:
duke@1 271 throw new AssertionError("Bad kind " + k + " for NoType" + t);
duke@1 272 }
duke@1 273 }
duke@1 274
duke@1 275 /**
duke@1 276 * Visits a {@link TypeKind#VOID VOID} pseudo-type by calling
duke@1 277 * {@code defaultAction}.
duke@1 278 *
duke@1 279 * @param t the type to visit
duke@1 280 * @param p a visitor-specified parameter
duke@1 281 * @return the result of {@code defaultAction}
duke@1 282 */
duke@1 283 public R visitNoTypeAsVoid(NoType t, P p) {
duke@1 284 return defaultAction(t, p);
duke@1 285 }
duke@1 286
duke@1 287 /**
duke@1 288 * Visits a {@link TypeKind#PACKAGE PACKAGE} pseudo-type by calling
duke@1 289 * {@code defaultAction}.
duke@1 290 *
duke@1 291 * @param t the type to visit
duke@1 292 * @param p a visitor-specified parameter
duke@1 293 * @return the result of {@code defaultAction}
duke@1 294 */
duke@1 295 public R visitNoTypeAsPackage(NoType t, P p) {
duke@1 296 return defaultAction(t, p);
duke@1 297 }
duke@1 298
duke@1 299 /**
duke@1 300 * Visits a {@link TypeKind#NONE NONE} pseudo-type by calling
duke@1 301 * {@code defaultAction}.
duke@1 302 *
duke@1 303 * @param t the type to visit
duke@1 304 * @param p a visitor-specified parameter
duke@1 305 * @return the result of {@code defaultAction}
duke@1 306 */
duke@1 307 public R visitNoTypeAsNone(NoType t, P p) {
duke@1 308 return defaultAction(t, p);
duke@1 309 }
duke@1 310 }

mercurial