6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6993963
27 * @summary Project Coin: Use precise exception analysis for effectively final catch parameters
28 * @library ../../lib
29 * @build JavacTestingAbstractProcessor ModelChecker
30 * @compile -processor ModelChecker Model01.java
31 */
32
33 import com.sun.source.tree.CatchTree;
34 import com.sun.source.util.TreePathScanner;
35 import com.sun.source.util.Trees;
36 import com.sun.source.util.TreePath;
37
38 import java.util.Set;
39 import javax.annotation.processing.RoundEnvironment;
40 import javax.annotation.processing.SupportedAnnotationTypes;
41 import javax.lang.model.element.Element;
42 import javax.lang.model.element.ElementKind;
43 import javax.lang.model.element.TypeElement;
44 import javax.lang.model.type.TypeMirror;
45 import javax.lang.model.type.TypeKind;
46 import javax.lang.model.type.UnionType;
90 assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
91 }
92 return super.visitCatch(node, p);
93 }
94 }
95
96 private void validateUnionTypeInfo(Element ex) {
97 UnionTypeInfo ut = ex.getAnnotation(UnionTypeInfo.class);
98 assertTrue(ut != null, "UnionType annotation must be present");
99
100 TypeMirror expectedUnionType = ex.asType();
101 assertTrue(expectedUnionType.getKind() == TypeKind.UNION, "UNION kind expected");
102
103 try {
104 new SimpleTypeVisitor6<Void, Void>(){}.visit(expectedUnionType);
105 throw new RuntimeException("Expected UnknownTypeException not thrown.");
106 } catch (UnknownTypeException ute) {
107 ; // Expected
108 }
109
110 UnionType unionType = new SimpleTypeVisitor7<UnionType, Void>(){
111 @Override
112 protected UnionType defaultAction(TypeMirror e, Void p) {return null;}
113
114 @Override
115 public UnionType visitUnion(UnionType t, Void p) {return t;}
116 }.visit(expectedUnionType);
117 assertTrue(unionType != null, "Must get a non-null union type.");
118
119 assertTrue(ut.value().length == unionType.getAlternatives().size(), "Cardinalities do not match");
120
121 String[] typeNames = ut.value();
122 for(int i = 0; i < typeNames.length; i++) {
123 TypeMirror typeFromAnnotation = nameToType(typeNames[i]);
124 assertTrue(types.isSameType(typeFromAnnotation, unionType.getAlternatives().get(i)),
125 "Types were not equal.");
126 }
127 }
128
129 private TypeMirror nameToType(String name) {
130 return elements.getTypeElement(name).asType();
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6993963 7025809
27 * @summary Project Coin: Use precise exception analysis for effectively final catch parameters
28 * @library ../../lib
29 * @build JavacTestingAbstractProcessor ModelChecker
30 * @compile -processor ModelChecker Model01.java
31 */
32
33 import com.sun.source.tree.CatchTree;
34 import com.sun.source.util.TreePathScanner;
35 import com.sun.source.util.Trees;
36 import com.sun.source.util.TreePath;
37
38 import java.util.Set;
39 import javax.annotation.processing.RoundEnvironment;
40 import javax.annotation.processing.SupportedAnnotationTypes;
41 import javax.lang.model.element.Element;
42 import javax.lang.model.element.ElementKind;
43 import javax.lang.model.element.TypeElement;
44 import javax.lang.model.type.TypeMirror;
45 import javax.lang.model.type.TypeKind;
46 import javax.lang.model.type.UnionType;
90 assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
91 }
92 return super.visitCatch(node, p);
93 }
94 }
95
96 private void validateUnionTypeInfo(Element ex) {
97 UnionTypeInfo ut = ex.getAnnotation(UnionTypeInfo.class);
98 assertTrue(ut != null, "UnionType annotation must be present");
99
100 TypeMirror expectedUnionType = ex.asType();
101 assertTrue(expectedUnionType.getKind() == TypeKind.UNION, "UNION kind expected");
102
103 try {
104 new SimpleTypeVisitor6<Void, Void>(){}.visit(expectedUnionType);
105 throw new RuntimeException("Expected UnknownTypeException not thrown.");
106 } catch (UnknownTypeException ute) {
107 ; // Expected
108 }
109
110 UnionType unionType = new SimpleTypeVisitor<UnionType, Void>(){
111 @Override
112 protected UnionType defaultAction(TypeMirror e, Void p) {return null;}
113
114 @Override
115 public UnionType visitUnion(UnionType t, Void p) {return t;}
116 }.visit(expectedUnionType);
117 assertTrue(unionType != null, "Must get a non-null union type.");
118
119 assertTrue(ut.value().length == unionType.getAlternatives().size(), "Cardinalities do not match");
120
121 String[] typeNames = ut.value();
122 for(int i = 0; i < typeNames.length; i++) {
123 TypeMirror typeFromAnnotation = nameToType(typeNames[i]);
124 assertTrue(types.isSameType(typeFromAnnotation, unionType.getAlternatives().get(i)),
125 "Types were not equal.");
126 }
127 }
128
129 private TypeMirror nameToType(String name) {
130 return elements.getTypeElement(name).asType();
|