Thu, 07 Nov 2013 20:11:56 -0800
8027730: Fix release-8 type visitors to support intersection types
Reviewed-by: jjg, jlahoda, sogoel
1.1 --- a/src/share/classes/javax/lang/model/util/SimpleTypeVisitor8.java Wed Nov 06 17:48:25 2013 +0100 1.2 +++ b/src/share/classes/javax/lang/model/util/SimpleTypeVisitor8.java Thu Nov 07 20:11:56 2013 -0800 1.3 @@ -27,6 +27,7 @@ 1.4 1.5 import javax.annotation.processing.SupportedSourceVersion; 1.6 import javax.lang.model.SourceVersion; 1.7 +import javax.lang.model.type.IntersectionType; 1.8 import static javax.lang.model.SourceVersion.*; 1.9 1.10 /** 1.11 @@ -98,4 +99,17 @@ 1.12 protected SimpleTypeVisitor8(R defaultValue){ 1.13 super(defaultValue); 1.14 } 1.15 + 1.16 + /** 1.17 + * This implementation visits an {@code IntersectionType} by calling 1.18 + * {@code defaultAction}. 1.19 + * 1.20 + * @param t {@inheritDoc} 1.21 + * @param p {@inheritDoc} 1.22 + * @return the result of {@code defaultAction} 1.23 + */ 1.24 + @Override 1.25 + public R visitIntersection(IntersectionType t, P p){ 1.26 + return defaultAction(t, p); 1.27 + } 1.28 }
2.1 --- a/src/share/classes/javax/lang/model/util/TypeKindVisitor8.java Wed Nov 06 17:48:25 2013 +0100 2.2 +++ b/src/share/classes/javax/lang/model/util/TypeKindVisitor8.java Thu Nov 07 20:11:56 2013 -0800 2.3 @@ -101,4 +101,17 @@ 2.4 protected TypeKindVisitor8(R defaultValue) { 2.5 super(defaultValue); 2.6 } 2.7 + 2.8 + /** 2.9 + * This implementation visits an {@code IntersectionType} by calling 2.10 + * {@code defaultAction}. 2.11 + * 2.12 + * @param t {@inheritDoc} 2.13 + * @param p {@inheritDoc} 2.14 + * @return the result of {@code defaultAction} 2.15 + */ 2.16 + @Override 2.17 + public R visitIntersection(IntersectionType t, P p) { 2.18 + return defaultAction(t, p); 2.19 + } 2.20 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/processing/model/util/TestIntersectionTypeVisitors.java Thu Nov 07 20:11:56 2013 -0800 3.3 @@ -0,0 +1,122 @@ 3.4 +/* 3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 8027730 3.30 + * @summary Test visitor support for intersection types 3.31 + */ 3.32 + 3.33 +import java.lang.annotation.Annotation; 3.34 +import java.util.List; 3.35 +import javax.lang.model.element.*; 3.36 +import javax.lang.model.type.*; 3.37 +import javax.lang.model.util.*; 3.38 + 3.39 +public class TestIntersectionTypeVisitors { 3.40 + public static void main(String... args) throws Exception { 3.41 + IntersectionType it = new TestIntersectionType(); 3.42 + 3.43 + boolean result = it.accept(new TypeKindVisitor8Child(), null) && 3.44 + it.accept(new SimpleTypeVisitor8Child(), null) && 3.45 + it.accept(new SimpleTypeVisitor6Child(), null); 3.46 + 3.47 + if (!result) 3.48 + throw new RuntimeException(); 3.49 + } 3.50 + 3.51 + static class TestIntersectionType implements IntersectionType { 3.52 + TestIntersectionType() {} 3.53 + 3.54 + @Override 3.55 + public List<? extends TypeMirror> getBounds() { 3.56 + throw new UnsupportedOperationException(); 3.57 + } 3.58 + 3.59 + @Override 3.60 + public <R,P> R accept(TypeVisitor<R,P> v, 3.61 + P p) { 3.62 + return v.visitIntersection(this, p); 3.63 + } 3.64 + 3.65 + @Override 3.66 + public TypeKind getKind() { 3.67 + return TypeKind.INTERSECTION; 3.68 + } 3.69 + 3.70 + @Override 3.71 + public <A extends Annotation> A getAnnotation(Class<A> annotationType) { 3.72 + throw new UnsupportedOperationException(); 3.73 + } 3.74 + 3.75 + @Override 3.76 + public List<? extends AnnotationMirror> getAnnotationMirrors() { 3.77 + throw new UnsupportedOperationException(); 3.78 + } 3.79 + 3.80 + @Override 3.81 + public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) { 3.82 + throw new UnsupportedOperationException(); 3.83 + } 3.84 + } 3.85 + 3.86 + static class TypeKindVisitor8Child extends TypeKindVisitor8<Boolean, Void> { 3.87 + TypeKindVisitor8Child() { 3.88 + super(false); 3.89 + } 3.90 + 3.91 + @Override 3.92 + public Boolean visitIntersection(IntersectionType t, Void p) { 3.93 + super.visitIntersection(t, p); // Make sure overridden method doesn't throw an exception 3.94 + return true; 3.95 + } 3.96 + } 3.97 + 3.98 + static class SimpleTypeVisitor8Child extends SimpleTypeVisitor8<Boolean, Void> { 3.99 + SimpleTypeVisitor8Child() { 3.100 + super(false); 3.101 + } 3.102 + 3.103 + @Override 3.104 + public Boolean visitIntersection(IntersectionType t, Void p) { 3.105 + super.visitIntersection(t, p); // Make sure overridden method doesn't throw an exception 3.106 + return true; 3.107 + } 3.108 + } 3.109 + 3.110 + static class SimpleTypeVisitor6Child extends SimpleTypeVisitor6<Boolean, Void> { 3.111 + SimpleTypeVisitor6Child() { 3.112 + super(false); 3.113 + } 3.114 + 3.115 + @Override 3.116 + public Boolean visitIntersection(IntersectionType t, Void p) { 3.117 + try { 3.118 + super.visitIntersection(t, p); 3.119 + return false; 3.120 + } catch (UnknownTypeException ute) { 3.121 + return true; // Expected 3.122 + } 3.123 + } 3.124 + } 3.125 +}