Tue, 28 Dec 2010 15:54:52 -0800
6962318: Update copyright year
Reviewed-by: xdono
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2005, 2006, 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™ 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 | * |
duke@1 | 55 | * @param <R> the return type of this visitor's methods. Use {@link |
duke@1 | 56 | * Void} for visitors that do not need to return results. |
duke@1 | 57 | * @param <P> the type of the additional parameter to this visitor's |
duke@1 | 58 | * methods. Use {@code Void} for visitors that do not need an |
duke@1 | 59 | * additional parameter. |
duke@1 | 60 | * |
duke@1 | 61 | * @author Joseph D. Darcy |
duke@1 | 62 | * @author Scott Seligman |
duke@1 | 63 | * @author Peter von der Ahé |
duke@1 | 64 | * @since 1.6 |
duke@1 | 65 | */ |
duke@1 | 66 | public interface TypeVisitor<R, P> { |
duke@1 | 67 | /** |
duke@1 | 68 | * Visits a type. |
duke@1 | 69 | * @param t the type to visit |
duke@1 | 70 | * @param p a visitor-specified parameter |
duke@1 | 71 | * @return a visitor-specified result |
duke@1 | 72 | */ |
duke@1 | 73 | R visit(TypeMirror t, P p); |
duke@1 | 74 | |
duke@1 | 75 | /** |
duke@1 | 76 | * A convenience method equivalent to {@code v.visit(t, null)}. |
duke@1 | 77 | * @param t the element to visit |
duke@1 | 78 | * @return a visitor-specified result |
duke@1 | 79 | */ |
duke@1 | 80 | R visit(TypeMirror t); |
duke@1 | 81 | |
duke@1 | 82 | /** |
duke@1 | 83 | * Visits a primitive type. |
duke@1 | 84 | * @param t the type to visit |
duke@1 | 85 | * @param p a visitor-specified parameter |
duke@1 | 86 | * @return a visitor-specified result |
duke@1 | 87 | */ |
duke@1 | 88 | R visitPrimitive(PrimitiveType t, P p); |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * Visits the null type. |
duke@1 | 92 | * @param t the type 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 | R visitNull(NullType t, P p); |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * Visits an array type. |
duke@1 | 100 | * @param t the type to visit |
duke@1 | 101 | * @param p a visitor-specified parameter |
duke@1 | 102 | * @return a visitor-specified result |
duke@1 | 103 | */ |
duke@1 | 104 | R visitArray(ArrayType t, P p); |
duke@1 | 105 | |
duke@1 | 106 | /** |
duke@1 | 107 | * Visits a declared type. |
duke@1 | 108 | * @param t the type to visit |
duke@1 | 109 | * @param p a visitor-specified parameter |
duke@1 | 110 | * @return a visitor-specified result |
duke@1 | 111 | */ |
duke@1 | 112 | R visitDeclared(DeclaredType t, P p); |
duke@1 | 113 | |
duke@1 | 114 | /** |
duke@1 | 115 | * Visits an error type. |
duke@1 | 116 | * @param t the type to visit |
duke@1 | 117 | * @param p a visitor-specified parameter |
duke@1 | 118 | * @return a visitor-specified result |
duke@1 | 119 | */ |
duke@1 | 120 | R visitError(ErrorType t, P p); |
duke@1 | 121 | |
duke@1 | 122 | /** |
duke@1 | 123 | * Visits a type variable. |
duke@1 | 124 | * @param t the type to visit |
duke@1 | 125 | * @param p a visitor-specified parameter |
duke@1 | 126 | * @return a visitor-specified result |
duke@1 | 127 | */ |
duke@1 | 128 | R visitTypeVariable(TypeVariable t, P p); |
duke@1 | 129 | |
duke@1 | 130 | /** |
duke@1 | 131 | * Visits a wildcard type. |
duke@1 | 132 | * @param t the type to visit |
duke@1 | 133 | * @param p a visitor-specified parameter |
duke@1 | 134 | * @return a visitor-specified result |
duke@1 | 135 | */ |
duke@1 | 136 | R visitWildcard(WildcardType t, P p); |
duke@1 | 137 | |
duke@1 | 138 | /** |
duke@1 | 139 | * Visits an executable type. |
duke@1 | 140 | * @param t the type to visit |
duke@1 | 141 | * @param p a visitor-specified parameter |
duke@1 | 142 | * @return a visitor-specified result |
duke@1 | 143 | */ |
duke@1 | 144 | R visitExecutable(ExecutableType t, P p); |
duke@1 | 145 | |
duke@1 | 146 | /** |
duke@1 | 147 | * Visits a {@link NoType} instance. |
duke@1 | 148 | * @param t the type to visit |
duke@1 | 149 | * @param p a visitor-specified parameter |
duke@1 | 150 | * @return a visitor-specified result |
duke@1 | 151 | */ |
duke@1 | 152 | R visitNoType(NoType t, P p); |
duke@1 | 153 | |
duke@1 | 154 | /** |
duke@1 | 155 | * Visits an unknown kind of type. |
duke@1 | 156 | * This can occur if the language evolves and new kinds |
duke@1 | 157 | * of types are added to the {@code TypeMirror} hierarchy. |
duke@1 | 158 | * @param t the type to visit |
duke@1 | 159 | * @param p a visitor-specified parameter |
duke@1 | 160 | * @return a visitor-specified result |
duke@1 | 161 | * @throws UnknownTypeException |
duke@1 | 162 | * a visitor implementation may optionally throw this exception |
duke@1 | 163 | */ |
duke@1 | 164 | R visitUnknown(TypeMirror t, P p); |
duke@1 | 165 | } |