1 /* 2 * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24 /* 25 * @test 26 * @bug 5034991 5040842 5040853 27 * @summary Modify class-file representation of Class-valued annotation elements 28 * @author gafter 29 * 30 * @compile -source 1.5 Primitives.java 31 * @run main Primitives 32 */ 33 34 public class Primitives { 35 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) 36 @interface A { 37 Class value() default void.class; 38 } 39 40 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) 41 @interface B { 42 Class[] value() default { void.class }; 43 } 44 45 @A() 46 @B() 47 static class T1 {} 48 49 @A(int.class) 50 @B({void.class, byte.class, char.class, short.class, int.class, long.class, 51 boolean.class, float.class, double.class, A[].class, int[].class}) 52 static class T2 {} 53 54 static void check(Object actual, Object expected) { 55 if (actual != expected) 56 throw new Error("expected: " + expected + "; actual = " + actual); 57 } 58 59 public static void main(String[] args) { 60 check(T1.class.getAnnotation(A.class).value(), void.class); 61 check(T1.class.getAnnotation(B.class).value().length, 1); 62 check(T1.class.getAnnotation(B.class).value()[0], void.class); 63 64 check(T2.class.getAnnotation(A.class).value(), int.class); 65 check(T2.class.getAnnotation(B.class).value().length, 11); 66 check(T2.class.getAnnotation(B.class).value()[0], void.class); 67 check(T2.class.getAnnotation(B.class).value()[1], byte.class); 68 check(T2.class.getAnnotation(B.class).value()[2], char.class); 69 check(T2.class.getAnnotation(B.class).value()[3], short.class); 70 check(T2.class.getAnnotation(B.class).value()[4], int.class); 71 check(T2.class.getAnnotation(B.class).value()[5], long.class); 72 check(T2.class.getAnnotation(B.class).value()[6], boolean.class); 73 check(T2.class.getAnnotation(B.class).value()[7], float.class); 74 check(T2.class.getAnnotation(B.class).value()[8], double.class); 75 check(T2.class.getAnnotation(B.class).value()[9], A[].class); 76 check(T2.class.getAnnotation(B.class).value()[10], int[].class); 77 } 78 }