Wed, 23 Jan 2013 13:27:24 -0800
8006775: JSR 308: Compiler changes in JDK8
Reviewed-by: jjg
Contributed-by: mernst@cs.washington.edu, wmdietl@cs.washington.edu, mpapi@csail.mit.edu, mahmood@notnoop.com
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.util; |
duke@1 | 27 | |
duke@1 | 28 | import javax.lang.model.type.*; |
duke@1 | 29 | |
duke@1 | 30 | /** |
duke@1 | 31 | * A skeletal visitor of types with default behavior appropriate for |
darcy@851 | 32 | * the {@link javax.lang.model.SourceVersion#RELEASE_6 RELEASE_6} |
darcy@851 | 33 | * source version. |
duke@1 | 34 | * |
duke@1 | 35 | * <p> <b>WARNING:</b> The {@code TypeVisitor} interface implemented |
duke@1 | 36 | * by this class may have methods added to it in the future to |
duke@1 | 37 | * accommodate new, currently unknown, language structures added to |
duke@1 | 38 | * future versions of the Java™ programming language. |
duke@1 | 39 | * Therefore, methods whose names begin with {@code "visit"} may be |
duke@1 | 40 | * added to this class in the future; to avoid incompatibilities, |
duke@1 | 41 | * classes which extend this class should not declare any instance |
duke@1 | 42 | * methods with names beginning with {@code "visit"}. |
duke@1 | 43 | * |
duke@1 | 44 | * <p>When such a new visit method is added, the default |
duke@1 | 45 | * implementation in this class will be to call the {@link |
duke@1 | 46 | * #visitUnknown visitUnknown} method. A new abstract type visitor |
duke@1 | 47 | * class will also be introduced to correspond to the new language |
duke@1 | 48 | * level; this visitor will have different default behavior for the |
duke@1 | 49 | * visit method in question. When the new visitor is introduced, all |
duke@1 | 50 | * or portions of this visitor may be deprecated. |
duke@1 | 51 | * |
duke@1 | 52 | * @param <R> the return type of this visitor's methods. Use {@link |
duke@1 | 53 | * Void} for visitors that do not need to return results. |
duke@1 | 54 | * @param <P> the type of the additional parameter to this visitor's |
duke@1 | 55 | * methods. Use {@code Void} for visitors that do not need an |
duke@1 | 56 | * additional parameter. |
duke@1 | 57 | * |
duke@1 | 58 | * @author Joseph D. Darcy |
duke@1 | 59 | * @author Scott Seligman |
duke@1 | 60 | * @author Peter von der Ahé |
darcy@575 | 61 | * |
darcy@575 | 62 | * @see AbstractTypeVisitor7 |
darcy@1054 | 63 | * @see AbstractTypeVisitor8 |
duke@1 | 64 | * @since 1.6 |
duke@1 | 65 | */ |
duke@1 | 66 | public abstract class AbstractTypeVisitor6<R, P> implements TypeVisitor<R, P> { |
duke@1 | 67 | /** |
duke@1 | 68 | * Constructor for concrete subclasses to call. |
duke@1 | 69 | */ |
duke@1 | 70 | protected AbstractTypeVisitor6() {} |
duke@1 | 71 | |
duke@1 | 72 | /** |
duke@1 | 73 | * Visits any type mirror as if by passing itself to that type |
duke@1 | 74 | * mirror's {@link TypeMirror#accept accept} method. The |
duke@1 | 75 | * invocation {@code v.visit(t, p)} is equivalent to {@code |
duke@1 | 76 | * t.accept(v, p)}. |
duke@1 | 77 | * |
duke@1 | 78 | * @param t the type to visit |
duke@1 | 79 | * @param p a visitor-specified parameter |
duke@1 | 80 | * @return a visitor-specified result |
duke@1 | 81 | */ |
duke@1 | 82 | public final R visit(TypeMirror t, P p) { |
duke@1 | 83 | return t.accept(this, p); |
duke@1 | 84 | } |
duke@1 | 85 | |
duke@1 | 86 | /** |
duke@1 | 87 | * Visits any type mirror as if by passing itself to that type |
duke@1 | 88 | * mirror's {@link TypeMirror#accept accept} method and passing |
duke@1 | 89 | * {@code null} for the additional parameter. The invocation |
duke@1 | 90 | * {@code v.visit(t)} is equivalent to {@code t.accept(v, null)}. |
duke@1 | 91 | * |
duke@1 | 92 | * @param t the type to visit |
duke@1 | 93 | * @return a visitor-specified result |
duke@1 | 94 | */ |
duke@1 | 95 | public final R visit(TypeMirror t) { |
duke@1 | 96 | return t.accept(this, null); |
duke@1 | 97 | } |
duke@1 | 98 | |
duke@1 | 99 | /** |
darcy@969 | 100 | * Visits a {@code UnionType} element by calling {@code |
darcy@851 | 101 | * visitUnknown}. |
darcy@851 | 102 | |
darcy@851 | 103 | * @param t {@inheritDoc} |
darcy@851 | 104 | * @param p {@inheritDoc} |
darcy@851 | 105 | * @return the result of {@code visitUnknown} |
darcy@851 | 106 | * |
darcy@851 | 107 | * @since 1.7 |
darcy@851 | 108 | */ |
darcy@969 | 109 | public R visitUnion(UnionType t, P p) { |
darcy@851 | 110 | return visitUnknown(t, p); |
darcy@851 | 111 | } |
darcy@851 | 112 | |
darcy@851 | 113 | /** |
mcimadamore@1436 | 114 | * Visits an {@code IntersectionType} element by calling {@code |
mcimadamore@1436 | 115 | * visitUnknown}. |
mcimadamore@1436 | 116 | |
mcimadamore@1436 | 117 | * @param t {@inheritDoc} |
mcimadamore@1436 | 118 | * @param p {@inheritDoc} |
mcimadamore@1436 | 119 | * @return the result of {@code visitUnknown} |
mcimadamore@1436 | 120 | * |
mcimadamore@1436 | 121 | * @since 1.8 |
mcimadamore@1436 | 122 | */ |
mcimadamore@1436 | 123 | public R visitIntersection(IntersectionType t, P p) { |
mcimadamore@1436 | 124 | return visitUnknown(t, p); |
mcimadamore@1436 | 125 | } |
mcimadamore@1436 | 126 | |
mcimadamore@1436 | 127 | /** |
jjg@1521 | 128 | * Visits an {@code AnnotatedType} element by calling {@code |
jjg@1521 | 129 | * visit} on the underlying type. |
jjg@1521 | 130 | |
jjg@1521 | 131 | * @param t {@inheritDoc} |
jjg@1521 | 132 | * @param p {@inheritDoc} |
jjg@1521 | 133 | * @return the result of calling {@code visit} on the underlying type |
jjg@1521 | 134 | * |
jjg@1521 | 135 | * @since 1.8 |
jjg@1521 | 136 | * |
jjg@1521 | 137 | * TODO: should xxxVisitor8 subclasses override this and call |
jjg@1521 | 138 | * the defaultAction? |
jjg@1521 | 139 | */ |
jjg@1521 | 140 | public R visitAnnotated(AnnotatedType t, P p) { |
jjg@1521 | 141 | return visit(t.getUnderlyingType(), p); |
jjg@1521 | 142 | } |
jjg@1521 | 143 | |
jjg@1521 | 144 | /** |
duke@1 | 145 | * {@inheritDoc} |
duke@1 | 146 | * |
duke@1 | 147 | * <p> The default implementation of this method in {@code |
duke@1 | 148 | * AbstractTypeVisitor6} will always throw {@code |
duke@1 | 149 | * UnknownTypeException}. This behavior is not required of a |
duke@1 | 150 | * subclass. |
duke@1 | 151 | * |
duke@1 | 152 | * @param t the type to visit |
duke@1 | 153 | * @return a visitor-specified result |
duke@1 | 154 | * @throws UnknownTypeException |
duke@1 | 155 | * a visitor implementation may optionally throw this exception |
duke@1 | 156 | */ |
duke@1 | 157 | public R visitUnknown(TypeMirror t, P p) { |
duke@1 | 158 | throw new UnknownTypeException(t, p); |
duke@1 | 159 | } |
duke@1 | 160 | } |