1 /*
   2  * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.lang.model.util;
  27 
  28 import javax.lang.model.element.*;
  29 import javax.annotation.processing.SupportedSourceVersion;
  30 import javax.lang.model.SourceVersion;
  31 import static javax.lang.model.SourceVersion.*;
  32 
  33 
  34 /**
  35  * A scanning visitor of program elements with default behavior
  36  * appropriate for source versions {@link SourceVersion#RELEASE_9
  37  * RELEASE_9} through {@link SourceVersion#RELEASE_14 RELEASE_14}.
  38  *
  39  * The <code>visit<i>Xyz</i></code> methods in this
  40  * class scan their component elements by calling {@code scan} on
  41  * their {@linkplain Element#getEnclosedElements enclosed elements},
  42  * {@linkplain ExecutableElement#getParameters parameters}, etc., as
  43  * indicated in the individual method specifications.  A subclass can
  44  * control the order elements are visited by overriding the
  45  * <code>visit<i>Xyz</i></code> methods.  Note that clients of a scanner
  46  * may get the desired behavior be invoking {@code v.scan(e, p)} rather
  47  * than {@code v.visit(e, p)} on the root objects of interest.
  48  *
  49  * <p>When a subclass overrides a <code>visit<i>Xyz</i></code> method, the
  50  * new method can cause the enclosed elements to be scanned in the
  51  * default way by calling <code>super.visit<i>Xyz</i></code>.  In this
  52  * fashion, the concrete visitor can control the ordering of traversal
  53  * over the component elements with respect to the additional
  54  * processing; for example, consistently calling
  55  * <code>super.visit<i>Xyz</i></code> at the start of the overridden
  56  * methods will yield a preorder traversal, etc.  If the component
  57  * elements should be traversed in some other order, instead of
  58  * calling <code>super.visit<i>Xyz</i></code>, an overriding visit method
  59  * should call {@code scan} with the elements in the desired order.
  60  *
  61  * @apiNote
  62  * Methods in this class may be overridden subject to their
  63  * general contract.
  64  *
  65  * @param <R> the return type of this visitor's methods.  Use {@link
  66  *            Void} for visitors that do not need to return results.
  67  * @param <P> the type of the additional parameter to this visitor's
  68  *            methods.  Use {@code Void} for visitors that do not need an
  69  *            additional parameter.
  70  *
  71  * @see <a href="ElementScanner6.html#note_for_subclasses"><strong>Compatibility note for subclasses</strong></a>
  72  * @see ElementScanner6
  73  * @see ElementScanner7
  74  * @see ElementScanner8
  75  * @see ElementScanner14
  76  * @since 9
  77  * @spec JPMS
  78  */
  79 @SupportedSourceVersion(RELEASE_14)
  80 public class ElementScanner9<R, P> extends ElementScanner8<R, P> {
  81     /**
  82      * Constructor for concrete subclasses; uses {@code null} for the
  83      * default value.
  84      */
  85     protected ElementScanner9(){
  86         super(null);
  87     }
  88 
  89     /**
  90      * Constructor for concrete subclasses; uses the argument for the
  91      * default value.
  92      *
  93      * @param defaultValue the default value
  94      */
  95     protected ElementScanner9(R defaultValue){
  96         super(defaultValue);
  97     }
  98 
  99     /**
 100      * {@inheritDoc}
 101      *
 102      * @implSpec This implementation scans the enclosed elements.
 103      *
 104      * @param e the element to visit
 105      * @param p a visitor-specified parameter
 106      * @return  the result of the scan
 107      */
 108     @Override
 109     public R visitModule(ModuleElement e, P p) {
 110         return scan(e.getEnclosedElements(), p); // TODO: Hmmm, this might not be right
 111     }
 112 }