test/tools/javac/annotations/pos/Primitives.java

Thu, 25 Aug 2011 17:18:25 -0700

author
schien
date
Thu, 25 Aug 2011 17:18:25 -0700
changeset 1067
f497fac86cf9
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8-b02 for changeset b3c059de2a61

     1 /*
     2  * Copyright (c) 2004, 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  */
    24 /*
    25  * @test
    26  * @bug 5034991 5040842 5040853
    27  * @summary Modify class-file representation of Class-valued annotation elements
    28  * @author gafter
    29  */
    31 public class Primitives {
    32     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
    33     @interface A {
    34         Class value() default void.class;
    35     }
    37     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
    38     @interface B {
    39         Class[] value() default { void.class };
    40     }
    42     @A()
    43     @B()
    44     static class T1 {}
    46     @A(int.class)
    47     @B({void.class, byte.class, char.class, short.class, int.class, long.class,
    48         boolean.class, float.class, double.class, A[].class, int[].class})
    49     static class T2 {}
    51     static void check(Object actual, Object expected) {
    52         if (actual != expected)
    53             throw new Error("expected: " + expected + "; actual = " + actual);
    54     }
    56     public static void main(String[] args) {
    57         check(T1.class.getAnnotation(A.class).value(), void.class);
    58         check(T1.class.getAnnotation(B.class).value().length, 1);
    59         check(T1.class.getAnnotation(B.class).value()[0], void.class);
    61         check(T2.class.getAnnotation(A.class).value(), int.class);
    62         check(T2.class.getAnnotation(B.class).value().length, 11);
    63         check(T2.class.getAnnotation(B.class).value()[0], void.class);
    64         check(T2.class.getAnnotation(B.class).value()[1], byte.class);
    65         check(T2.class.getAnnotation(B.class).value()[2], char.class);
    66         check(T2.class.getAnnotation(B.class).value()[3], short.class);
    67         check(T2.class.getAnnotation(B.class).value()[4], int.class);
    68         check(T2.class.getAnnotation(B.class).value()[5], long.class);
    69         check(T2.class.getAnnotation(B.class).value()[6], boolean.class);
    70         check(T2.class.getAnnotation(B.class).value()[7], float.class);
    71         check(T2.class.getAnnotation(B.class).value()[8], double.class);
    72         check(T2.class.getAnnotation(B.class).value()[9], A[].class);
    73         check(T2.class.getAnnotation(B.class).value()[10], int[].class);
    74     }
    75 }

mercurial