574N/A/*
850N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
574N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
574N/A *
574N/A * This code is free software; you can redistribute it and/or modify it
574N/A * under the terms of the GNU General Public License version 2 only, as
574N/A * published by the Free Software Foundation. Oracle designates this
574N/A * particular file as subject to the "Classpath" exception as provided
574N/A * by Oracle in the LICENSE file that accompanied this code.
574N/A *
574N/A * This code is distributed in the hope that it will be useful, but WITHOUT
574N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
574N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
574N/A * version 2 for more details (a copy is included in the LICENSE file that
574N/A * accompanied this code).
574N/A *
574N/A * You should have received a copy of the GNU General Public License version
574N/A * 2 along with this work; if not, write to the Free Software Foundation,
574N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
574N/A *
574N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
574N/A * or visit www.oracle.com if you need additional information or have any
574N/A * questions.
574N/A */
574N/A
574N/Apackage javax.lang.model.util;
574N/A
574N/Aimport javax.lang.model.element.*;
574N/Aimport javax.annotation.processing.SupportedSourceVersion;
574N/Aimport static javax.lang.model.element.ElementKind.*;
574N/Aimport javax.lang.model.SourceVersion;
574N/Aimport static javax.lang.model.SourceVersion.*;
574N/A
574N/A
574N/A/**
574N/A * A scanning visitor of program elements with default behavior
574N/A * appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}
574N/A * source version. The <tt>visit<i>XYZ</i></tt> methods in this
574N/A * class scan their component elements by calling {@code scan} on
574N/A * their {@linkplain Element#getEnclosedElements enclosed elements},
574N/A * {@linkplain ExecutableElement#getParameters parameters}, etc., as
574N/A * indicated in the individual method specifications. A subclass can
574N/A * control the order elements are visited by overriding the
574N/A * <tt>visit<i>XYZ</i></tt> methods. Note that clients of a scanner
574N/A * may get the desired behavior be invoking {@code v.scan(e, p)} rather
574N/A * than {@code v.visit(e, p)} on the root objects of interest.
574N/A *
574N/A * <p>When a subclass overrides a <tt>visit<i>XYZ</i></tt> method, the
574N/A * new method can cause the enclosed elements to be scanned in the
574N/A * default way by calling <tt>super.visit<i>XYZ</i></tt>. In this
574N/A * fashion, the concrete visitor can control the ordering of traversal
574N/A * over the component elements with respect to the additional
574N/A * processing; for example, consistently calling
574N/A * <tt>super.visit<i>XYZ</i></tt> at the start of the overridden
574N/A * methods will yield a preorder traversal, etc. If the component
574N/A * elements should be traversed in some other order, instead of
574N/A * calling <tt>super.visit<i>XYZ</i></tt>, an overriding visit method
574N/A * should call {@code scan} with the elements in the desired order.
574N/A *
574N/A * <p> Methods in this class may be overridden subject to their
574N/A * general contract. Note that annotating methods in concrete
574N/A * subclasses with {@link java.lang.Override @Override} will help
574N/A * ensure that methods are overridden as intended.
574N/A *
574N/A * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
574N/A * implemented by this class may have methods added to it in the
574N/A * future to accommodate new, currently unknown, language structures
574N/A * added to future versions of the Java&trade; programming language.
574N/A * Therefore, methods whose names begin with {@code "visit"} may be
574N/A * added to this class in the future; to avoid incompatibilities,
574N/A * classes which extend this class should not declare any instance
574N/A * methods with names beginning with {@code "visit"}.
574N/A *
574N/A * <p>When such a new visit method is added, the default
574N/A * implementation in this class will be to call the {@link
574N/A * #visitUnknown visitUnknown} method. A new element scanner visitor
574N/A * class will also be introduced to correspond to the new language
574N/A * level; this visitor will have different default behavior for the
574N/A * visit method in question. When the new visitor is introduced, all
574N/A * or portions of this visitor may be deprecated.
574N/A *
574N/A * @param <R> the return type of this visitor's methods. Use {@link
574N/A * Void} for visitors that do not need to return results.
574N/A * @param <P> the type of the additional parameter to this visitor's
574N/A * methods. Use {@code Void} for visitors that do not need an
574N/A * additional parameter.
574N/A *
574N/A * @see ElementScanner6
574N/A * @since 1.7
574N/A */
574N/A@SupportedSourceVersion(RELEASE_7)
574N/Apublic class ElementScanner7<R, P> extends ElementScanner6<R, P> {
574N/A /**
574N/A * Constructor for concrete subclasses; uses {@code null} for the
574N/A * default value.
574N/A */
574N/A protected ElementScanner7(){
574N/A super(null);
574N/A }
574N/A
574N/A /**
574N/A * Constructor for concrete subclasses; uses the argument for the
574N/A * default value.
574N/A */
574N/A protected ElementScanner7(R defaultValue){
574N/A super(defaultValue);
574N/A }
850N/A
850N/A /**
850N/A * This implementation scans the enclosed elements.
850N/A *
850N/A * @param e {@inheritDoc}
850N/A * @param p {@inheritDoc}
850N/A * @return the result of scanning
850N/A */
850N/A @Override
850N/A public R visitVariable(VariableElement e, P p) {
850N/A return scan(e.getEnclosedElements(), p);
850N/A }
574N/A}