/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 8013497 * @summary test for API: AnnotatedType.getType() * @author Charlie Wang * @library ../../../../ * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper * @run main AnnotatedTypeGetTypeTest */ import java.io.Serializable; import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; /* * This file is intended to test API: AnnotatedType.getType(). * It can be run directly by java command or by jtreg. * Annotation declarations for the test are defined in this file. */ public class AnnotatedTypeGetTypeTest extends AnnotationTest { public boolean checkResult() throws Exception { if (!AnnoTypeCls01.class.getAnnotatedInterfaces()[0]. getType().equals(Serializable.class)) { return false; } if (!AnnoTypeCls02.class.getAnnotatedSuperclass(). getType().equals(Exception.class)) { return false; } if (!AnnoTypeCls01.class.getDeclaredField("f1").getAnnotatedType(). getType().equals(String[].class)) { return false; } if (!((AnnotatedWildcardType) ((AnnotatedParameterizedType) AnnoTypeCls01.class.getDeclaredField("f2").getAnnotatedType()). getAnnotatedActualTypeArguments()[0]). getAnnotatedLowerBounds()[0].getType().equals(Object.class)) { return false; } if (!((AnnotatedWildcardType) ((AnnotatedParameterizedType) AnnoTypeCls01.class.getDeclaredField("f3").getAnnotatedType()) .getAnnotatedActualTypeArguments()[0]) .getAnnotatedUpperBounds()[0].getType().equals(Object.class)) { return false; } if (!AnnoTypeCls01.class.getDeclaredMethod("m1", (Class[]) null) .getAnnotatedExceptionTypes()[0].getType(). equals(RuntimeException.class)) { return false; } if (!AnnoTypeCls01.class.getDeclaredMethod("m2" , new Class[] {String.class}).getAnnotatedParameterTypes()[0]. getType().equals(String.class)) return false; if (!AnnoTypeCls01.class.getDeclaredMethod("m3", (Class[]) null) .getAnnotatedReturnType().getType().equals(Integer.class)) { return false; } if (!AnnoTypeCls01.class.getDeclaredMethod("m4") .getAnnotatedReceiverType().getType(). equals(AnnoTypeCls01.class)) { return false; } if (!AnnoTypeCls03.class.getTypeParameters()[0] .getAnnotatedBounds()[0].getType().equals(Object.class)) { return false; } return true; } public static void main(String[] args) throws Exception { new AnnotatedTypeGetTypeTest().test(); } @Override protected String genTestCode(Class tcg) { throw new UnsupportedOperationException("Not supported yet."); } } class AnnoTypeCls01 implements @TypeAnno1("TypeAnno1") Serializable{ public String @TypeAnno1("TypeAnno1") [] f1 ; private List f2 ; private List f3 ; public String m1() throws @TypeAnno1("TypeAnno1") RuntimeException { return null; } public String m2(@TypeAnno1("TypeAnno1") String s) { return null; } public @TypeAnno1("TypeAnno1") Integer m3() { return null; } public @TypeAnno1("TypeAnno11")Integer m4( @TypeAnno1("TypeAnno12") AnnoTypeCls01 this){ return null; } } class AnnoTypeCls02 extends @TypeAnno1("TypeAnno1") Exception {} class AnnoTypeCls03 {} @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) @Repeatable(TypeAnno1Container.class) @interface TypeAnno1 { String value(); } @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) @Repeatable(TypeAnno2Container.class) @interface TypeAnno2 { String value(); } @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) @Repeatable(TypeAnno3Container.class) @interface TypeAnno3 { } @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) @interface TypeAnno1Container { TypeAnno1[] value(); } @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) @interface TypeAnno2Container { TypeAnno2[] value(); } @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) @interface TypeAnno3Container { TypeAnno3[] value(); }