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 4979440 27 * @summary Test for signature parsing corner case 28 * @author Joseph D. Darcy 29 * @compile -source 1.5 getAnnotationTest.java 30 * @run main getAnnotationTest 31 */ 32 33 import java.lang.reflect.*; 34 import java.lang.annotation.*; 35 36 /* 37 * Make sure: 38 * 1. getAnnotation can be called directly 39 * 2. getAnnotation can be called reflectively 40 * 3. generic information methods on the Method object for 41 * getAnnotation can be called 42 */ 43 44 public class getAnnotationTest { 45 public static void main (String[] args) throws Throwable { 46 // Base level 47 Class c = Class.forName("java.lang.annotation.Retention"); 48 Annotation result = c.getAnnotation(Retention.class); 49 // System.out.println("Base result:" + result); 50 51 // Meta level, invoke Class.getAnnotation reflectively... 52 Class meta_c = c.getClass(); 53 Method meta_getAnnotation = meta_c.getMethod("getAnnotation", 54 (Retention.class).getClass()); 55 56 Object meta_result = meta_getAnnotation.invoke(c, Retention.class); 57 // System.out.println("Meta result:" + meta_result); 58 59 if (!meta_result.equals(result)) { 60 throw new RuntimeException("Base and meta results are not equal."); 61 } 62 63 meta_getAnnotation.getGenericExceptionTypes(); 64 meta_getAnnotation.getGenericParameterTypes(); 65 meta_getAnnotation.getGenericReturnType(); 66 } 67 }