Fri, 02 Nov 2012 14:35:57 -0700
7169362: JDK8: Write compiler tests for repeating annotations for JDK8
Reviewed-by: darcy, jjg
Contributed-by: sonali.goel@oracle.com
jfranck@1313 | 1 | /* |
jfranck@1313 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
jfranck@1313 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jfranck@1313 | 4 | * |
jfranck@1313 | 5 | * This code is free software; you can redistribute it and/or modify it |
jfranck@1313 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jfranck@1313 | 7 | * published by the Free Software Foundation. |
jfranck@1313 | 8 | * |
jfranck@1313 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jfranck@1313 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jfranck@1313 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jfranck@1313 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jfranck@1313 | 13 | * accompanied this code). |
jfranck@1313 | 14 | * |
jfranck@1313 | 15 | * You should have received a copy of the GNU General Public License version |
jfranck@1313 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jfranck@1313 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jfranck@1313 | 18 | * |
jfranck@1313 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jfranck@1313 | 20 | * or visit www.oracle.com if you need additional information or have any |
jfranck@1313 | 21 | * questions. |
jfranck@1313 | 22 | */ |
jfranck@1313 | 23 | |
jfranck@1313 | 24 | /** |
jfranck@1313 | 25 | * @test |
jfranck@1313 | 26 | * @summary Smoke test for repeating annotations |
jfranck@1313 | 27 | * @bug 7151010 |
jfranck@1313 | 28 | * |
jfranck@1313 | 29 | * @run clean BasicRepeatingAnnotations BasicRepeatingAnnos BasicNonRepeatingAnno Foo Foos Bar |
jfranck@1313 | 30 | * @run compile BasicRepeatingAnnotations.java |
jfranck@1313 | 31 | * @run main BasicRepeatingAnnotations |
jfranck@1313 | 32 | */ |
jfranck@1313 | 33 | |
jfranck@1313 | 34 | import java.lang.annotation.*; |
jfranck@1313 | 35 | |
jfranck@1313 | 36 | @Retention(RetentionPolicy.RUNTIME) |
jfranck@1313 | 37 | @ContainedBy(Foos.class) |
jfranck@1313 | 38 | @interface Foo {} |
jfranck@1313 | 39 | |
jfranck@1313 | 40 | @ContainerFor(Foo.class) |
jfranck@1313 | 41 | @Retention(RetentionPolicy.RUNTIME) |
jfranck@1313 | 42 | @interface Foos { |
jfranck@1313 | 43 | Foo[] value(); |
jfranck@1313 | 44 | } |
jfranck@1313 | 45 | |
jfranck@1313 | 46 | @interface Bar {} |
jfranck@1313 | 47 | |
jfranck@1313 | 48 | @Foo @Foo |
jfranck@1313 | 49 | @Foo |
jfranck@1313 | 50 | @Bar |
jfranck@1313 | 51 | @Foo |
jfranck@1313 | 52 | @Foo |
jfranck@1313 | 53 | @Foo |
jfranck@1313 | 54 | @Foo |
jfranck@1313 | 55 | @Foo @Foo |
jfranck@1313 | 56 | @Foo |
jfranck@1313 | 57 | class BasicRepeatingAnnos {} |
jfranck@1313 | 58 | |
jfranck@1313 | 59 | @Foo |
jfranck@1313 | 60 | class BasicNonRepeatingAnno {} |
jfranck@1313 | 61 | |
jfranck@1313 | 62 | public class BasicRepeatingAnnotations { |
jfranck@1313 | 63 | public static void main(String[] args) throws Exception { |
jfranck@1313 | 64 | Annotation a = BasicRepeatingAnnos.class.getAnnotation(Foos.class); |
jfranck@1313 | 65 | if (a == null) { |
jfranck@1313 | 66 | throw new RuntimeException("Container annotation missing"); |
jfranck@1313 | 67 | } |
jfranck@1313 | 68 | |
jfranck@1313 | 69 | // verify that container not present on nonrepeating |
jfranck@1313 | 70 | a = BasicNonRepeatingAnno.class.getAnnotation(Foos.class); |
jfranck@1313 | 71 | if (a != null) { |
jfranck@1313 | 72 | throw new RuntimeException("Container annotation present"); |
jfranck@1313 | 73 | } |
jfranck@1313 | 74 | a = BasicNonRepeatingAnno.class.getAnnotation(Foo.class); |
jfranck@1313 | 75 | if (a == null) { |
jfranck@1313 | 76 | throw new RuntimeException("Repeated annoation not directly present"); |
jfranck@1313 | 77 | } |
jfranck@1313 | 78 | } |
jfranck@1313 | 79 | } |