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