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 {
plain(@ DefaultUnmodified this)34   void plain(@A DefaultUnmodified this) { }
generic(@ DefaultUnmodified this)35   <T> void generic(@A DefaultUnmodified this) { }
withException(@ DefaultUnmodified this)36   void withException(@A DefaultUnmodified this) throws Exception { }
nonVoid(@ DefaultUnmodified this)37   String nonVoid(@A DefaultUnmodified this) { return null; }
accept(@ DefaultUnmodified this, T r)38   <T extends Runnable> void accept(@A DefaultUnmodified this, T r) throws Exception { }
39 }
40 
41 class PublicModified {
plain(@ PublicModified this)42   public final void plain(@A PublicModified this) { }
generic(@ PublicModified this)43   public final <T> void generic(@A PublicModified this) { }
withException(@ PublicModified this)44   public final void withException(@A PublicModified this) throws Exception { }
nonVoid(@ PublicModified this)45   public final String nonVoid(@A PublicModified this) { return null; }
accept(@ PublicModified this, T r)46   public final <T extends Runnable> void accept(@A PublicModified this, T r) throws Exception { }
47 }
48 
49 class WithValue {
plain(@R) WithValue this)50   void plain(@B("m") WithValue this) { }
generic(@R) WithValue this)51   <T> void generic(@B("m") WithValue this) { }
withException(@R) WithValue this)52   void withException(@B("m") WithValue this) throws Exception { }
nonVoid(@R) WithValue this)53   String nonVoid(@B("m") WithValue this) { return null; }
accept(@R) WithValue this, T r)54   <T extends Runnable> void accept(@B("m") WithValue this, T r) throws Exception { }
55 }
56 
57 class WithBody {
58   Object f;
59 
field(@ WithBody this)60   void field(@A WithBody this) {
61     this.f = null;
62   }
meth(@ WithBody this)63   void meth(@A WithBody this) {
64     this.toString();
65   }
66 }
67 
68 class Generic1<X> {
test1(Generic1<X> this)69   void test1(Generic1<X> this) {}
test2(@ Generic1<X> this)70   void test2(@A Generic1<X> this) {}
test3(Generic1<@A X> this)71   void test3(Generic1<@A X> this) {}
test4(@ Generic1<@A X> this)72   void test4(@A Generic1<@A X> this) {}
73 }
74 
75 class Generic2<@A X> {
test1(Generic2<X> this)76   void test1(Generic2<X> this) {}
test2(@ Generic2<X> this)77   void test2(@A Generic2<X> this) {}
test3(Generic2<@A X> this)78   void test3(Generic2<@A X> this) {}
test4(@ Generic2<@A X> this)79   void test4(@A Generic2<@A X> this) {}
80 }
81 
82 class Generic3<X extends @A Object> {
test1(Generic3<X> this)83   void test1(Generic3<X> this) {}
test2(@ Generic3<X> this)84   void test2(@A Generic3<X> this) {}
test3(Generic3<@A X> this)85   void test3(Generic3<@A X> this) {}
test4(@ Generic3<@A X> this)86   void test4(@A Generic3<@A X> this) {}
87 }
88 
89 class Generic4<X extends @A Object> {
test1(Generic4<X> this)90   <Y> void test1(Generic4<X> this) {}
test2(@ Generic4<X> this)91   <Y> void test2(@A Generic4<X> this) {}
test3(Generic4<@A X> this)92   <Y> void test3(Generic4<@A X> this) {}
test4(@ Generic4<@A X> this)93   <Y> void test4(@A Generic4<@A X> this) {}
94 }
95 
96 class Outer {
97   class Inner {
none(Outer.Inner this)98     void none(Outer.Inner this) {}
outer(@ Outer.Inner this)99     void outer(@A Outer.Inner this) {}
inner(Outer. @R) Inner this)100     void inner(Outer. @B("i") Inner this) {}
both(@ Outer.@R) Inner this)101     void both(@A Outer.@B("i") Inner this) {}
102 
innerOnlyNone(Inner this)103     void innerOnlyNone(Inner this) {}
innerOnly(@ Inner this)104     void innerOnly(@A Inner this) {}
105   }
106 }
107 
108 class GenericOuter<S, T> {
109   class GenericInner<U, V> {
none(GenericOuter<S, T>.GenericInner<U, V> this)110     void none(GenericOuter<S, T>.GenericInner<U, V> this) {}
outer(@ GenericOuter<S, T>.GenericInner<U, V> this)111     void outer(@A GenericOuter<S, T>.GenericInner<U, V> this) {}
inner(GenericOuter<S, T>. @B(R) GenericInner<U, V> this)112     void inner(GenericOuter<S, T>. @B("i") GenericInner<U, V> this) {}
both(@ GenericOuter<S, T>.@B(R) GenericInner<U, V> this)113     void both(@A GenericOuter<S, T>.@B("i") GenericInner<U, V> this) {}
114 
innerOnlyNone(GenericInner<U, V> this)115     void innerOnlyNone(GenericInner<U, V> this) {}
innerOnly(@ GenericInner<U, V> this)116     void innerOnly(@A GenericInner<U, V> this) {}
117   }
118 }
119 
120 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
121 @interface A {}
122 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
value()123 @interface B { String value(); }
124