src/share/classes/javax/lang/model/element/ElementVisitor.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1522
09f65aad4759
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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.element;
aoqi@0 27
aoqi@0 28 import javax.lang.model.util.*;
aoqi@0 29
aoqi@0 30 /**
aoqi@0 31 * A visitor of program elements, in the style of the visitor design
aoqi@0 32 * pattern. Classes implementing this interface are used to operate
aoqi@0 33 * on an element when the kind of element is unknown at compile time.
aoqi@0 34 * When a visitor is passed to an element's {@link Element#accept
aoqi@0 35 * accept} method, the <tt>visit<i>XYZ</i></tt> method most applicable
aoqi@0 36 * to that element is invoked.
aoqi@0 37 *
aoqi@0 38 * <p> Classes implementing this interface may or may not throw a
aoqi@0 39 * {@code NullPointerException} if the additional parameter {@code p}
aoqi@0 40 * is {@code null}; see documentation of the implementing class for
aoqi@0 41 * details.
aoqi@0 42 *
aoqi@0 43 * <p> <b>WARNING:</b> It is possible that methods will be added to
aoqi@0 44 * this interface to accommodate new, currently unknown, language
aoqi@0 45 * structures added to future versions of the Java&trade; programming
aoqi@0 46 * language. Therefore, visitor classes directly implementing this
aoqi@0 47 * interface may be source incompatible with future versions of the
aoqi@0 48 * platform. To avoid this source incompatibility, visitor
aoqi@0 49 * implementations are encouraged to instead extend the appropriate
aoqi@0 50 * abstract visitor class that implements this interface. However, an
aoqi@0 51 * API should generally use this visitor interface as the type for
aoqi@0 52 * parameters, return type, etc. rather than one of the abstract
aoqi@0 53 * classes.
aoqi@0 54 *
aoqi@0 55 * <p>Note that methods to accommodate new language constructs could
aoqi@0 56 * be added in a source <em>compatible</em> way if they were added as
aoqi@0 57 * <em>default methods</em>. However, default methods are only
aoqi@0 58 * available on Java SE 8 and higher releases and the {@code
aoqi@0 59 * javax.lang.model.*} packages bundled in Java SE 8 are required to
aoqi@0 60 * also be runnable on Java SE 7. Therefore, default methods
aoqi@0 61 * <em>cannot</em> be used when extending {@code javax.lang.model.*}
aoqi@0 62 * to cover Java SE 8 language features. However, default methods may
aoqi@0 63 * be used in subsequent revisions of the {@code javax.lang.model.*}
aoqi@0 64 * packages that are only required to run on Java SE 8 and higher
aoqi@0 65 * platform versions.
aoqi@0 66 *
aoqi@0 67 * @param <R> the return type of this visitor's methods. Use {@link
aoqi@0 68 * Void} for visitors that do not need to return results.
aoqi@0 69 * @param <P> the type of the additional parameter to this visitor's
aoqi@0 70 * methods. Use {@code Void} for visitors that do not need an
aoqi@0 71 * additional parameter.
aoqi@0 72 *
aoqi@0 73 * @author Joseph D. Darcy
aoqi@0 74 * @author Scott Seligman
aoqi@0 75 * @author Peter von der Ah&eacute;
aoqi@0 76 * @see AbstractElementVisitor6
aoqi@0 77 * @see AbstractElementVisitor7
aoqi@0 78 * @since 1.6
aoqi@0 79 */
aoqi@0 80 public interface ElementVisitor<R, P> {
aoqi@0 81 /**
aoqi@0 82 * Visits an element.
aoqi@0 83 * @param e the element to visit
aoqi@0 84 * @param p a visitor-specified parameter
aoqi@0 85 * @return a visitor-specified result
aoqi@0 86 */
aoqi@0 87 R visit(Element e, P p);
aoqi@0 88
aoqi@0 89 /**
aoqi@0 90 * A convenience method equivalent to {@code v.visit(e, null)}.
aoqi@0 91 * @param e the element to visit
aoqi@0 92 * @return a visitor-specified result
aoqi@0 93 */
aoqi@0 94 R visit(Element e);
aoqi@0 95
aoqi@0 96 /**
aoqi@0 97 * Visits a package element.
aoqi@0 98 * @param e the element to visit
aoqi@0 99 * @param p a visitor-specified parameter
aoqi@0 100 * @return a visitor-specified result
aoqi@0 101 */
aoqi@0 102 R visitPackage(PackageElement e, P p);
aoqi@0 103
aoqi@0 104 /**
aoqi@0 105 * Visits a type element.
aoqi@0 106 * @param e the element to visit
aoqi@0 107 * @param p a visitor-specified parameter
aoqi@0 108 * @return a visitor-specified result
aoqi@0 109 */
aoqi@0 110 R visitType(TypeElement e, P p);
aoqi@0 111
aoqi@0 112 /**
aoqi@0 113 * Visits a variable element.
aoqi@0 114 * @param e the element to visit
aoqi@0 115 * @param p a visitor-specified parameter
aoqi@0 116 * @return a visitor-specified result
aoqi@0 117 */
aoqi@0 118 R visitVariable(VariableElement e, P p);
aoqi@0 119
aoqi@0 120 /**
aoqi@0 121 * Visits an executable element.
aoqi@0 122 * @param e the element to visit
aoqi@0 123 * @param p a visitor-specified parameter
aoqi@0 124 * @return a visitor-specified result
aoqi@0 125 */
aoqi@0 126 R visitExecutable(ExecutableElement e, P p);
aoqi@0 127
aoqi@0 128 /**
aoqi@0 129 * Visits a type parameter element.
aoqi@0 130 * @param e the element to visit
aoqi@0 131 * @param p a visitor-specified parameter
aoqi@0 132 * @return a visitor-specified result
aoqi@0 133 */
aoqi@0 134 R visitTypeParameter(TypeParameterElement e, P p);
aoqi@0 135
aoqi@0 136 /**
aoqi@0 137 * Visits an unknown kind of element.
aoqi@0 138 * This can occur if the language evolves and new kinds
aoqi@0 139 * of elements are added to the {@code Element} hierarchy.
aoqi@0 140 *
aoqi@0 141 * @param e the element to visit
aoqi@0 142 * @param p a visitor-specified parameter
aoqi@0 143 * @return a visitor-specified result
aoqi@0 144 * @throws UnknownElementException
aoqi@0 145 * a visitor implementation may optionally throw this exception
aoqi@0 146 */
aoqi@0 147 R visitUnknown(Element e, P p);
aoqi@0 148 }

mercurial