1 /*
2  * Copyright (c) 2008, 2015, 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.
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 6843077 8006775 8031744
27  * @summary random tests for new locations
28  * @author Matt Papi
29  * @compile BasicTest.java
30  */
31 
32 import java.lang.annotation.*;
33 import java.util.*;
34 import java.io.*;
35 
36 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
37 @interface A {}
38 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
39 @interface B {}
40 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
41 @interface C {}
42 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
43 @interface D {}
44 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
45 @interface E {}
46 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
47 @interface F {}
48 
49 /**
50  * Tests basic JSR 308 parser functionality. We don't really care about what
51  * the parse tree looks like, just that these annotations can be parsed.
52  */
53 class BasicTest<@D T extends @A Object> extends @B LinkedList<@E T> implements @C List<@F T> {
54 
test()55     void test() {
56 
57         // Handle annotated cast types
58         Object o = (@A Object) "foo";
59 
60         // Handle annotated "new" expressions (except arrays; see ArrayTest)
61         String s = new @A String("bar");
62 
63         boolean b = o instanceof @A Object;
64 
65         @A Map<@B List<@C String>, @D String> map =
66             new @A HashMap<@B List<@C String>, @D String>();
67 
68         Class<? extends @A String> c2 = null;
69     }
70 
71     // Handle receiver annotations
72     // Handle annotations on a qualified identifier list
73     void test2(@C @D BasicTest<T> this) throws @A IllegalArgumentException, @B IOException {
74 
75     }
76 
77     // Handle annotations on a varargs element type
test3(@ Object @... objs)78     void test3(@B Object @A... objs) { }
79 
test4(@ Class<@C ?> @ .... clz)80     void test4(@B Class<@C ?> @A ... clz) { }
81 
82 
83     // TODO: add more tests... nested classes, etc.
84 }
85