src/share/classes/javax/lang/model/type/TypeVisitor.java

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

author
darcy
date
Wed, 23 Jan 2013 20:11:07 -0800
changeset 1522
09f65aad4759
parent 1521
71f35e4b93a5
child 1644
40adaf938847
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 /*
jjg@1521 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.type;
duke@1 27
duke@1 28 import javax.lang.model.element.*;
duke@1 29
duke@1 30 /**
duke@1 31 * A visitor of types, in the style of the
duke@1 32 * visitor design pattern. Classes implementing this
duke@1 33 * interface are used to operate on a type when the kind of
duke@1 34 * type is unknown at compile time. When a visitor is passed to a
duke@1 35 * type's {@link TypeMirror#accept accept} method, the <tt>visit<i>XYZ</i></tt>
duke@1 36 * method most applicable to that type is invoked.
duke@1 37 *
duke@1 38 * <p> Classes implementing this interface may or may not throw a
duke@1 39 * {@code NullPointerException} if the additional parameter {@code p}
duke@1 40 * is {@code null}; see documentation of the implementing class for
duke@1 41 * details.
duke@1 42 *
duke@1 43 * <p> <b>WARNING:</b> It is possible that methods will be added to
duke@1 44 * this interface to accommodate new, currently unknown, language
duke@1 45 * structures added to future versions of the Java&trade; programming
duke@1 46 * language. Therefore, visitor classes directly implementing this
duke@1 47 * interface may be source incompatible with future versions of the
duke@1 48 * platform. To avoid this source incompatibility, visitor
duke@1 49 * implementations are encouraged to instead extend the appropriate
duke@1 50 * abstract visitor class that implements this interface. However, an
duke@1 51 * API should generally use this visitor interface as the type for
duke@1 52 * parameters, return type, etc. rather than one of the abstract
duke@1 53 * classes.
duke@1 54 *
darcy@1522 55 * <p>Note that methods to accommodate new language constructs could
darcy@1522 56 * be added in a source <em>compatible</em> way if they were added as
darcy@1522 57 * <em>default methods</em>. However, default methods are only
darcy@1522 58 * available on Java SE 8 and higher releases and the {@code
darcy@1522 59 * javax.lang.model.*} packages bundled in Java SE 8 are required to
darcy@1522 60 * also be runnable on Java SE 7. Therefore, default methods
darcy@1522 61 * <em>cannot</em> be used when extending {@code javax.lang.model.*}
darcy@1522 62 * to cover Java SE 8 language features. However, default methods may
darcy@1522 63 * be used in subsequent revisions of the {@code javax.lang.model.*}
darcy@1522 64 * packages that are only required to run on Java SE 8 and higher
darcy@1522 65 * platform versions.
darcy@1522 66 *
duke@1 67 * @param <R> the return type of this visitor's methods. Use {@link
duke@1 68 * Void} for visitors that do not need to return results.
duke@1 69 * @param <P> the type of the additional parameter to this visitor's
duke@1 70 * methods. Use {@code Void} for visitors that do not need an
duke@1 71 * 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&eacute;
duke@1 76 * @since 1.6
duke@1 77 */
duke@1 78 public interface TypeVisitor<R, P> {
duke@1 79 /**
duke@1 80 * Visits a type.
duke@1 81 * @param t the type to visit
duke@1 82 * @param p a visitor-specified parameter
duke@1 83 * @return a visitor-specified result
duke@1 84 */
duke@1 85 R visit(TypeMirror t, P p);
duke@1 86
duke@1 87 /**
duke@1 88 * A convenience method equivalent to {@code v.visit(t, null)}.
duke@1 89 * @param t the element to visit
duke@1 90 * @return a visitor-specified result
duke@1 91 */
duke@1 92 R visit(TypeMirror t);
duke@1 93
duke@1 94 /**
duke@1 95 * Visits a primitive type.
duke@1 96 * @param t the type to visit
duke@1 97 * @param p a visitor-specified parameter
duke@1 98 * @return a visitor-specified result
duke@1 99 */
duke@1 100 R visitPrimitive(PrimitiveType t, P p);
duke@1 101
duke@1 102 /**
duke@1 103 * Visits the null type.
duke@1 104 * @param t the type to visit
duke@1 105 * @param p a visitor-specified parameter
duke@1 106 * @return a visitor-specified result
duke@1 107 */
duke@1 108 R visitNull(NullType t, P p);
duke@1 109
duke@1 110 /**
duke@1 111 * Visits an array type.
duke@1 112 * @param t the type to visit
duke@1 113 * @param p a visitor-specified parameter
duke@1 114 * @return a visitor-specified result
duke@1 115 */
duke@1 116 R visitArray(ArrayType t, P p);
duke@1 117
duke@1 118 /**
duke@1 119 * Visits a declared type.
duke@1 120 * @param t the type to visit
duke@1 121 * @param p a visitor-specified parameter
duke@1 122 * @return a visitor-specified result
duke@1 123 */
duke@1 124 R visitDeclared(DeclaredType t, P p);
duke@1 125
duke@1 126 /**
duke@1 127 * Visits an error type.
duke@1 128 * @param t the type to visit
duke@1 129 * @param p a visitor-specified parameter
duke@1 130 * @return a visitor-specified result
duke@1 131 */
duke@1 132 R visitError(ErrorType t, P p);
duke@1 133
duke@1 134 /**
duke@1 135 * Visits a type variable.
duke@1 136 * @param t the type to visit
duke@1 137 * @param p a visitor-specified parameter
duke@1 138 * @return a visitor-specified result
duke@1 139 */
duke@1 140 R visitTypeVariable(TypeVariable t, P p);
duke@1 141
duke@1 142 /**
duke@1 143 * Visits a wildcard type.
duke@1 144 * @param t the type to visit
duke@1 145 * @param p a visitor-specified parameter
duke@1 146 * @return a visitor-specified result
duke@1 147 */
duke@1 148 R visitWildcard(WildcardType t, P p);
duke@1 149
duke@1 150 /**
duke@1 151 * Visits an executable type.
duke@1 152 * @param t the type to visit
duke@1 153 * @param p a visitor-specified parameter
duke@1 154 * @return a visitor-specified result
duke@1 155 */
duke@1 156 R visitExecutable(ExecutableType t, P p);
duke@1 157
duke@1 158 /**
duke@1 159 * Visits a {@link NoType} instance.
duke@1 160 * @param t the type to visit
duke@1 161 * @param p a visitor-specified parameter
duke@1 162 * @return a visitor-specified result
duke@1 163 */
duke@1 164 R visitNoType(NoType t, P p);
duke@1 165
duke@1 166 /**
duke@1 167 * Visits an unknown kind of type.
duke@1 168 * This can occur if the language evolves and new kinds
duke@1 169 * of types are added to the {@code TypeMirror} hierarchy.
duke@1 170 * @param t the type to visit
duke@1 171 * @param p a visitor-specified parameter
duke@1 172 * @return a visitor-specified result
duke@1 173 * @throws UnknownTypeException
duke@1 174 * a visitor implementation may optionally throw this exception
duke@1 175 */
duke@1 176 R visitUnknown(TypeMirror t, P p);
darcy@851 177
darcy@851 178 /**
darcy@969 179 * Visits a union type.
darcy@851 180 *
darcy@851 181 * @param t the type to visit
darcy@851 182 * @param p a visitor-specified parameter
darcy@851 183 * @return a visitor-specified result
darcy@851 184 * @since 1.7
darcy@851 185 */
darcy@969 186 R visitUnion(UnionType t, P p);
mcimadamore@1436 187
mcimadamore@1436 188 /**
mcimadamore@1436 189 * Visits an intersection type.
mcimadamore@1436 190 *
mcimadamore@1436 191 * @param t the type to visit
mcimadamore@1436 192 * @param p a visitor-specified parameter
mcimadamore@1436 193 * @return a visitor-specified result
mcimadamore@1436 194 * @since 1.8
mcimadamore@1436 195 */
mcimadamore@1436 196 R visitIntersection(IntersectionType t, P p);
jjg@1521 197
jjg@1521 198 /**
jjg@1521 199 * Visits an annotated type.
jjg@1521 200 *
jjg@1521 201 * @param t the type to visit
jjg@1521 202 * @param p a visitor-specified parameter
jjg@1521 203 * @return a visitor-specified result
jjg@1521 204 * @since 1.8
jjg@1521 205 */
jjg@1521 206 R visitAnnotated(AnnotatedType t, P p);
duke@1 207 }

mercurial