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

Wed, 18 Jun 2014 12:30:29 -0400

author
pgovereau
date
Wed, 18 Jun 2014 12:30:29 -0400
changeset 2424
7e97c65c373c
parent 1521
71f35e4b93a5
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8027886: javac allows illegal receiver parameters
8029042: Receiver parameter not supported on local class constructor
Reviewed-by: jfranck, jlahoda

jjg@1521 1 /*
jjg@1521 2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
jjg@1521 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1521 4 *
jjg@1521 5 * This code is free software; you can redistribute it and/or modify it
jjg@1521 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1521 7 * published by the Free Software Foundation.
jjg@1521 8 *
jjg@1521 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1521 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1521 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1521 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1521 13 * accompanied this code).
jjg@1521 14 *
jjg@1521 15 * You should have received a copy of the GNU General Public License version
jjg@1521 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1521 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1521 18 *
jjg@1521 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1521 20 * or visit www.oracle.com if you need additional information or have any
jjg@1521 21 * questions.
jjg@1521 22 */
jjg@1521 23
jjg@1521 24 import java.lang.annotation.*;
jjg@1521 25
jjg@1521 26 /*
jjg@1521 27 * @test
jjg@1521 28 * @bug 6843077 8006775
jjg@1521 29 * @summary new type annotation location: receivers
jjg@1521 30 * @author Mahmood Ali, Werner Dietl
jjg@1521 31 * @compile Receivers.java
jjg@1521 32 */
jjg@1521 33 class DefaultUnmodified {
jjg@1521 34 void plain(@A DefaultUnmodified this) { }
jjg@1521 35 <T> void generic(@A DefaultUnmodified this) { }
jjg@1521 36 void withException(@A DefaultUnmodified this) throws Exception { }
jjg@1521 37 String nonVoid(@A DefaultUnmodified this) { return null; }
jjg@1521 38 <T extends Runnable> void accept(@A DefaultUnmodified this, T r) throws Exception { }
jjg@1521 39 }
jjg@1521 40
jjg@1521 41 class PublicModified {
jjg@1521 42 public final void plain(@A PublicModified this) { }
jjg@1521 43 public final <T> void generic(@A PublicModified this) { }
jjg@1521 44 public final void withException(@A PublicModified this) throws Exception { }
jjg@1521 45 public final String nonVoid(@A PublicModified this) { return null; }
jjg@1521 46 public final <T extends Runnable> void accept(@A PublicModified this, T r) throws Exception { }
jjg@1521 47 }
jjg@1521 48
jjg@1521 49 class WithValue {
jjg@1521 50 void plain(@B("m") WithValue this) { }
jjg@1521 51 <T> void generic(@B("m") WithValue this) { }
jjg@1521 52 void withException(@B("m") WithValue this) throws Exception { }
jjg@1521 53 String nonVoid(@B("m") WithValue this) { return null; }
jjg@1521 54 <T extends Runnable> void accept(@B("m") WithValue this, T r) throws Exception { }
jjg@1521 55 }
jjg@1521 56
jjg@1521 57 class WithBody {
jjg@1521 58 Object f;
jjg@1521 59
jjg@1521 60 void field(@A WithBody this) {
jjg@1521 61 this.f = null;
jjg@1521 62 }
jjg@1521 63 void meth(@A WithBody this) {
jjg@1521 64 this.toString();
jjg@1521 65 }
jjg@1521 66 }
jjg@1521 67
jjg@1521 68 class Generic1<X> {
jjg@1521 69 void test1(Generic1<X> this) {}
jjg@1521 70 void test2(@A Generic1<X> this) {}
jjg@1521 71 void test3(Generic1<@A X> this) {}
jjg@1521 72 void test4(@A Generic1<@A X> this) {}
jjg@1521 73 }
jjg@1521 74
jjg@1521 75 class Generic2<@A X> {
jjg@1521 76 void test1(Generic2<X> this) {}
jjg@1521 77 void test2(@A Generic2<X> this) {}
jjg@1521 78 void test3(Generic2<@A X> this) {}
jjg@1521 79 void test4(@A Generic2<@A X> this) {}
jjg@1521 80 }
jjg@1521 81
jjg@1521 82 class Generic3<X extends @A Object> {
jjg@1521 83 void test1(Generic3<X> this) {}
jjg@1521 84 void test2(@A Generic3<X> this) {}
jjg@1521 85 void test3(Generic3<@A X> this) {}
jjg@1521 86 void test4(@A Generic3<@A X> this) {}
jjg@1521 87 }
jjg@1521 88
jjg@1521 89 class Generic4<X extends @A Object> {
jjg@1521 90 <Y> void test1(Generic4<X> this) {}
jjg@1521 91 <Y> void test2(@A Generic4<X> this) {}
jjg@1521 92 <Y> void test3(Generic4<@A X> this) {}
jjg@1521 93 <Y> void test4(@A Generic4<@A X> this) {}
jjg@1521 94 }
jjg@1521 95
jjg@1521 96 class Outer {
jjg@1521 97 class Inner {
jjg@1521 98 void none(Outer.Inner this) {}
jjg@1521 99 void outer(@A Outer.Inner this) {}
jjg@1521 100 void inner(Outer. @B("i") Inner this) {}
jjg@1521 101 void both(@A Outer.@B("i") Inner this) {}
jjg@1521 102
jjg@1521 103 void innerOnlyNone(Inner this) {}
jjg@1521 104 void innerOnly(@A Inner this) {}
jjg@1521 105 }
jjg@1521 106 }
jjg@1521 107
jjg@1521 108 class GenericOuter<S, T> {
jjg@1521 109 class GenericInner<U, V> {
jjg@1521 110 void none(GenericOuter<S, T>.GenericInner<U, V> this) {}
jjg@1521 111 void outer(@A GenericOuter<S, T>.GenericInner<U, V> this) {}
jjg@1521 112 void inner(GenericOuter<S, T>. @B("i") GenericInner<U, V> this) {}
jjg@1521 113 void both(@A GenericOuter<S, T>.@B("i") GenericInner<U, V> this) {}
jjg@1521 114
jjg@1521 115 void innerOnlyNone(GenericInner<U, V> this) {}
jjg@1521 116 void innerOnly(@A GenericInner<U, V> this) {}
jjg@1521 117 }
jjg@1521 118 }
jjg@1521 119
jjg@1521 120 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
jjg@1521 121 @interface A {}
jjg@1521 122 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
jjg@1521 123 @interface B { String value(); }

mercurial