Tue, 09 Oct 2012 19:10:00 -0700
8000663: clean up langtools imports
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1357 | 2 | * Copyright (c) 2005, 2012, 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 simple 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 | * Visit methods corresponding to {@code RELEASE_6} language |
darcy@851 | 40 | * constructs call {@link #defaultAction defaultAction}, passing their |
darcy@851 | 41 | * arguments to {@code defaultAction}'s corresponding parameters. |
darcy@851 | 42 | * |
darcy@851 | 43 | * For constructs introduced in {@code RELEASE_7} and later, {@code |
darcy@851 | 44 | * visitUnknown} is called instead. |
duke@1 | 45 | * |
duke@1 | 46 | * <p> Methods in this class may be overridden subject to their |
duke@1 | 47 | * general contract. Note that annotating methods in concrete |
duke@1 | 48 | * subclasses with {@link java.lang.Override @Override} will help |
duke@1 | 49 | * ensure that methods are overridden as intended. |
duke@1 | 50 | * |
duke@1 | 51 | * <p> <b>WARNING:</b> The {@code ElementVisitor} interface |
duke@1 | 52 | * implemented by this class may have methods added to it in the |
duke@1 | 53 | * future to accommodate new, currently unknown, language structures |
duke@1 | 54 | * added to future versions of the Java™ programming language. |
duke@1 | 55 | * Therefore, methods whose names begin with {@code "visit"} may be |
duke@1 | 56 | * added to this class in the future; to avoid incompatibilities, |
duke@1 | 57 | * classes which extend this class should not declare any instance |
duke@1 | 58 | * methods with names beginning with {@code "visit"}. |
duke@1 | 59 | * |
duke@1 | 60 | * <p>When such a new visit method is added, the default |
duke@1 | 61 | * implementation in this class will be to call the {@link |
duke@1 | 62 | * #visitUnknown visitUnknown} method. A new simple element visitor |
duke@1 | 63 | * class will also be introduced to correspond to the new language |
duke@1 | 64 | * level; this visitor will have different default behavior for the |
duke@1 | 65 | * visit method in question. When the new visitor is introduced, all |
duke@1 | 66 | * or portions of this visitor may be deprecated. |
duke@1 | 67 | * |
duke@1 | 68 | * @param <R> the return type of this visitor's methods. Use {@code Void} |
duke@1 | 69 | * for visitors that do not need to return results. |
duke@1 | 70 | * @param <P> the type of the additional parameter to this visitor's methods. Use {@code Void} |
duke@1 | 71 | * for visitors that do not need an additional parameter. |
duke@1 | 72 | * |
duke@1 | 73 | * @author Joseph D. Darcy |
duke@1 | 74 | * @author Scott Seligman |
duke@1 | 75 | * @author Peter von der Ahé |
darcy@575 | 76 | * |
darcy@575 | 77 | * @see SimpleElementVisitor7 |
darcy@1054 | 78 | * @see SimpleElementVisitor8 |
duke@1 | 79 | * @since 1.6 |
duke@1 | 80 | */ |
duke@1 | 81 | @SupportedSourceVersion(RELEASE_6) |
duke@1 | 82 | public class SimpleElementVisitor6<R, P> extends AbstractElementVisitor6<R, P> { |
duke@1 | 83 | /** |
duke@1 | 84 | * Default value to be returned; {@link #defaultAction |
duke@1 | 85 | * defaultAction} returns this value unless the method is |
duke@1 | 86 | * overridden. |
duke@1 | 87 | */ |
duke@1 | 88 | protected final R DEFAULT_VALUE; |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * Constructor for concrete subclasses; uses {@code null} for the |
duke@1 | 92 | * default value. |
duke@1 | 93 | */ |
duke@1 | 94 | protected SimpleElementVisitor6(){ |
duke@1 | 95 | DEFAULT_VALUE = null; |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * Constructor for concrete subclasses; uses the argument for the |
duke@1 | 100 | * default value. |
duke@1 | 101 | * |
duke@1 | 102 | * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} |
duke@1 | 103 | */ |
duke@1 | 104 | protected SimpleElementVisitor6(R defaultValue){ |
duke@1 | 105 | DEFAULT_VALUE = defaultValue; |
duke@1 | 106 | } |
duke@1 | 107 | /** |
duke@1 | 108 | * The default action for visit methods. The implementation in |
duke@1 | 109 | * this class just returns {@link #DEFAULT_VALUE}; subclasses will |
duke@1 | 110 | * commonly override this method. |
duke@1 | 111 | * |
duke@1 | 112 | * @param e the element to process |
duke@1 | 113 | * @param p a visitor-specified parameter |
duke@1 | 114 | * @return {@code DEFAULT_VALUE} unless overridden |
duke@1 | 115 | */ |
duke@1 | 116 | protected R defaultAction(Element e, P p) { |
duke@1 | 117 | return DEFAULT_VALUE; |
duke@1 | 118 | } |
duke@1 | 119 | |
duke@1 | 120 | /** |
duke@1 | 121 | * {@inheritDoc} This implementation calls {@code defaultAction}. |
duke@1 | 122 | * |
duke@1 | 123 | * @param e {@inheritDoc} |
duke@1 | 124 | * @param p {@inheritDoc} |
duke@1 | 125 | * @return the result of {@code defaultAction} |
duke@1 | 126 | */ |
duke@1 | 127 | public R visitPackage(PackageElement e, P p) { |
duke@1 | 128 | return defaultAction(e, p); |
duke@1 | 129 | } |
duke@1 | 130 | |
duke@1 | 131 | /** |
duke@1 | 132 | * {@inheritDoc} This implementation calls {@code defaultAction}. |
duke@1 | 133 | * |
duke@1 | 134 | * @param e {@inheritDoc} |
duke@1 | 135 | * @param p {@inheritDoc} |
duke@1 | 136 | * @return the result of {@code defaultAction} |
duke@1 | 137 | */ |
duke@1 | 138 | public R visitType(TypeElement e, P p) { |
duke@1 | 139 | return defaultAction(e, p); |
duke@1 | 140 | } |
duke@1 | 141 | |
duke@1 | 142 | /** |
darcy@851 | 143 | * {@inheritDoc} |
darcy@851 | 144 | * |
darcy@851 | 145 | * This implementation calls {@code defaultAction}, unless the |
darcy@851 | 146 | * element is a {@code RESOURCE_VARIABLE} in which case {@code |
darcy@851 | 147 | * visitUnknown} is called. |
duke@1 | 148 | * |
duke@1 | 149 | * @param e {@inheritDoc} |
duke@1 | 150 | * @param p {@inheritDoc} |
darcy@851 | 151 | * @return the result of {@code defaultAction} or {@code visitUnknown} |
duke@1 | 152 | */ |
duke@1 | 153 | public R visitVariable(VariableElement e, P p) { |
darcy@851 | 154 | if (e.getKind() != ElementKind.RESOURCE_VARIABLE) |
darcy@851 | 155 | return defaultAction(e, p); |
darcy@851 | 156 | else |
darcy@851 | 157 | return visitUnknown(e, p); |
duke@1 | 158 | } |
duke@1 | 159 | |
duke@1 | 160 | /** |
duke@1 | 161 | * {@inheritDoc} This implementation calls {@code defaultAction}. |
duke@1 | 162 | * |
duke@1 | 163 | * @param e {@inheritDoc} |
duke@1 | 164 | * @param p {@inheritDoc} |
duke@1 | 165 | * @return the result of {@code defaultAction} |
duke@1 | 166 | */ |
duke@1 | 167 | public R visitExecutable(ExecutableElement e, P p) { |
duke@1 | 168 | return defaultAction(e, p); |
duke@1 | 169 | } |
duke@1 | 170 | |
duke@1 | 171 | /** |
duke@1 | 172 | * {@inheritDoc} This implementation calls {@code defaultAction}. |
duke@1 | 173 | * |
duke@1 | 174 | * @param e {@inheritDoc} |
duke@1 | 175 | * @param p {@inheritDoc} |
duke@1 | 176 | * @return the result of {@code defaultAction} |
duke@1 | 177 | */ |
duke@1 | 178 | public R visitTypeParameter(TypeParameterElement e, P p) { |
duke@1 | 179 | return defaultAction(e, p); |
duke@1 | 180 | } |
duke@1 | 181 | } |