Thu, 31 Aug 2017 15:17:03 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.lang.model.type; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import javax.lang.model.element.*; |
aoqi@0 | 29 | |
aoqi@0 | 30 | /** |
aoqi@0 | 31 | * A visitor of types, in the style of the |
aoqi@0 | 32 | * visitor design pattern. Classes implementing this |
aoqi@0 | 33 | * interface are used to operate on a type when the kind of |
aoqi@0 | 34 | * type is unknown at compile time. When a visitor is passed to a |
aoqi@0 | 35 | * type's {@link TypeMirror#accept accept} method, the <tt>visit<i>XYZ</i></tt> |
aoqi@0 | 36 | * method most applicable to that type is invoked. |
aoqi@0 | 37 | * |
aoqi@0 | 38 | * <p> Classes implementing this interface may or may not throw a |
aoqi@0 | 39 | * {@code NullPointerException} if the additional parameter {@code p} |
aoqi@0 | 40 | * is {@code null}; see documentation of the implementing class for |
aoqi@0 | 41 | * details. |
aoqi@0 | 42 | * |
aoqi@0 | 43 | * <p> <b>WARNING:</b> It is possible that methods will be added to |
aoqi@0 | 44 | * this interface to accommodate new, currently unknown, language |
aoqi@0 | 45 | * structures added to future versions of the Java™ programming |
aoqi@0 | 46 | * language. Therefore, visitor classes directly implementing this |
aoqi@0 | 47 | * interface may be source incompatible with future versions of the |
aoqi@0 | 48 | * platform. To avoid this source incompatibility, visitor |
aoqi@0 | 49 | * implementations are encouraged to instead extend the appropriate |
aoqi@0 | 50 | * abstract visitor class that implements this interface. However, an |
aoqi@0 | 51 | * API should generally use this visitor interface as the type for |
aoqi@0 | 52 | * parameters, return type, etc. rather than one of the abstract |
aoqi@0 | 53 | * classes. |
aoqi@0 | 54 | * |
aoqi@0 | 55 | * <p>Note that methods to accommodate new language constructs could |
aoqi@0 | 56 | * be added in a source <em>compatible</em> way if they were added as |
aoqi@0 | 57 | * <em>default methods</em>. However, default methods are only |
aoqi@0 | 58 | * available on Java SE 8 and higher releases and the {@code |
aoqi@0 | 59 | * javax.lang.model.*} packages bundled in Java SE 8 are required to |
aoqi@0 | 60 | * also be runnable on Java SE 7. Therefore, default methods |
aoqi@0 | 61 | * <em>cannot</em> be used when extending {@code javax.lang.model.*} |
aoqi@0 | 62 | * to cover Java SE 8 language features. However, default methods may |
aoqi@0 | 63 | * be used in subsequent revisions of the {@code javax.lang.model.*} |
aoqi@0 | 64 | * packages that are only required to run on Java SE 8 and higher |
aoqi@0 | 65 | * platform versions. |
aoqi@0 | 66 | * |
aoqi@0 | 67 | * @param <R> the return type of this visitor's methods. Use {@link |
aoqi@0 | 68 | * Void} for visitors that do not need to return results. |
aoqi@0 | 69 | * @param <P> the type of the additional parameter to this visitor's |
aoqi@0 | 70 | * methods. Use {@code Void} for visitors that do not need an |
aoqi@0 | 71 | * additional parameter. |
aoqi@0 | 72 | * |
aoqi@0 | 73 | * @author Joseph D. Darcy |
aoqi@0 | 74 | * @author Scott Seligman |
aoqi@0 | 75 | * @author Peter von der Ahé |
aoqi@0 | 76 | * @since 1.6 |
aoqi@0 | 77 | */ |
aoqi@0 | 78 | public interface TypeVisitor<R, P> { |
aoqi@0 | 79 | /** |
aoqi@0 | 80 | * Visits a type. |
aoqi@0 | 81 | * @param t the type to visit |
aoqi@0 | 82 | * @param p a visitor-specified parameter |
aoqi@0 | 83 | * @return a visitor-specified result |
aoqi@0 | 84 | */ |
aoqi@0 | 85 | R visit(TypeMirror t, P p); |
aoqi@0 | 86 | |
aoqi@0 | 87 | /** |
aoqi@0 | 88 | * A convenience method equivalent to {@code v.visit(t, null)}. |
aoqi@0 | 89 | * @param t the element to visit |
aoqi@0 | 90 | * @return a visitor-specified result |
aoqi@0 | 91 | */ |
aoqi@0 | 92 | R visit(TypeMirror t); |
aoqi@0 | 93 | |
aoqi@0 | 94 | /** |
aoqi@0 | 95 | * Visits a primitive type. |
aoqi@0 | 96 | * @param t the type to visit |
aoqi@0 | 97 | * @param p a visitor-specified parameter |
aoqi@0 | 98 | * @return a visitor-specified result |
aoqi@0 | 99 | */ |
aoqi@0 | 100 | R visitPrimitive(PrimitiveType t, P p); |
aoqi@0 | 101 | |
aoqi@0 | 102 | /** |
aoqi@0 | 103 | * Visits the null type. |
aoqi@0 | 104 | * @param t the type to visit |
aoqi@0 | 105 | * @param p a visitor-specified parameter |
aoqi@0 | 106 | * @return a visitor-specified result |
aoqi@0 | 107 | */ |
aoqi@0 | 108 | R visitNull(NullType t, P p); |
aoqi@0 | 109 | |
aoqi@0 | 110 | /** |
aoqi@0 | 111 | * Visits an array type. |
aoqi@0 | 112 | * @param t the type to visit |
aoqi@0 | 113 | * @param p a visitor-specified parameter |
aoqi@0 | 114 | * @return a visitor-specified result |
aoqi@0 | 115 | */ |
aoqi@0 | 116 | R visitArray(ArrayType t, P p); |
aoqi@0 | 117 | |
aoqi@0 | 118 | /** |
aoqi@0 | 119 | * Visits a declared type. |
aoqi@0 | 120 | * @param t the type to visit |
aoqi@0 | 121 | * @param p a visitor-specified parameter |
aoqi@0 | 122 | * @return a visitor-specified result |
aoqi@0 | 123 | */ |
aoqi@0 | 124 | R visitDeclared(DeclaredType t, P p); |
aoqi@0 | 125 | |
aoqi@0 | 126 | /** |
aoqi@0 | 127 | * Visits an error type. |
aoqi@0 | 128 | * @param t the type to visit |
aoqi@0 | 129 | * @param p a visitor-specified parameter |
aoqi@0 | 130 | * @return a visitor-specified result |
aoqi@0 | 131 | */ |
aoqi@0 | 132 | R visitError(ErrorType t, P p); |
aoqi@0 | 133 | |
aoqi@0 | 134 | /** |
aoqi@0 | 135 | * Visits a type variable. |
aoqi@0 | 136 | * @param t the type to visit |
aoqi@0 | 137 | * @param p a visitor-specified parameter |
aoqi@0 | 138 | * @return a visitor-specified result |
aoqi@0 | 139 | */ |
aoqi@0 | 140 | R visitTypeVariable(TypeVariable t, P p); |
aoqi@0 | 141 | |
aoqi@0 | 142 | /** |
aoqi@0 | 143 | * Visits a wildcard type. |
aoqi@0 | 144 | * @param t the type to visit |
aoqi@0 | 145 | * @param p a visitor-specified parameter |
aoqi@0 | 146 | * @return a visitor-specified result |
aoqi@0 | 147 | */ |
aoqi@0 | 148 | R visitWildcard(WildcardType t, P p); |
aoqi@0 | 149 | |
aoqi@0 | 150 | /** |
aoqi@0 | 151 | * Visits an executable type. |
aoqi@0 | 152 | * @param t the type to visit |
aoqi@0 | 153 | * @param p a visitor-specified parameter |
aoqi@0 | 154 | * @return a visitor-specified result |
aoqi@0 | 155 | */ |
aoqi@0 | 156 | R visitExecutable(ExecutableType t, P p); |
aoqi@0 | 157 | |
aoqi@0 | 158 | /** |
aoqi@0 | 159 | * Visits a {@link NoType} instance. |
aoqi@0 | 160 | * @param t the type to visit |
aoqi@0 | 161 | * @param p a visitor-specified parameter |
aoqi@0 | 162 | * @return a visitor-specified result |
aoqi@0 | 163 | */ |
aoqi@0 | 164 | R visitNoType(NoType t, P p); |
aoqi@0 | 165 | |
aoqi@0 | 166 | /** |
aoqi@0 | 167 | * Visits an unknown kind of type. |
aoqi@0 | 168 | * This can occur if the language evolves and new kinds |
aoqi@0 | 169 | * of types are added to the {@code TypeMirror} hierarchy. |
aoqi@0 | 170 | * @param t the type to visit |
aoqi@0 | 171 | * @param p a visitor-specified parameter |
aoqi@0 | 172 | * @return a visitor-specified result |
aoqi@0 | 173 | * @throws UnknownTypeException |
aoqi@0 | 174 | * a visitor implementation may optionally throw this exception |
aoqi@0 | 175 | */ |
aoqi@0 | 176 | R visitUnknown(TypeMirror t, P p); |
aoqi@0 | 177 | |
aoqi@0 | 178 | /** |
aoqi@0 | 179 | * Visits a union type. |
aoqi@0 | 180 | * |
aoqi@0 | 181 | * @param t the type to visit |
aoqi@0 | 182 | * @param p a visitor-specified parameter |
aoqi@0 | 183 | * @return a visitor-specified result |
aoqi@0 | 184 | * @since 1.7 |
aoqi@0 | 185 | */ |
aoqi@0 | 186 | R visitUnion(UnionType t, P p); |
aoqi@0 | 187 | |
aoqi@0 | 188 | /** |
aoqi@0 | 189 | * Visits an intersection type. |
aoqi@0 | 190 | * |
aoqi@0 | 191 | * @param t the type to visit |
aoqi@0 | 192 | * @param p a visitor-specified parameter |
aoqi@0 | 193 | * @return a visitor-specified result |
aoqi@0 | 194 | * @since 1.8 |
aoqi@0 | 195 | */ |
aoqi@0 | 196 | R visitIntersection(IntersectionType t, P p); |
aoqi@0 | 197 | } |