Mon, 13 Dec 2010 14:56:50 +0000
7006109: Add test library to simplify the task of writing automated type-system tests
Summary: Types.java needs to be more stress-tested
Reviewed-by: jjg
2 /*
3 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
25 /*
26 * @test
27 * @bug 6843077
28 * @summary random tests for new locations
29 * @author Matt Papi
30 * @compile/fail/ref=BasicTest.out -XDrawDiagnostics BasicTest.java
31 */
33 import java.util.*;
34 import java.io.*;
36 @interface A {}
37 @interface B {}
38 @interface C {}
39 @interface D {}
41 //308: Test inverted to verify that type annotations can not be parsed yet.
43 /**
44 * Tests basic JSR 308 parser functionality. We don't really care about what
45 * the parse tree looks like, just that these annotations can be parsed.
46 */
47 class BasicTest<T extends @A Object> extends @B LinkedList<T> implements @C List<T> {
49 void test() {
51 // Handle annotated class literals/cast types
52 Class<?> c = @A String.class;
53 Object o = (@A Object) "foo";
55 // Handle annotated "new" expressions (except arrays; see ArrayTest)
56 String s = new @A String("bar");
58 boolean b = o instanceof @A Object;
61 @A Map<@B List<@C String>, @D String> map =
62 new @A HashMap<@B List<@C String>, @D String>();
64 Class<? extends @A String> c2 = @A String.class;
65 }
67 // Handle receiver annotations
68 // Handle annotations on a qualified identifier list
69 void test2() @C @D throws @A IllegalArgumentException, @B IOException {
71 }
73 // Handle annotations on a varargs element type
74 void test3(Object @A... objs) {
76 }
77 }