1 /* 2 * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any questions. 24 */ 25 26 package javax.lang.model.util; 27 28 import javax.lang.model.type.*; 29 import javax.annotation.processing.SupportedSourceVersion; 30 import javax.lang.model.SourceVersion; 31 import static javax.lang.model.SourceVersion.*; 32 33 34 /** 35 * A simple visitor of types with default behavior appropriate for the 36 * {@link SourceVersion#RELEASE_6 RELEASE_6} source version. 37 * 38 * Visit methods corresponding to {@code RELEASE_6} language 39 * constructs call {@link #defaultAction}, passing their arguments to 40 * {@code defaultAction}'s corresponding parameters. 41 * 42 * <p> Methods in this class may be overridden subject to their 43 * general contract. Note that annotating methods in concrete 44 * subclasses with {@link java.lang.Override @Override} will help 45 * ensure that methods are overridden as intended. 46 * 47 * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented 48 * by this class may have methods added to it in the future to 49 * accommodate new, currently unknown, language structures added to 50 * future versions of the Java™ programming language. 51 * Therefore, methods whose names begin with {@code "visit"} may be 52 * added to this class in the future; to avoid incompatibilities, 53 * classes which extend this class should not declare any instance 54 * methods with names beginning with {@code "visit"}. 55 * 56 * <p>When such a new visit method is added, the default 57 * implementation in this class will be to call the {@link 58 * #visitUnknown visitUnknown} method. A new simple type visitor 59 * class will also be introduced to correspond to the new language 60 * level; this visitor will have different default behavior for the 61 * visit method in question. When the new visitor is introduced, all 62 * or portions of this visitor may be deprecated. 63 * 64 * @param <R> the return type of this visitor's methods. Use {@link 65 * Void} for visitors that do not need to return results. 66 * @param <P> the type of the additional parameter to this visitor's 67 * methods. Use {@code Void} for visitors that do not need an 68 * additional parameter. 69 * 70 * @author Joseph D. Darcy 71 * @author Scott Seligman 72 * @author Peter von der Ahé 73 * @since 1.6 74 */ 75 @SupportedSourceVersion(RELEASE_6) 76 public class SimpleTypeVisitor6<R, P> extends AbstractTypeVisitor6<R, P> { 77 /** 78 * Default value to be returned; {@link #defaultAction 79 * defaultAction} returns this value unless the method is 80 * overridden. 81 */ 82 protected final R DEFAULT_VALUE; 83 84 /** 85 * Constructor for concrete subclasses; uses {@code null} for the 86 * default value. 87 */ 88 protected SimpleTypeVisitor6(){ 89 DEFAULT_VALUE = null; 90 } 91 92 /** 93 * Constructor for concrete subclasses; uses the argument for the 94 * default value. 95 * 96 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} 97 */ 98 protected SimpleTypeVisitor6(R defaultValue){ 99 DEFAULT_VALUE = defaultValue; 100 } 101 102 /** 103 * The default action for visit methods. The implementation in 104 * this class just returns {@link #DEFAULT_VALUE}; subclasses will 105 * commonly override this method. 106 */ 107 protected R defaultAction(TypeMirror e, P p) { 108 return DEFAULT_VALUE; 109 } 110 111 /** 112 * {@inheritDoc} This implementation calls {@code defaultAction}. 113 * 114 * @param t {@inheritDoc} 115 * @param p {@inheritDoc} 116 * @return the result of {@code defaultAction} 117 */ 118 public R visitPrimitive(PrimitiveType t, P p) { 119 return defaultAction(t, p); 120 } 121 122 /** 123 * {@inheritDoc} This implementation calls {@code defaultAction}. 124 * 125 * @param t {@inheritDoc} 126 * @param p {@inheritDoc} 127 * @return the result of {@code defaultAction} 128 */ 129 public R visitNull(NullType t, P p){ 130 return defaultAction(t, p); 131 } 132 133 /** 134 * {@inheritDoc} This implementation calls {@code defaultAction}. 135 * 136 * @param t {@inheritDoc} 137 * @param p {@inheritDoc} 138 * @return the result of {@code defaultAction} 139 */ 140 public R visitArray(ArrayType t, P p){ 141 return defaultAction(t, p); 142 } 143 144 /** 145 * {@inheritDoc} This implementation calls {@code defaultAction}. 146 * 147 * @param t {@inheritDoc} 148 * @param p {@inheritDoc} 149 * @return the result of {@code defaultAction} 150 */ 151 public R visitDeclared(DeclaredType t, P p){ 152 return defaultAction(t, p); 153 } 154 155 /** 156 * {@inheritDoc} This implementation calls {@code defaultAction}. 157 * 158 * @param t {@inheritDoc} 159 * @param p {@inheritDoc} 160 * @return the result of {@code defaultAction} 161 */ 162 public R visitError(ErrorType t, P p){ 163 return defaultAction(t, p); 164 } 165 166 /** 167 * {@inheritDoc} This implementation calls {@code defaultAction}. 168 * 169 * @param t {@inheritDoc} 170 * @param p {@inheritDoc} 171 * @return the result of {@code defaultAction} 172 */ 173 public R visitTypeVariable(TypeVariable t, P p){ 174 return defaultAction(t, p); 175 } 176 177 /** 178 * {@inheritDoc} This implementation calls {@code defaultAction}. 179 * 180 * @param t {@inheritDoc} 181 * @param p {@inheritDoc} 182 * @return the result of {@code defaultAction} 183 */ 184 public R visitWildcard(WildcardType t, P p){ 185 return defaultAction(t, p); 186 } 187 188 /** 189 * {@inheritDoc} This implementation calls {@code defaultAction}. 190 * 191 * @param t {@inheritDoc} 192 * @param p {@inheritDoc} 193 * @return the result of {@code defaultAction} 194 */ 195 public R visitExecutable(ExecutableType t, P p) { 196 return defaultAction(t, p); 197 } 198 199 /** 200 * {@inheritDoc} This implementation calls {@code defaultAction}. 201 * 202 * @param t {@inheritDoc} 203 * @param p {@inheritDoc} 204 * @return the result of {@code defaultAction} 205 */ 206 public R visitNoType(NoType t, P p){ 207 return defaultAction(t, p); 208 } 209 }