test/tools/javac/annotations/typeAnnotations/newlocations/Receivers.java

changeset 1521
71f35e4b93a5
child 2424
7e97c65c373c
equal deleted inserted replaced
1520:5c956be64b9e 1521:71f35e4b93a5
1 /*
2 * Copyright (c) 2008, 2013, 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 import java.lang.annotation.*;
25
26 /*
27 * @test
28 * @bug 6843077 8006775
29 * @summary new type annotation location: receivers
30 * @author Mahmood Ali, Werner Dietl
31 * @compile Receivers.java
32 */
33 class DefaultUnmodified {
34 void plain(@A DefaultUnmodified this) { }
35 <T> void generic(@A DefaultUnmodified this) { }
36 void withException(@A DefaultUnmodified this) throws Exception { }
37 String nonVoid(@A DefaultUnmodified this) { return null; }
38 <T extends Runnable> void accept(@A DefaultUnmodified this, T r) throws Exception { }
39 }
40
41 class PublicModified {
42 public final void plain(@A PublicModified this) { }
43 public final <T> void generic(@A PublicModified this) { }
44 public final void withException(@A PublicModified this) throws Exception { }
45 public final String nonVoid(@A PublicModified this) { return null; }
46 public final <T extends Runnable> void accept(@A PublicModified this, T r) throws Exception { }
47 }
48
49 class WithValue {
50 void plain(@B("m") WithValue this) { }
51 <T> void generic(@B("m") WithValue this) { }
52 void withException(@B("m") WithValue this) throws Exception { }
53 String nonVoid(@B("m") WithValue this) { return null; }
54 <T extends Runnable> void accept(@B("m") WithValue this, T r) throws Exception { }
55 }
56
57 class WithFinal {
58 void plain(final @B("m") WithFinal this) { }
59 <T> void generic(final @B("m") WithFinal this) { }
60 void withException(final @B("m") WithFinal this) throws Exception { }
61 String nonVoid(final @B("m") WithFinal this) { return null; }
62 <T extends Runnable> void accept(final @B("m") WithFinal this, T r) throws Exception { }
63 }
64
65 class WithBody {
66 Object f;
67
68 void field(@A WithBody this) {
69 this.f = null;
70 }
71 void meth(@A WithBody this) {
72 this.toString();
73 }
74 }
75
76 class Generic1<X> {
77 void test1(Generic1<X> this) {}
78 void test2(@A Generic1<X> this) {}
79 void test3(Generic1<@A X> this) {}
80 void test4(@A Generic1<@A X> this) {}
81 }
82
83 class Generic2<@A X> {
84 void test1(Generic2<X> this) {}
85 void test2(@A Generic2<X> this) {}
86 void test3(Generic2<@A X> this) {}
87 void test4(@A Generic2<@A X> this) {}
88 }
89
90 class Generic3<X extends @A Object> {
91 void test1(Generic3<X> this) {}
92 void test2(@A Generic3<X> this) {}
93 void test3(Generic3<@A X> this) {}
94 void test4(@A Generic3<@A X> this) {}
95 }
96
97 class Generic4<X extends @A Object> {
98 <Y> void test1(Generic4<X> this) {}
99 <Y> void test2(@A Generic4<X> this) {}
100 <Y> void test3(Generic4<@A X> this) {}
101 <Y> void test4(@A Generic4<@A X> this) {}
102 }
103
104 class Outer {
105 class Inner {
106 void none(Outer.Inner this) {}
107 void outer(@A Outer.Inner this) {}
108 void inner(Outer. @B("i") Inner this) {}
109 void both(@A Outer.@B("i") Inner this) {}
110
111 void innerOnlyNone(Inner this) {}
112 void innerOnly(@A Inner this) {}
113 }
114 }
115
116 class GenericOuter<S, T> {
117 class GenericInner<U, V> {
118 void none(GenericOuter<S, T>.GenericInner<U, V> this) {}
119 void outer(@A GenericOuter<S, T>.GenericInner<U, V> this) {}
120 void inner(GenericOuter<S, T>. @B("i") GenericInner<U, V> this) {}
121 void both(@A GenericOuter<S, T>.@B("i") GenericInner<U, V> this) {}
122
123 void innerOnlyNone(GenericInner<U, V> this) {}
124 void innerOnly(@A GenericInner<U, V> this) {}
125 }
126 }
127
128 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
129 @interface A {}
130 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
131 @interface B { String value(); }

mercurial