1 /* 2 * Copyright (c) 2005, 2020, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.lang.model.util; 27 28 import javax.annotation.processing.SupportedSourceVersion; 29 import javax.lang.model.type.*; 30 31 import static javax.lang.model.SourceVersion.*; 32 33 /** 34 * A skeletal visitor of types with default behavior appropriate for 35 * the {@link javax.lang.model.SourceVersion#RELEASE_6 RELEASE_6} 36 * source version. 37 * 38 * @apiNote 39 * <p id=note_for_subclasses><strong>WARNING:</strong> The {@code 40 * TypeVisitor} interface implemented by this class may have methods 41 * added to it in the future to accommodate new, currently unknown, 42 * language structures added to future versions of the Java™ 43 * programming language. Therefore, methods whose names begin with 44 * {@code "visit"} may be added to this class in the future; to avoid 45 * incompatibilities, classes and subclasses which extend this class 46 * should not declare any instance methods with names beginning with 47 * {@code "visit"}. 48 * 49 * <p>When such a new visit method is added, the default 50 * implementation in this class will be to directly or indirectly call 51 * the {@link #visitUnknown visitUnknown} method. A new abstract type 52 * visitor class will also be introduced to correspond to the new 53 * language level; this visitor will have different default behavior 54 * for the visit method in question. When a new visitor is 55 * introduced, portions of this visitor class may be deprecated, 56 * including its constructors. 57 * 58 * @param <R> the return type of this visitor's methods. Use {@link 59 * Void} for visitors that do not need to return results. 60 * @param <P> the type of the additional parameter to this visitor's 61 * methods. Use {@code Void} for visitors that do not need an 62 * additional parameter. 63 * 64 * @author Joseph D. Darcy 65 * @author Scott Seligman 66 * @author Peter von der Ahé 67 * 68 * @see AbstractTypeVisitor7 69 * @see AbstractTypeVisitor8 70 * @see AbstractTypeVisitor9 71 * @see AbstractTypeVisitor14 72 * @since 1.6 73 */ 74 @SupportedSourceVersion(RELEASE_6) 75 public abstract class AbstractTypeVisitor6<R, P> implements TypeVisitor<R, P> { 76 /** 77 * Constructor for concrete subclasses to call. 78 * @deprecated Release 6 is obsolete; update to a visitor for a newer 79 * release level. 80 */ 81 @Deprecated(since="9") 82 protected AbstractTypeVisitor6() {} 83 84 /** 85 * Visits any type mirror as if by passing itself to that type 86 * mirror's {@link TypeMirror#accept accept} method. The 87 * invocation {@code v.visit(t, p)} is equivalent to {@code 88 * t.accept(v, p)}. 89 * 90 * @param t the type to visit 91 * @param p a visitor-specified parameter 92 * @return a visitor-specified result 93 */ 94 public final R visit(TypeMirror t, P p) { 95 return t.accept(this, p); 96 } 97 98 /** 99 * Visits any type mirror as if by passing itself to that type 100 * mirror's {@link TypeMirror#accept accept} method and passing 101 * {@code null} for the additional parameter. The invocation 102 * {@code v.visit(t)} is equivalent to {@code t.accept(v, null)}. 103 * 104 * @param t the type to visit 105 * @return a visitor-specified result 106 */ 107 public final R visit(TypeMirror t) { 108 return t.accept(this, null); 109 } 110 111 /** 112 * {@inheritDoc} 113 * 114 * @implSpec Visits a {@code UnionType} element by calling {@code 115 * visitUnknown}. 116 * 117 * @param t {@inheritDoc} 118 * @param p {@inheritDoc} 119 * @return the result of {@code visitUnknown} 120 * 121 * @since 1.7 122 */ 123 public R visitUnion(UnionType t, P p) { 124 return visitUnknown(t, p); 125 } 126 127 /** 128 * {@inheritDoc} 129 * 130 * @implSpec Visits an {@code IntersectionType} element by calling {@code 131 * visitUnknown}. 132 * 133 * @param t {@inheritDoc} 134 * @param p {@inheritDoc} 135 * @return the result of {@code visitUnknown} 136 * 137 * @since 1.8 138 */ 139 @Override 140 public R visitIntersection(IntersectionType t, P p) { 141 return visitUnknown(t, p); 142 } 143 144 /** 145 * {@inheritDoc} 146 * 147 * @implSpec The default implementation of this method in {@code 148 * AbstractTypeVisitor6} will always throw {@code 149 * new UnknownTypeException(t, p)}. This behavior is not required of a 150 * subclass. 151 * 152 * @param t {@inheritDoc} 153 * @param p {@inheritDoc} 154 * @return a visitor-specified result 155 * @throws UnknownTypeException 156 * a visitor implementation may optionally throw this exception 157 */ 158 @Override 159 public R visitUnknown(TypeMirror t, P p) { 160 throw new UnknownTypeException(t, p); 161 } 162 }