src/share/classes/javax/lang/model/util/ElementScanner6.java

Mon, 17 Jun 2013 14:46:01 -0700

author
darcy
date
Mon, 17 Jun 2013 14:46:01 -0700
changeset 1823
b7a10bc02e7a
parent 1725
e8987ce7fb4b
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8016779: Fix doclint warnings in javax.lang.model
Reviewed-by: jjg

duke@1 1 /*
darcy@1725 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package javax.lang.model.util;
duke@1 27
duke@1 28 import javax.lang.model.element.*;
duke@1 29 import javax.annotation.processing.SupportedSourceVersion;
duke@1 30 import javax.lang.model.SourceVersion;
duke@1 31 import static javax.lang.model.SourceVersion.*;
duke@1 32
duke@1 33
duke@1 34 /**
duke@1 35 * A scanning visitor of program elements with default behavior
duke@1 36 * appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
duke@1 37 * source version. The <tt>visit<i>XYZ</i></tt> methods in this
duke@1 38 * class scan their component elements by calling {@code scan} on
duke@1 39 * their {@linkplain Element#getEnclosedElements enclosed elements},
duke@1 40 * {@linkplain ExecutableElement#getParameters parameters}, etc., as
duke@1 41 * indicated in the individual method specifications. A subclass can
duke@1 42 * control the order elements are visited by overriding the
duke@1 43 * <tt>visit<i>XYZ</i></tt> methods. Note that clients of a scanner
duke@1 44 * may get the desired behavior be invoking {@code v.scan(e, p)} rather
duke@1 45 * than {@code v.visit(e, p)} on the root objects of interest.
duke@1 46 *
duke@1 47 * <p>When a subclass overrides a <tt>visit<i>XYZ</i></tt> method, the
duke@1 48 * new method can cause the enclosed elements to be scanned in the
duke@1 49 * default way by calling <tt>super.visit<i>XYZ</i></tt>. In this
duke@1 50 * fashion, the concrete visitor can control the ordering of traversal
duke@1 51 * over the component elements with respect to the additional
duke@1 52 * processing; for example, consistently calling
duke@1 53 * <tt>super.visit<i>XYZ</i></tt> at the start of the overridden
duke@1 54 * methods will yield a preorder traversal, etc. If the component
duke@1 55 * elements should be traversed in some other order, instead of
duke@1 56 * calling <tt>super.visit<i>XYZ</i></tt>, an overriding visit method
duke@1 57 * should call {@code scan} with the elements in the desired order.
duke@1 58 *
duke@1 59 * <p> Methods in this class may be overridden subject to their
duke@1 60 * general contract. Note that annotating methods in concrete
duke@1 61 * subclasses with {@link java.lang.Override @Override} will help
duke@1 62 * ensure that methods are overridden as intended.
duke@1 63 *
duke@1 64 * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
duke@1 65 * implemented by this class may have methods added to it in the
duke@1 66 * future to accommodate new, currently unknown, language structures
duke@1 67 * added to future versions of the Java&trade; programming language.
duke@1 68 * Therefore, methods whose names begin with {@code "visit"} may be
duke@1 69 * added to this class in the future; to avoid incompatibilities,
duke@1 70 * classes which extend this class should not declare any instance
duke@1 71 * methods with names beginning with {@code "visit"}.
duke@1 72 *
duke@1 73 * <p>When such a new visit method is added, the default
duke@1 74 * implementation in this class will be to call the {@link
duke@1 75 * #visitUnknown visitUnknown} method. A new element scanner visitor
duke@1 76 * class will also be introduced to correspond to the new language
duke@1 77 * level; this visitor will have different default behavior for the
duke@1 78 * visit method in question. When the new visitor is introduced, all
duke@1 79 * or portions of this visitor may be deprecated.
duke@1 80 *
duke@1 81 * @param <R> the return type of this visitor's methods. Use {@link
duke@1 82 * Void} for visitors that do not need to return results.
duke@1 83 * @param <P> the type of the additional parameter to this visitor's
duke@1 84 * methods. Use {@code Void} for visitors that do not need an
duke@1 85 * additional parameter.
duke@1 86 *
duke@1 87 * @author Joseph D. Darcy
duke@1 88 * @author Scott Seligman
duke@1 89 * @author Peter von der Ah&eacute;
darcy@575 90 *
darcy@575 91 * @see ElementScanner7
darcy@1054 92 * @see ElementScanner8
duke@1 93 * @since 1.6
duke@1 94 */
duke@1 95 @SupportedSourceVersion(RELEASE_6)
duke@1 96 public class ElementScanner6<R, P> extends AbstractElementVisitor6<R, P> {
duke@1 97 /**
duke@1 98 * The specified default value.
duke@1 99 */
duke@1 100 protected final R DEFAULT_VALUE;
duke@1 101
duke@1 102 /**
duke@1 103 * Constructor for concrete subclasses; uses {@code null} for the
duke@1 104 * default value.
duke@1 105 */
duke@1 106 protected ElementScanner6(){
duke@1 107 DEFAULT_VALUE = null;
duke@1 108 }
duke@1 109
duke@1 110 /**
duke@1 111 * Constructor for concrete subclasses; uses the argument for the
duke@1 112 * default value.
darcy@1823 113 *
darcy@1823 114 * @param defaultValue the default value
duke@1 115 */
duke@1 116 protected ElementScanner6(R defaultValue){
duke@1 117 DEFAULT_VALUE = defaultValue;
duke@1 118 }
duke@1 119
duke@1 120 /**
duke@1 121 * Iterates over the given elements and calls {@link
duke@1 122 * #scan(Element, Object) scan(Element, P)} on each one. Returns
duke@1 123 * the result of the last call to {@code scan} or {@code
duke@1 124 * DEFAULT_VALUE} for an empty iterable.
duke@1 125 *
duke@1 126 * @param iterable the elements to scan
duke@1 127 * @param p additional parameter
duke@1 128 * @return the scan of the last element or {@code DEFAULT_VALUE} if no elements
duke@1 129 */
duke@1 130 public final R scan(Iterable<? extends Element> iterable, P p) {
duke@1 131 R result = DEFAULT_VALUE;
duke@1 132 for(Element e : iterable)
duke@1 133 result = scan(e, p);
duke@1 134 return result;
duke@1 135 }
duke@1 136
duke@1 137 /**
duke@1 138 * Processes an element by calling {@code e.accept(this, p)};
duke@1 139 * this method may be overridden by subclasses.
darcy@1725 140 *
darcy@1725 141 * @param e the element to scan
darcy@1725 142 * @param p a scanner-specified parameter
duke@1 143 * @return the result of visiting {@code e}.
duke@1 144 */
duke@1 145 public R scan(Element e, P p) {
duke@1 146 return e.accept(this, p);
duke@1 147 }
duke@1 148
duke@1 149 /**
duke@1 150 * Convenience method equivalent to {@code v.scan(e, null)}.
darcy@1725 151 *
darcy@1725 152 * @param e the element to scan
duke@1 153 * @return the result of scanning {@code e}.
duke@1 154 */
duke@1 155 public final R scan(Element e) {
duke@1 156 return scan(e, null);
duke@1 157 }
duke@1 158
duke@1 159 /**
duke@1 160 * {@inheritDoc} This implementation scans the enclosed elements.
duke@1 161 *
darcy@851 162 * @param e {@inheritDoc}
darcy@851 163 * @param p {@inheritDoc}
duke@1 164 * @return the result of scanning
duke@1 165 */
duke@1 166 public R visitPackage(PackageElement e, P p) {
duke@1 167 return scan(e.getEnclosedElements(), p);
duke@1 168 }
duke@1 169
duke@1 170 /**
duke@1 171 * {@inheritDoc} This implementation scans the enclosed elements.
duke@1 172 *
darcy@851 173 * @param e {@inheritDoc}
darcy@851 174 * @param p {@inheritDoc}
duke@1 175 * @return the result of scanning
duke@1 176 */
duke@1 177 public R visitType(TypeElement e, P p) {
duke@1 178 return scan(e.getEnclosedElements(), p);
duke@1 179 }
duke@1 180
duke@1 181 /**
darcy@851 182 * {@inheritDoc}
duke@1 183 *
darcy@851 184 * This implementation scans the enclosed elements, unless the
darcy@851 185 * element is a {@code RESOURCE_VARIABLE} in which case {@code
darcy@851 186 * visitUnknown} is called.
darcy@851 187 *
darcy@851 188 * @param e {@inheritDoc}
darcy@851 189 * @param p {@inheritDoc}
duke@1 190 * @return the result of scanning
duke@1 191 */
duke@1 192 public R visitVariable(VariableElement e, P p) {
darcy@851 193 if (e.getKind() != ElementKind.RESOURCE_VARIABLE)
darcy@851 194 return scan(e.getEnclosedElements(), p);
darcy@851 195 else
darcy@851 196 return visitUnknown(e, p);
duke@1 197 }
duke@1 198
duke@1 199 /**
duke@1 200 * {@inheritDoc} This implementation scans the parameters.
duke@1 201 *
darcy@851 202 * @param e {@inheritDoc}
darcy@851 203 * @param p {@inheritDoc}
duke@1 204 * @return the result of scanning
duke@1 205 */
duke@1 206 public R visitExecutable(ExecutableElement e, P p) {
duke@1 207 return scan(e.getParameters(), p);
duke@1 208 }
duke@1 209
duke@1 210 /**
duke@1 211 * {@inheritDoc} This implementation scans the enclosed elements.
duke@1 212 *
darcy@851 213 * @param e {@inheritDoc}
darcy@851 214 * @param p {@inheritDoc}
duke@1 215 * @return the result of scanning
duke@1 216 */
duke@1 217 public R visitTypeParameter(TypeParameterElement e, P p) {
duke@1 218 return scan(e.getEnclosedElements(), p);
duke@1 219 }
duke@1 220 }

mercurial