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

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/javax/lang/model/util/ElementKindVisitor6.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,413 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.lang.model.util;
    1.30 +
    1.31 +import javax.lang.model.element.*;
    1.32 +import static javax.lang.model.element.ElementKind.*;
    1.33 +import javax.annotation.processing.SupportedSourceVersion;
    1.34 +import static javax.lang.model.SourceVersion.*;
    1.35 +import javax.lang.model.SourceVersion;
    1.36 +
    1.37 +
    1.38 +/**
    1.39 + * A visitor of program elements based on their {@linkplain
    1.40 + * ElementKind kind} with default behavior appropriate for the {@link
    1.41 + * SourceVersion#RELEASE_6 RELEASE_6} source version.  For {@linkplain
    1.42 + * Element elements} <tt><i>XYZ</i></tt> that may have more than one
    1.43 + * kind, the <tt>visit<i>XYZ</i></tt> methods in this class delegate
    1.44 + * to the <tt>visit<i>XYZKind</i></tt> method corresponding to the
    1.45 + * first argument's kind.  The <tt>visit<i>XYZKind</i></tt> methods
    1.46 + * call {@link #defaultAction defaultAction}, passing their arguments
    1.47 + * to {@code defaultAction}'s corresponding parameters.
    1.48 + *
    1.49 + * <p> Methods in this class may be overridden subject to their
    1.50 + * general contract.  Note that annotating methods in concrete
    1.51 + * subclasses with {@link java.lang.Override @Override} will help
    1.52 + * ensure that methods are overridden as intended.
    1.53 + *
    1.54 + * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
    1.55 + * implemented by this class may have methods added to it or the
    1.56 + * {@code ElementKind} {@code enum} used in this case may have
    1.57 + * constants added to it in the future to accommodate new, currently
    1.58 + * unknown, language structures added to future versions of the
    1.59 + * Java&trade; programming language.  Therefore, methods whose names
    1.60 + * begin with {@code "visit"} may be added to this class in the
    1.61 + * future; to avoid incompatibilities, classes which extend this class
    1.62 + * should not declare any instance methods with names beginning with
    1.63 + * {@code "visit"}.
    1.64 + *
    1.65 + * <p>When such a new visit method is added, the default
    1.66 + * implementation in this class will be to call the {@link
    1.67 + * #visitUnknown visitUnknown} method.  A new abstract element kind
    1.68 + * visitor class will also be introduced to correspond to the new
    1.69 + * language level; this visitor will have different default behavior
    1.70 + * for the visit method in question.  When the new visitor is
    1.71 + * introduced, all or portions of this visitor may be deprecated.
    1.72 + *
    1.73 + * <p>Note that adding a default implementation of a new visit method
    1.74 + * in a visitor class will occur instead of adding a <em>default
    1.75 + * method</em> directly in the visitor interface since a Java SE 8
    1.76 + * language feature cannot be used to this version of the API since
    1.77 + * this version is required to be runnable on Java SE 7
    1.78 + * implementations.  Future versions of the API that are only required
    1.79 + * to run on Java SE 8 and later may take advantage of default methods
    1.80 + * in this situation.
    1.81 + *
    1.82 + * @param <R> the return type of this visitor's methods.  Use {@link
    1.83 + *            Void} for visitors that do not need to return results.
    1.84 + * @param <P> the type of the additional parameter to this visitor's
    1.85 + *            methods.  Use {@code Void} for visitors that do not need an
    1.86 + *            additional parameter.
    1.87 + *
    1.88 + * @author Joseph D. Darcy
    1.89 + * @author Scott Seligman
    1.90 + * @author Peter von der Ah&eacute;
    1.91 + *
    1.92 + * @see ElementKindVisitor7
    1.93 + * @see ElementKindVisitor8
    1.94 + * @since 1.6
    1.95 + */
    1.96 +@SupportedSourceVersion(RELEASE_6)
    1.97 +public class ElementKindVisitor6<R, P>
    1.98 +                  extends SimpleElementVisitor6<R, P> {
    1.99 +    /**
   1.100 +     * Constructor for concrete subclasses; uses {@code null} for the
   1.101 +     * default value.
   1.102 +     */
   1.103 +    protected ElementKindVisitor6() {
   1.104 +        super(null);
   1.105 +    }
   1.106 +
   1.107 +    /**
   1.108 +     * Constructor for concrete subclasses; uses the argument for the
   1.109 +     * default value.
   1.110 +     *
   1.111 +     * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
   1.112 +     */
   1.113 +    protected ElementKindVisitor6(R defaultValue) {
   1.114 +        super(defaultValue);
   1.115 +    }
   1.116 +
   1.117 +    /**
   1.118 +     * {@inheritDoc}
   1.119 +     *
   1.120 +     * The element argument has kind {@code PACKAGE}.
   1.121 +     *
   1.122 +     * @param e {@inheritDoc}
   1.123 +     * @param p {@inheritDoc}
   1.124 +     * @return  {@inheritDoc}
   1.125 +     */
   1.126 +    @Override
   1.127 +    public R visitPackage(PackageElement e, P p) {
   1.128 +        assert e.getKind() == PACKAGE: "Bad kind on PackageElement";
   1.129 +        return defaultAction(e, p);
   1.130 +    }
   1.131 +
   1.132 +    /**
   1.133 +     * Visits a type element, dispatching to the visit method for the
   1.134 +     * specific {@linkplain ElementKind kind} of type, {@code
   1.135 +     * ANNOTATION_TYPE}, {@code CLASS}, {@code ENUM}, or {@code
   1.136 +     * INTERFACE}.
   1.137 +     *
   1.138 +     * @param e {@inheritDoc}
   1.139 +     * @param p {@inheritDoc}
   1.140 +     * @return  the result of the kind-specific visit method
   1.141 +     */
   1.142 +    @Override
   1.143 +    public R visitType(TypeElement e, P p) {
   1.144 +        ElementKind k = e.getKind();
   1.145 +        switch(k) {
   1.146 +        case ANNOTATION_TYPE:
   1.147 +            return visitTypeAsAnnotationType(e, p);
   1.148 +
   1.149 +        case CLASS:
   1.150 +            return visitTypeAsClass(e, p);
   1.151 +
   1.152 +        case ENUM:
   1.153 +            return visitTypeAsEnum(e, p);
   1.154 +
   1.155 +        case INTERFACE:
   1.156 +            return visitTypeAsInterface(e, p);
   1.157 +
   1.158 +        default:
   1.159 +            throw new AssertionError("Bad kind " + k + " for TypeElement" + e);
   1.160 +        }
   1.161 +    }
   1.162 +
   1.163 +    /**
   1.164 +     * Visits an {@code ANNOTATION_TYPE} type element by calling
   1.165 +     * {@code defaultAction}.
   1.166 +     *
   1.167 +     * @param e the element to visit
   1.168 +     * @param p a visitor-specified parameter
   1.169 +     * @return  the result of {@code defaultAction}
   1.170 +     */
   1.171 +    public R visitTypeAsAnnotationType(TypeElement e, P p) {
   1.172 +        return defaultAction(e, p);
   1.173 +    }
   1.174 +
   1.175 +    /**
   1.176 +     * Visits a {@code CLASS} type element by calling {@code
   1.177 +     * defaultAction}.
   1.178 +     *
   1.179 +     * @param e the element to visit
   1.180 +     * @param p a visitor-specified parameter
   1.181 +     * @return  the result of {@code defaultAction}
   1.182 +     */
   1.183 +    public R visitTypeAsClass(TypeElement e, P p) {
   1.184 +        return defaultAction(e, p);
   1.185 +    }
   1.186 +
   1.187 +    /**
   1.188 +     * Visits an {@code ENUM} type element by calling {@code
   1.189 +     * defaultAction}.
   1.190 +     *
   1.191 +     * @param e the element to visit
   1.192 +     * @param p a visitor-specified parameter
   1.193 +     * @return  the result of {@code defaultAction}
   1.194 +     */
   1.195 +    public R visitTypeAsEnum(TypeElement e, P p) {
   1.196 +        return defaultAction(e, p);
   1.197 +    }
   1.198 +
   1.199 +    /**
   1.200 +     * Visits an {@code INTERFACE} type element by calling {@code
   1.201 +     * defaultAction}.
   1.202 +     *.
   1.203 +     * @param e the element to visit
   1.204 +     * @param p a visitor-specified parameter
   1.205 +     * @return  the result of {@code defaultAction}
   1.206 +     */
   1.207 +    public R visitTypeAsInterface(TypeElement e, P p) {
   1.208 +        return defaultAction(e, p);
   1.209 +    }
   1.210 +
   1.211 +    /**
   1.212 +     * Visits a variable element, dispatching to the visit method for
   1.213 +     * the specific {@linkplain ElementKind kind} of variable, {@code
   1.214 +     * ENUM_CONSTANT}, {@code EXCEPTION_PARAMETER}, {@code FIELD},
   1.215 +     * {@code LOCAL_VARIABLE}, {@code PARAMETER}, or {@code RESOURCE_VARIABLE}.
   1.216 +     *
   1.217 +     * @param e {@inheritDoc}
   1.218 +     * @param p {@inheritDoc}
   1.219 +     * @return  the result of the kind-specific visit method
   1.220 +     */
   1.221 +    @Override
   1.222 +    public R visitVariable(VariableElement e, P p) {
   1.223 +        ElementKind k = e.getKind();
   1.224 +        switch(k) {
   1.225 +        case ENUM_CONSTANT:
   1.226 +            return visitVariableAsEnumConstant(e, p);
   1.227 +
   1.228 +        case EXCEPTION_PARAMETER:
   1.229 +            return visitVariableAsExceptionParameter(e, p);
   1.230 +
   1.231 +        case FIELD:
   1.232 +            return visitVariableAsField(e, p);
   1.233 +
   1.234 +        case LOCAL_VARIABLE:
   1.235 +            return visitVariableAsLocalVariable(e, p);
   1.236 +
   1.237 +        case PARAMETER:
   1.238 +            return visitVariableAsParameter(e, p);
   1.239 +
   1.240 +        case RESOURCE_VARIABLE:
   1.241 +            return visitVariableAsResourceVariable(e, p);
   1.242 +
   1.243 +        default:
   1.244 +            throw new AssertionError("Bad kind " + k + " for VariableElement" + e);
   1.245 +        }
   1.246 +    }
   1.247 +
   1.248 +    /**
   1.249 +     * Visits an {@code ENUM_CONSTANT} variable element by calling
   1.250 +     * {@code defaultAction}.
   1.251 +     *
   1.252 +     * @param e the element to visit
   1.253 +     * @param p a visitor-specified parameter
   1.254 +     * @return  the result of {@code defaultAction}
   1.255 +     */
   1.256 +    public R visitVariableAsEnumConstant(VariableElement e, P p) {
   1.257 +        return defaultAction(e, p);
   1.258 +    }
   1.259 +
   1.260 +    /**
   1.261 +     * Visits an {@code EXCEPTION_PARAMETER} variable element by calling
   1.262 +     * {@code defaultAction}.
   1.263 +     *
   1.264 +     * @param e the element to visit
   1.265 +     * @param p a visitor-specified parameter
   1.266 +     * @return  the result of {@code defaultAction}
   1.267 +     */
   1.268 +    public R visitVariableAsExceptionParameter(VariableElement e, P p) {
   1.269 +        return defaultAction(e, p);
   1.270 +    }
   1.271 +
   1.272 +    /**
   1.273 +     * Visits a {@code FIELD} variable element by calling
   1.274 +     * {@code defaultAction}.
   1.275 +     *
   1.276 +     * @param e the element to visit
   1.277 +     * @param p a visitor-specified parameter
   1.278 +     * @return  the result of {@code defaultAction}
   1.279 +     */
   1.280 +    public R visitVariableAsField(VariableElement e, P p) {
   1.281 +        return defaultAction(e, p);
   1.282 +    }
   1.283 +
   1.284 +    /**
   1.285 +     * Visits a {@code LOCAL_VARIABLE} variable element by calling
   1.286 +     * {@code defaultAction}.
   1.287 +     *
   1.288 +     * @param e the element to visit
   1.289 +     * @param p a visitor-specified parameter
   1.290 +     * @return  the result of {@code defaultAction}
   1.291 +     */
   1.292 +    public R visitVariableAsLocalVariable(VariableElement e, P p) {
   1.293 +        return defaultAction(e, p);
   1.294 +    }
   1.295 +
   1.296 +    /**
   1.297 +     * Visits a {@code PARAMETER} variable element by calling
   1.298 +     * {@code defaultAction}.
   1.299 +     *
   1.300 +     * @param e the element to visit
   1.301 +     * @param p a visitor-specified parameter
   1.302 +     * @return  the result of {@code defaultAction}
   1.303 +     */
   1.304 +    public R visitVariableAsParameter(VariableElement e, P p) {
   1.305 +        return defaultAction(e, p);
   1.306 +    }
   1.307 +
   1.308 +    /**
   1.309 +     * Visits a {@code RESOURCE_VARIABLE} variable element by calling
   1.310 +     * {@code visitUnknown}.
   1.311 +     *
   1.312 +     * @param e the element to visit
   1.313 +     * @param p a visitor-specified parameter
   1.314 +     * @return  the result of {@code visitUnknown}
   1.315 +     *
   1.316 +     * @since 1.7
   1.317 +     */
   1.318 +    public R visitVariableAsResourceVariable(VariableElement e, P p) {
   1.319 +        return visitUnknown(e, p);
   1.320 +    }
   1.321 +
   1.322 +    /**
   1.323 +     * Visits an executable element, dispatching to the visit method
   1.324 +     * for the specific {@linkplain ElementKind kind} of executable,
   1.325 +     * {@code CONSTRUCTOR}, {@code INSTANCE_INIT}, {@code METHOD}, or
   1.326 +     * {@code STATIC_INIT}.
   1.327 +     *
   1.328 +     * @param e {@inheritDoc}
   1.329 +     * @param p {@inheritDoc}
   1.330 +     * @return  the result of the kind-specific visit method
   1.331 +     */
   1.332 +    @Override
   1.333 +    public R visitExecutable(ExecutableElement e, P p) {
   1.334 +        ElementKind k = e.getKind();
   1.335 +        switch(k) {
   1.336 +        case CONSTRUCTOR:
   1.337 +            return visitExecutableAsConstructor(e, p);
   1.338 +
   1.339 +        case INSTANCE_INIT:
   1.340 +            return visitExecutableAsInstanceInit(e, p);
   1.341 +
   1.342 +        case METHOD:
   1.343 +            return visitExecutableAsMethod(e, p);
   1.344 +
   1.345 +        case STATIC_INIT:
   1.346 +            return visitExecutableAsStaticInit(e, p);
   1.347 +
   1.348 +        default:
   1.349 +            throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e);
   1.350 +        }
   1.351 +    }
   1.352 +
   1.353 +    /**
   1.354 +     * Visits a {@code CONSTRUCTOR} executable element by calling
   1.355 +     * {@code defaultAction}.
   1.356 +     *
   1.357 +     * @param e the element to visit
   1.358 +     * @param p a visitor-specified parameter
   1.359 +     * @return  the result of {@code defaultAction}
   1.360 +     */
   1.361 +    public R visitExecutableAsConstructor(ExecutableElement e, P p) {
   1.362 +        return defaultAction(e, p);
   1.363 +    }
   1.364 +
   1.365 +    /**
   1.366 +     * Visits an {@code INSTANCE_INIT} executable element by calling
   1.367 +     * {@code defaultAction}.
   1.368 +     *
   1.369 +     * @param e the element to visit
   1.370 +     * @param p a visitor-specified parameter
   1.371 +     * @return  the result of {@code defaultAction}
   1.372 +     */
   1.373 +    public R visitExecutableAsInstanceInit(ExecutableElement e, P p) {
   1.374 +        return defaultAction(e, p);
   1.375 +    }
   1.376 +
   1.377 +    /**
   1.378 +     * Visits a {@code METHOD} executable element by calling
   1.379 +     * {@code defaultAction}.
   1.380 +     *
   1.381 +     * @param e the element to visit
   1.382 +     * @param p a visitor-specified parameter
   1.383 +     * @return  the result of {@code defaultAction}
   1.384 +     */
   1.385 +    public R visitExecutableAsMethod(ExecutableElement e, P p) {
   1.386 +        return defaultAction(e, p);
   1.387 +    }
   1.388 +
   1.389 +    /**
   1.390 +     * Visits a {@code STATIC_INIT} executable element by calling
   1.391 +     * {@code defaultAction}.
   1.392 +     *
   1.393 +     * @param e the element to visit
   1.394 +     * @param p a visitor-specified parameter
   1.395 +     * @return  the result of {@code defaultAction}
   1.396 +     */
   1.397 +    public R visitExecutableAsStaticInit(ExecutableElement e, P p) {
   1.398 +        return defaultAction(e, p);
   1.399 +    }
   1.400 +
   1.401 +
   1.402 +    /**
   1.403 +     * {@inheritDoc}
   1.404 +     *
   1.405 +     * The element argument has kind {@code TYPE_PARAMETER}.
   1.406 +     *
   1.407 +     * @param e {@inheritDoc}
   1.408 +     * @param p {@inheritDoc}
   1.409 +     * @return  {@inheritDoc}
   1.410 +     */
   1.411 +    @Override
   1.412 +    public R visitTypeParameter(TypeParameterElement e, P p) {
   1.413 +        assert e.getKind() == TYPE_PARAMETER: "Bad kind on TypeParameterElement";
   1.414 +        return defaultAction(e, p);
   1.415 +    }
   1.416 +}

mercurial