Path: blob/master/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner9.java
41161 views
/*1* Copyright (c) 2011, 2020, 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 source versions {@link SourceVersion#RELEASE_936* RELEASE_9} through {@link SourceVersion#RELEASE_14 RELEASE_14}.37*38* The <code>visit<i>Xyz</i></code> methods in this39* class scan their component elements by calling {@code scan} on40* their {@linkplain Element#getEnclosedElements enclosed elements},41* {@linkplain ExecutableElement#getParameters parameters}, etc., as42* indicated in the individual method specifications. A subclass can43* control the order elements are visited by overriding the44* <code>visit<i>Xyz</i></code> methods. Note that clients of a scanner45* may get the desired behavior be invoking {@code v.scan(e, p)} rather46* than {@code v.visit(e, p)} on the root objects of interest.47*48* <p>When a subclass overrides a <code>visit<i>Xyz</i></code> method, the49* new method can cause the enclosed elements to be scanned in the50* default way by calling <code>super.visit<i>Xyz</i></code>. In this51* fashion, the concrete visitor can control the ordering of traversal52* over the component elements with respect to the additional53* processing; for example, consistently calling54* <code>super.visit<i>Xyz</i></code> at the start of the overridden55* methods will yield a preorder traversal, etc. If the component56* elements should be traversed in some other order, instead of57* calling <code>super.visit<i>Xyz</i></code>, an overriding visit method58* should call {@code scan} with the elements in the desired order.59*60* @apiNote61* Methods in this class may be overridden subject to their general62* contract.63*64* @param <R> the return type of this visitor's methods. Use {@link65* Void} for visitors that do not need to return results.66* @param <P> the type of the additional parameter to this visitor's67* methods. Use {@code Void} for visitors that do not need an68* additional parameter.69*70* @see <a href="ElementScanner6.html#note_for_subclasses"><strong>Compatibility note for subclasses</strong></a>71* @see ElementScanner672* @see ElementScanner773* @see ElementScanner874* @see ElementScanner1475* @since 976*/77@SupportedSourceVersion(RELEASE_14)78public class ElementScanner9<R, P> extends ElementScanner8<R, P> {79/**80* Constructor for concrete subclasses; uses {@code null} for the81* default value.82*/83protected ElementScanner9(){84super(null);85}8687/**88* Constructor for concrete subclasses; uses the argument for the89* default value.90*91* @param defaultValue the default value92*/93protected ElementScanner9(R defaultValue){94super(defaultValue);95}9697/**98* {@inheritDoc}99*100* @implSpec This implementation scans the enclosed elements.101*102* @param e the element to visit103* @param p a visitor-specified parameter104* @return the result of the scan105*/106@Override107public R visitModule(ModuleElement e, P p) {108return scan(e.getEnclosedElements(), p); // TODO: Hmmm, this might not be right109}110}111112113