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

Wed, 23 Jan 2013 20:11:07 -0800

author
darcy
date
Wed, 23 Jan 2013 20:11:07 -0800
changeset 1522
09f65aad4759
parent 1357
c75be5bc5283
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
Reviewed-by: jjg

duke@1 1 /*
darcy@1522 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
jjg@1357 28 import javax.annotation.processing.SupportedSourceVersion;
jjg@1357 29 import javax.lang.model.SourceVersion;
duke@1 30 import javax.lang.model.element.*;
duke@1 31 import static javax.lang.model.SourceVersion.*;
duke@1 32
duke@1 33
duke@1 34 /**
duke@1 35 * A skeletal visitor of program elements with default behavior
duke@1 36 * appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
duke@1 37 * source version.
duke@1 38 *
duke@1 39 * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
duke@1 40 * implemented by this class may have methods added to it in the
duke@1 41 * future to accommodate new, currently unknown, language structures
duke@1 42 * added to future versions of the Java&trade; programming language.
duke@1 43 * Therefore, methods whose names begin with {@code "visit"} may be
duke@1 44 * added to this class in the future; to avoid incompatibilities,
duke@1 45 * classes which extend this class should not declare any instance
duke@1 46 * methods with names beginning with {@code "visit"}.
duke@1 47 *
duke@1 48 * <p>When such a new visit method is added, the default
duke@1 49 * implementation in this class will be to call the {@link
duke@1 50 * #visitUnknown visitUnknown} method. A new abstract element visitor
duke@1 51 * class will also be introduced to correspond to the new language
duke@1 52 * level; this visitor will have different default behavior for the
duke@1 53 * visit method in question. When the new visitor is introduced, all
duke@1 54 * or portions of this visitor may be deprecated.
duke@1 55 *
darcy@1522 56 * <p>Note that adding a default implementation of a new visit method
darcy@1522 57 * in a visitor class will occur instead of adding a <em>default
darcy@1522 58 * method</em> directly in the visitor interface since a Java SE 8
darcy@1522 59 * language feature cannot be used to this version of the API since
darcy@1522 60 * this version is required to be runnable on Java SE 7
darcy@1522 61 * implementations. Future versions of the API that are only required
darcy@1522 62 * to run on Java SE 8 and later may take advantage of default methods
darcy@1522 63 * in this situation.
darcy@1522 64 *
duke@1 65 * @param <R> the return type of this visitor's methods. Use {@link
duke@1 66 * Void} for visitors that do not need to return results.
duke@1 67 * @param <P> the type of the additional parameter to this visitor's
duke@1 68 * methods. Use {@code Void} for visitors that do not need an
duke@1 69 * additional parameter.
duke@1 70 *
duke@1 71 * @author Joseph D. Darcy
duke@1 72 * @author Scott Seligman
duke@1 73 * @author Peter von der Ah&eacute;
darcy@575 74 *
darcy@575 75 * @see AbstractElementVisitor7
darcy@1054 76 * @see AbstractElementVisitor8
duke@1 77 * @since 1.6
duke@1 78 */
duke@1 79 @SupportedSourceVersion(RELEASE_6)
duke@1 80 public abstract class AbstractElementVisitor6<R, P> implements ElementVisitor<R, P> {
duke@1 81 /**
duke@1 82 * Constructor for concrete subclasses to call.
duke@1 83 */
duke@1 84 protected AbstractElementVisitor6(){}
duke@1 85
duke@1 86 /**
duke@1 87 * Visits any program element as if by passing itself to that
duke@1 88 * element's {@link Element#accept accept} method. The invocation
duke@1 89 * {@code v.visit(elem)} is equivalent to {@code elem.accept(v,
duke@1 90 * p)}.
duke@1 91 *
duke@1 92 * @param e the element to visit
duke@1 93 * @param p a visitor-specified parameter
duke@1 94 * @return a visitor-specified result
duke@1 95 */
duke@1 96 public final R visit(Element e, P p) {
duke@1 97 return e.accept(this, p);
duke@1 98 }
duke@1 99
duke@1 100 /**
duke@1 101 * Visits any program element as if by passing itself to that
duke@1 102 * element's {@link Element#accept accept} method and passing
duke@1 103 * {@code null} for the additional parameter. The invocation
duke@1 104 * {@code v.visit(elem)} is equivalent to {@code elem.accept(v,
duke@1 105 * null)}.
duke@1 106 *
duke@1 107 * @param e the element to visit
duke@1 108 * @return a visitor-specified result
duke@1 109 */
duke@1 110 public final R visit(Element e) {
duke@1 111 return e.accept(this, null);
duke@1 112 }
duke@1 113
duke@1 114 /**
duke@1 115 * {@inheritDoc}
duke@1 116 *
duke@1 117 * <p> The default implementation of this method in
duke@1 118 * {@code AbstractElementVisitor6} will always throw
duke@1 119 * {@code UnknownElementException}.
duke@1 120 * This behavior is not required of a subclass.
duke@1 121 *
duke@1 122 * @param e the element to visit
duke@1 123 * @param p a visitor-specified parameter
duke@1 124 * @return a visitor-specified result
duke@1 125 * @throws UnknownElementException
duke@1 126 * a visitor implementation may optionally throw this exception
duke@1 127 */
duke@1 128 public R visitUnknown(Element e, P p) {
duke@1 129 throw new UnknownElementException(e, p);
duke@1 130 }
duke@1 131 }

mercurial