Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/javax/lang/model/util/ElementScanner7.java
38899 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.lang.model.util;2627import javax.lang.model.element.*;28import javax.annotation.processing.SupportedSourceVersion;29import javax.lang.model.SourceVersion;30import static javax.lang.model.SourceVersion.*;313233/**34* A scanning visitor of program elements with default behavior35* appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}36* source version. The <tt>visit<i>XYZ</i></tt> methods in this37* class scan their component elements by calling {@code scan} on38* their {@linkplain Element#getEnclosedElements enclosed elements},39* {@linkplain ExecutableElement#getParameters parameters}, etc., as40* indicated in the individual method specifications. A subclass can41* control the order elements are visited by overriding the42* <tt>visit<i>XYZ</i></tt> methods. Note that clients of a scanner43* may get the desired behavior be invoking {@code v.scan(e, p)} rather44* than {@code v.visit(e, p)} on the root objects of interest.45*46* <p>When a subclass overrides a <tt>visit<i>XYZ</i></tt> method, the47* new method can cause the enclosed elements to be scanned in the48* default way by calling <tt>super.visit<i>XYZ</i></tt>. In this49* fashion, the concrete visitor can control the ordering of traversal50* over the component elements with respect to the additional51* processing; for example, consistently calling52* <tt>super.visit<i>XYZ</i></tt> at the start of the overridden53* methods will yield a preorder traversal, etc. If the component54* elements should be traversed in some other order, instead of55* calling <tt>super.visit<i>XYZ</i></tt>, an overriding visit method56* should call {@code scan} with the elements in the desired order.57*58* <p> Methods in this class may be overridden subject to their59* general contract. Note that annotating methods in concrete60* subclasses with {@link java.lang.Override @Override} will help61* ensure that methods are overridden as intended.62*63* <p> <b>WARNING:</b> The {@code ElementVisitor} interface64* implemented by this class may have methods added to it in the65* future to accommodate new, currently unknown, language structures66* added to future versions of the Java™ programming language.67* Therefore, methods whose names begin with {@code "visit"} may be68* added to this class in the future; to avoid incompatibilities,69* classes which extend this class should not declare any instance70* methods with names beginning with {@code "visit"}.71*72* <p>When such a new visit method is added, the default73* implementation in this class will be to call the {@link74* #visitUnknown visitUnknown} method. A new element scanner visitor75* class will also be introduced to correspond to the new language76* level; this visitor will have different default behavior for the77* visit method in question. When the new visitor is introduced, all78* or portions of this visitor may be deprecated.79*80* @param <R> the return type of this visitor's methods. Use {@link81* Void} for visitors that do not need to return results.82* @param <P> the type of the additional parameter to this visitor's83* methods. Use {@code Void} for visitors that do not need an84* additional parameter.85*86* @see ElementScanner687* @see ElementScanner888* @since 1.789*/90@SupportedSourceVersion(RELEASE_7)91public class ElementScanner7<R, P> extends ElementScanner6<R, P> {92/**93* Constructor for concrete subclasses; uses {@code null} for the94* default value.95*/96protected ElementScanner7(){97super(null);98}99100/**101* Constructor for concrete subclasses; uses the argument for the102* default value.103*104* @param defaultValue the default value105*/106protected ElementScanner7(R defaultValue){107super(defaultValue);108}109110/**111* This implementation scans the enclosed elements.112*113* @param e {@inheritDoc}114* @param p {@inheritDoc}115* @return the result of scanning116*/117@Override118public R visitVariable(VariableElement e, P p) {119return scan(e.getEnclosedElements(), p);120}121}122123124