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

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.lang.model.util;
aoqi@0 27
aoqi@0 28 import javax.lang.model.element.*;
aoqi@0 29 import static javax.lang.model.element.ElementKind.*;
aoqi@0 30 import javax.annotation.processing.SupportedSourceVersion;
aoqi@0 31 import static javax.lang.model.SourceVersion.*;
aoqi@0 32 import javax.lang.model.SourceVersion;
aoqi@0 33
aoqi@0 34
aoqi@0 35 /**
aoqi@0 36 * A visitor of program elements based on their {@linkplain
aoqi@0 37 * ElementKind kind} with default behavior appropriate for the {@link
aoqi@0 38 * SourceVersion#RELEASE_6 RELEASE_6} source version. For {@linkplain
aoqi@0 39 * Element elements} <tt><i>XYZ</i></tt> that may have more than one
aoqi@0 40 * kind, the <tt>visit<i>XYZ</i></tt> methods in this class delegate
aoqi@0 41 * to the <tt>visit<i>XYZKind</i></tt> method corresponding to the
aoqi@0 42 * first argument's kind. The <tt>visit<i>XYZKind</i></tt> methods
aoqi@0 43 * call {@link #defaultAction defaultAction}, passing their arguments
aoqi@0 44 * to {@code defaultAction}'s corresponding parameters.
aoqi@0 45 *
aoqi@0 46 * <p> Methods in this class may be overridden subject to their
aoqi@0 47 * general contract. Note that annotating methods in concrete
aoqi@0 48 * subclasses with {@link java.lang.Override @Override} will help
aoqi@0 49 * ensure that methods are overridden as intended.
aoqi@0 50 *
aoqi@0 51 * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
aoqi@0 52 * implemented by this class may have methods added to it or the
aoqi@0 53 * {@code ElementKind} {@code enum} used in this case may have
aoqi@0 54 * constants added to it in the future to accommodate new, currently
aoqi@0 55 * unknown, language structures added to future versions of the
aoqi@0 56 * Java&trade; programming language. Therefore, methods whose names
aoqi@0 57 * begin with {@code "visit"} may be added to this class in the
aoqi@0 58 * future; to avoid incompatibilities, classes which extend this class
aoqi@0 59 * should not declare any instance methods with names beginning with
aoqi@0 60 * {@code "visit"}.
aoqi@0 61 *
aoqi@0 62 * <p>When such a new visit method is added, the default
aoqi@0 63 * implementation in this class will be to call the {@link
aoqi@0 64 * #visitUnknown visitUnknown} method. A new abstract element kind
aoqi@0 65 * visitor class will also be introduced to correspond to the new
aoqi@0 66 * language level; this visitor will have different default behavior
aoqi@0 67 * for the visit method in question. When the new visitor is
aoqi@0 68 * introduced, all or portions of this visitor may be deprecated.
aoqi@0 69 *
aoqi@0 70 * <p>Note that adding a default implementation of a new visit method
aoqi@0 71 * in a visitor class will occur instead of adding a <em>default
aoqi@0 72 * method</em> directly in the visitor interface since a Java SE 8
aoqi@0 73 * language feature cannot be used to this version of the API since
aoqi@0 74 * this version is required to be runnable on Java SE 7
aoqi@0 75 * implementations. Future versions of the API that are only required
aoqi@0 76 * to run on Java SE 8 and later may take advantage of default methods
aoqi@0 77 * in this situation.
aoqi@0 78 *
aoqi@0 79 * @param <R> the return type of this visitor's methods. Use {@link
aoqi@0 80 * Void} for visitors that do not need to return results.
aoqi@0 81 * @param <P> the type of the additional parameter to this visitor's
aoqi@0 82 * methods. Use {@code Void} for visitors that do not need an
aoqi@0 83 * additional parameter.
aoqi@0 84 *
aoqi@0 85 * @author Joseph D. Darcy
aoqi@0 86 * @author Scott Seligman
aoqi@0 87 * @author Peter von der Ah&eacute;
aoqi@0 88 *
aoqi@0 89 * @see ElementKindVisitor7
aoqi@0 90 * @see ElementKindVisitor8
aoqi@0 91 * @since 1.6
aoqi@0 92 */
aoqi@0 93 @SupportedSourceVersion(RELEASE_6)
aoqi@0 94 public class ElementKindVisitor6<R, P>
aoqi@0 95 extends SimpleElementVisitor6<R, P> {
aoqi@0 96 /**
aoqi@0 97 * Constructor for concrete subclasses; uses {@code null} for the
aoqi@0 98 * default value.
aoqi@0 99 */
aoqi@0 100 protected ElementKindVisitor6() {
aoqi@0 101 super(null);
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 /**
aoqi@0 105 * Constructor for concrete subclasses; uses the argument for the
aoqi@0 106 * default value.
aoqi@0 107 *
aoqi@0 108 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
aoqi@0 109 */
aoqi@0 110 protected ElementKindVisitor6(R defaultValue) {
aoqi@0 111 super(defaultValue);
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 /**
aoqi@0 115 * {@inheritDoc}
aoqi@0 116 *
aoqi@0 117 * The element argument has kind {@code PACKAGE}.
aoqi@0 118 *
aoqi@0 119 * @param e {@inheritDoc}
aoqi@0 120 * @param p {@inheritDoc}
aoqi@0 121 * @return {@inheritDoc}
aoqi@0 122 */
aoqi@0 123 @Override
aoqi@0 124 public R visitPackage(PackageElement e, P p) {
aoqi@0 125 assert e.getKind() == PACKAGE: "Bad kind on PackageElement";
aoqi@0 126 return defaultAction(e, p);
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 /**
aoqi@0 130 * Visits a type element, dispatching to the visit method for the
aoqi@0 131 * specific {@linkplain ElementKind kind} of type, {@code
aoqi@0 132 * ANNOTATION_TYPE}, {@code CLASS}, {@code ENUM}, or {@code
aoqi@0 133 * INTERFACE}.
aoqi@0 134 *
aoqi@0 135 * @param e {@inheritDoc}
aoqi@0 136 * @param p {@inheritDoc}
aoqi@0 137 * @return the result of the kind-specific visit method
aoqi@0 138 */
aoqi@0 139 @Override
aoqi@0 140 public R visitType(TypeElement e, P p) {
aoqi@0 141 ElementKind k = e.getKind();
aoqi@0 142 switch(k) {
aoqi@0 143 case ANNOTATION_TYPE:
aoqi@0 144 return visitTypeAsAnnotationType(e, p);
aoqi@0 145
aoqi@0 146 case CLASS:
aoqi@0 147 return visitTypeAsClass(e, p);
aoqi@0 148
aoqi@0 149 case ENUM:
aoqi@0 150 return visitTypeAsEnum(e, p);
aoqi@0 151
aoqi@0 152 case INTERFACE:
aoqi@0 153 return visitTypeAsInterface(e, p);
aoqi@0 154
aoqi@0 155 default:
aoqi@0 156 throw new AssertionError("Bad kind " + k + " for TypeElement" + e);
aoqi@0 157 }
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 /**
aoqi@0 161 * Visits an {@code ANNOTATION_TYPE} type element by calling
aoqi@0 162 * {@code defaultAction}.
aoqi@0 163 *
aoqi@0 164 * @param e the element to visit
aoqi@0 165 * @param p a visitor-specified parameter
aoqi@0 166 * @return the result of {@code defaultAction}
aoqi@0 167 */
aoqi@0 168 public R visitTypeAsAnnotationType(TypeElement e, P p) {
aoqi@0 169 return defaultAction(e, p);
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 /**
aoqi@0 173 * Visits a {@code CLASS} type element by calling {@code
aoqi@0 174 * defaultAction}.
aoqi@0 175 *
aoqi@0 176 * @param e the element to visit
aoqi@0 177 * @param p a visitor-specified parameter
aoqi@0 178 * @return the result of {@code defaultAction}
aoqi@0 179 */
aoqi@0 180 public R visitTypeAsClass(TypeElement e, P p) {
aoqi@0 181 return defaultAction(e, p);
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 /**
aoqi@0 185 * Visits an {@code ENUM} type element by calling {@code
aoqi@0 186 * defaultAction}.
aoqi@0 187 *
aoqi@0 188 * @param e the element to visit
aoqi@0 189 * @param p a visitor-specified parameter
aoqi@0 190 * @return the result of {@code defaultAction}
aoqi@0 191 */
aoqi@0 192 public R visitTypeAsEnum(TypeElement e, P p) {
aoqi@0 193 return defaultAction(e, p);
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 /**
aoqi@0 197 * Visits an {@code INTERFACE} type element by calling {@code
aoqi@0 198 * defaultAction}.
aoqi@0 199 *.
aoqi@0 200 * @param e the element to visit
aoqi@0 201 * @param p a visitor-specified parameter
aoqi@0 202 * @return the result of {@code defaultAction}
aoqi@0 203 */
aoqi@0 204 public R visitTypeAsInterface(TypeElement e, P p) {
aoqi@0 205 return defaultAction(e, p);
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 /**
aoqi@0 209 * Visits a variable element, dispatching to the visit method for
aoqi@0 210 * the specific {@linkplain ElementKind kind} of variable, {@code
aoqi@0 211 * ENUM_CONSTANT}, {@code EXCEPTION_PARAMETER}, {@code FIELD},
aoqi@0 212 * {@code LOCAL_VARIABLE}, {@code PARAMETER}, or {@code RESOURCE_VARIABLE}.
aoqi@0 213 *
aoqi@0 214 * @param e {@inheritDoc}
aoqi@0 215 * @param p {@inheritDoc}
aoqi@0 216 * @return the result of the kind-specific visit method
aoqi@0 217 */
aoqi@0 218 @Override
aoqi@0 219 public R visitVariable(VariableElement e, P p) {
aoqi@0 220 ElementKind k = e.getKind();
aoqi@0 221 switch(k) {
aoqi@0 222 case ENUM_CONSTANT:
aoqi@0 223 return visitVariableAsEnumConstant(e, p);
aoqi@0 224
aoqi@0 225 case EXCEPTION_PARAMETER:
aoqi@0 226 return visitVariableAsExceptionParameter(e, p);
aoqi@0 227
aoqi@0 228 case FIELD:
aoqi@0 229 return visitVariableAsField(e, p);
aoqi@0 230
aoqi@0 231 case LOCAL_VARIABLE:
aoqi@0 232 return visitVariableAsLocalVariable(e, p);
aoqi@0 233
aoqi@0 234 case PARAMETER:
aoqi@0 235 return visitVariableAsParameter(e, p);
aoqi@0 236
aoqi@0 237 case RESOURCE_VARIABLE:
aoqi@0 238 return visitVariableAsResourceVariable(e, p);
aoqi@0 239
aoqi@0 240 default:
aoqi@0 241 throw new AssertionError("Bad kind " + k + " for VariableElement" + e);
aoqi@0 242 }
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 /**
aoqi@0 246 * Visits an {@code ENUM_CONSTANT} variable element by calling
aoqi@0 247 * {@code defaultAction}.
aoqi@0 248 *
aoqi@0 249 * @param e the element to visit
aoqi@0 250 * @param p a visitor-specified parameter
aoqi@0 251 * @return the result of {@code defaultAction}
aoqi@0 252 */
aoqi@0 253 public R visitVariableAsEnumConstant(VariableElement e, P p) {
aoqi@0 254 return defaultAction(e, p);
aoqi@0 255 }
aoqi@0 256
aoqi@0 257 /**
aoqi@0 258 * Visits an {@code EXCEPTION_PARAMETER} variable element by calling
aoqi@0 259 * {@code defaultAction}.
aoqi@0 260 *
aoqi@0 261 * @param e the element to visit
aoqi@0 262 * @param p a visitor-specified parameter
aoqi@0 263 * @return the result of {@code defaultAction}
aoqi@0 264 */
aoqi@0 265 public R visitVariableAsExceptionParameter(VariableElement e, P p) {
aoqi@0 266 return defaultAction(e, p);
aoqi@0 267 }
aoqi@0 268
aoqi@0 269 /**
aoqi@0 270 * Visits a {@code FIELD} variable element by calling
aoqi@0 271 * {@code defaultAction}.
aoqi@0 272 *
aoqi@0 273 * @param e the element to visit
aoqi@0 274 * @param p a visitor-specified parameter
aoqi@0 275 * @return the result of {@code defaultAction}
aoqi@0 276 */
aoqi@0 277 public R visitVariableAsField(VariableElement e, P p) {
aoqi@0 278 return defaultAction(e, p);
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 /**
aoqi@0 282 * Visits a {@code LOCAL_VARIABLE} variable element by calling
aoqi@0 283 * {@code defaultAction}.
aoqi@0 284 *
aoqi@0 285 * @param e the element to visit
aoqi@0 286 * @param p a visitor-specified parameter
aoqi@0 287 * @return the result of {@code defaultAction}
aoqi@0 288 */
aoqi@0 289 public R visitVariableAsLocalVariable(VariableElement e, P p) {
aoqi@0 290 return defaultAction(e, p);
aoqi@0 291 }
aoqi@0 292
aoqi@0 293 /**
aoqi@0 294 * Visits a {@code PARAMETER} variable element by calling
aoqi@0 295 * {@code defaultAction}.
aoqi@0 296 *
aoqi@0 297 * @param e the element to visit
aoqi@0 298 * @param p a visitor-specified parameter
aoqi@0 299 * @return the result of {@code defaultAction}
aoqi@0 300 */
aoqi@0 301 public R visitVariableAsParameter(VariableElement e, P p) {
aoqi@0 302 return defaultAction(e, p);
aoqi@0 303 }
aoqi@0 304
aoqi@0 305 /**
aoqi@0 306 * Visits a {@code RESOURCE_VARIABLE} variable element by calling
aoqi@0 307 * {@code visitUnknown}.
aoqi@0 308 *
aoqi@0 309 * @param e the element to visit
aoqi@0 310 * @param p a visitor-specified parameter
aoqi@0 311 * @return the result of {@code visitUnknown}
aoqi@0 312 *
aoqi@0 313 * @since 1.7
aoqi@0 314 */
aoqi@0 315 public R visitVariableAsResourceVariable(VariableElement e, P p) {
aoqi@0 316 return visitUnknown(e, p);
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 /**
aoqi@0 320 * Visits an executable element, dispatching to the visit method
aoqi@0 321 * for the specific {@linkplain ElementKind kind} of executable,
aoqi@0 322 * {@code CONSTRUCTOR}, {@code INSTANCE_INIT}, {@code METHOD}, or
aoqi@0 323 * {@code STATIC_INIT}.
aoqi@0 324 *
aoqi@0 325 * @param e {@inheritDoc}
aoqi@0 326 * @param p {@inheritDoc}
aoqi@0 327 * @return the result of the kind-specific visit method
aoqi@0 328 */
aoqi@0 329 @Override
aoqi@0 330 public R visitExecutable(ExecutableElement e, P p) {
aoqi@0 331 ElementKind k = e.getKind();
aoqi@0 332 switch(k) {
aoqi@0 333 case CONSTRUCTOR:
aoqi@0 334 return visitExecutableAsConstructor(e, p);
aoqi@0 335
aoqi@0 336 case INSTANCE_INIT:
aoqi@0 337 return visitExecutableAsInstanceInit(e, p);
aoqi@0 338
aoqi@0 339 case METHOD:
aoqi@0 340 return visitExecutableAsMethod(e, p);
aoqi@0 341
aoqi@0 342 case STATIC_INIT:
aoqi@0 343 return visitExecutableAsStaticInit(e, p);
aoqi@0 344
aoqi@0 345 default:
aoqi@0 346 throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e);
aoqi@0 347 }
aoqi@0 348 }
aoqi@0 349
aoqi@0 350 /**
aoqi@0 351 * Visits a {@code CONSTRUCTOR} executable element by calling
aoqi@0 352 * {@code defaultAction}.
aoqi@0 353 *
aoqi@0 354 * @param e the element to visit
aoqi@0 355 * @param p a visitor-specified parameter
aoqi@0 356 * @return the result of {@code defaultAction}
aoqi@0 357 */
aoqi@0 358 public R visitExecutableAsConstructor(ExecutableElement e, P p) {
aoqi@0 359 return defaultAction(e, p);
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 /**
aoqi@0 363 * Visits an {@code INSTANCE_INIT} executable element by calling
aoqi@0 364 * {@code defaultAction}.
aoqi@0 365 *
aoqi@0 366 * @param e the element to visit
aoqi@0 367 * @param p a visitor-specified parameter
aoqi@0 368 * @return the result of {@code defaultAction}
aoqi@0 369 */
aoqi@0 370 public R visitExecutableAsInstanceInit(ExecutableElement e, P p) {
aoqi@0 371 return defaultAction(e, p);
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 /**
aoqi@0 375 * Visits a {@code METHOD} executable element by calling
aoqi@0 376 * {@code defaultAction}.
aoqi@0 377 *
aoqi@0 378 * @param e the element to visit
aoqi@0 379 * @param p a visitor-specified parameter
aoqi@0 380 * @return the result of {@code defaultAction}
aoqi@0 381 */
aoqi@0 382 public R visitExecutableAsMethod(ExecutableElement e, P p) {
aoqi@0 383 return defaultAction(e, p);
aoqi@0 384 }
aoqi@0 385
aoqi@0 386 /**
aoqi@0 387 * Visits a {@code STATIC_INIT} executable element by calling
aoqi@0 388 * {@code defaultAction}.
aoqi@0 389 *
aoqi@0 390 * @param e the element to visit
aoqi@0 391 * @param p a visitor-specified parameter
aoqi@0 392 * @return the result of {@code defaultAction}
aoqi@0 393 */
aoqi@0 394 public R visitExecutableAsStaticInit(ExecutableElement e, P p) {
aoqi@0 395 return defaultAction(e, p);
aoqi@0 396 }
aoqi@0 397
aoqi@0 398
aoqi@0 399 /**
aoqi@0 400 * {@inheritDoc}
aoqi@0 401 *
aoqi@0 402 * The element argument has kind {@code TYPE_PARAMETER}.
aoqi@0 403 *
aoqi@0 404 * @param e {@inheritDoc}
aoqi@0 405 * @param p {@inheritDoc}
aoqi@0 406 * @return {@inheritDoc}
aoqi@0 407 */
aoqi@0 408 @Override
aoqi@0 409 public R visitTypeParameter(TypeParameterElement e, P p) {
aoqi@0 410 assert e.getKind() == TYPE_PARAMETER: "Bad kind on TypeParameterElement";
aoqi@0 411 return defaultAction(e, p);
aoqi@0 412 }
aoqi@0 413 }

mercurial