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

Thu, 31 Jan 2013 12:16:03 -0800

author
darcy
date
Thu, 31 Jan 2013 12:16:03 -0800
changeset 1531
8e4c22acebeb
parent 1521
71f35e4b93a5
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8007313: Remove use of {ContainerFor/ContainedBy} from langtools
Reviewed-by: jjg

jjg@1521 1 /*
jjg@1521 2 * Copyright (c) 2012, 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 8006775
jjg@1521 29 * @summary repeating type annotations are possible
jjg@1521 30 * @author Werner Dietl
jjg@1521 31 * @compile/fail/ref=RepeatingTypeAnnotations.out -XDrawDiagnostics RepeatingTypeAnnotations.java
jjg@1521 32 */
jjg@1521 33
jjg@1521 34 class RepeatingTypeAnnotations {
jjg@1521 35 // Fields
jjg@1521 36 @RTA @RTA Object fr1 = null;
jjg@1521 37 Object fr2 = new @RTA @RTA Object();
jjg@1521 38 // error
jjg@1521 39 Object fs = new @TA @TA Object();
jjg@1521 40 // error
jjg@1521 41 Object ft = new @TA @TA Object();
jjg@1521 42 Object fe = new @TA @TA Object();
jjg@1521 43
jjg@1521 44 // Local variables
jjg@1521 45 Object foo() {
jjg@1521 46 Object o = new @RTA @RTA Object();
jjg@1521 47 o = new @TA @RTA @RTA Object();
jjg@1521 48 o = new @RTA @TA @RTA Object();
jjg@1521 49 // error
jjg@1521 50 o = new @RTA @TA @RTA @TA Object();
jjg@1521 51 // error
jjg@1521 52 return new @TA @TA Object();
jjg@1521 53 }
jjg@1521 54
jjg@1521 55 // Instance creation
jjg@1521 56 Object bar() {
jjg@1521 57 Object o = new @RTA @RTA MyList<@RTA @RTA Object>();
jjg@1521 58 o = new @TA @RTA MyList<@TA @RTA Object>();
jjg@1521 59 o = new @TA @RTA @RTA MyList<@RTA @TA @RTA Object>();
jjg@1521 60 // error
jjg@1521 61 o = new @TA @TA MyList<@RTA @RTA Object>();
jjg@1521 62 // error
jjg@1521 63 o = new @RTA @RTA MyList<@TA @TA Object>();
jjg@1521 64 // error
jjg@1521 65 return new @TA @TA MyList<@RTA @RTA Object>();
jjg@1521 66 }
jjg@1521 67
jjg@1521 68 // More tests
jjg@1521 69 void oneArg() {
jjg@1521 70 Object o = new @RTA @RTA Object();
jjg@1521 71 // error
jjg@1521 72 o = new @TA @TA Object();
jjg@1521 73 o = new @RTA @TA @RTA Object();
jjg@1521 74
jjg@1521 75 o = new MyList<@RTA @RTA Object>();
jjg@1521 76 // error
jjg@1521 77 o = new MyList<@TA @TA Object>();
jjg@1521 78 // error
jjg@1521 79 o = new @TA @TA MyList<@TA @TA Object>();
jjg@1521 80 // error
jjg@1521 81 this.<@TA @TA String>newList();
jjg@1521 82
jjg@1521 83 this.<@RTA @RTA MyList<@RTA @RTA String>>newList();
jjg@1521 84 // error
jjg@1521 85 this.<@TA @TA MyList<@TA @TA String>>newList();
jjg@1521 86
jjg@1521 87 o = (@RTA @RTA MyList<@RTA @RTA Object>) o;
jjg@1521 88 // error
jjg@1521 89 o = (@TA @TA MyList<@TA @TA Object>) o;
jjg@1521 90
jjg@1521 91 this.<@RTA @RTA String, @RTA @RTA Object>newMap();
jjg@1521 92 // error
jjg@1521 93 this.<@TA @TA String, @TA @TA Object>newMap();
jjg@1521 94
jjg@1521 95 this.<@RTA @RTA String @RTA @RTA []>newList();
jjg@1521 96 // error
jjg@1521 97 this.<@TA @TA String @TA @TA []>newList();
jjg@1521 98
jjg@1521 99 this.<@RTA @RTA String @RTA @RTA [] @RTA @RTA [], MyList<@RTA @RTA String> @RTA @RTA []>newMap();
jjg@1521 100 // error
jjg@1521 101 this.<String @TA @TA [] @TA @TA [], MyList<@TA @TA String> @TA @TA []>newMap();
jjg@1521 102 }
jjg@1521 103
jjg@1521 104 static <E> void newList() { }
jjg@1521 105 static <K, V> void newMap() { }
jjg@1521 106 }
jjg@1521 107
jjg@1521 108 class MyList<E> { }
jjg@1521 109
jjg@1521 110
jjg@1521 111 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
jjg@1521 112 @interface TA { }
jjg@1521 113
jjg@1521 114 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
jjg@1521 115 @interface TAs {
jjg@1521 116 TA[] value();
jjg@1521 117 }
jjg@1521 118
jjg@1521 119 @Repeatable(RTAs.class)
jjg@1521 120 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
jjg@1521 121 @interface RTA { }
jjg@1521 122
jjg@1521 123 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
jjg@1521 124 @interface RTAs {
jjg@1521 125 RTA[] value();
jjg@1521 126 }

mercurial