RuntimeAnnotationsForInnerInterfaceTest.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2015, 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 */ 23 24/* 25 * @test 26 * @bug 8044411 27 * @summary Tests the RuntimeVisibleAnnotations/RuntimeInvisibleAnnotations attribute. 28 * @modules jdk.jdeps/com.sun.tools.classfile 29 * jdk.compiler/com.sun.tools.javac.api 30 * jdk.compiler/com.sun.tools.javac.main 31 * jdk.jdeps/com.sun.tools.javap 32 * @library /tools/lib /tools/javac/lib ../lib 33 * @build WorkAnnotations TestBase TestResult InMemoryFileManager ToolBox 34 * @build TestCase ClassType TestAnnotationInfo 35 * @build RuntimeAnnotationsForInnerInterfaceTest AnnotationsTestBase RuntimeAnnotationsTestBase 36 * @run main RuntimeAnnotationsForInnerInterfaceTest 37 */ 38 39import java.util.ArrayList; 40import java.util.List; 41 42/** 43 * The test checks that RuntimeVisibleAnnotationsAttribute and RuntimeInvisibleAnnotationsAttribute 44 * are generated properly for inner interfaces, for methods, for fields. The test checks both 45 * single and repeatable annotations. In addition, all possible combinations 46 * of retention policies are tested. 47 * 48 * The test generates source code, compiles it and checks the byte code. 49 * 50 * See README.txt for more information. 51 */ 52public class RuntimeAnnotationsForInnerInterfaceTest extends RuntimeAnnotationsTestBase { 53 @Override 54 public List<TestCase> generateTestCases() { 55 List<TestCase> testCases = new ArrayList<>(); 56 for (List<TestAnnotationInfos> groupedAnnotations : groupAnnotations(getAllCombinationsOfAnnotations())) { 57 for (ClassType outerClassType : ClassType.values()) { 58 TestCase test = new TestCase(); 59 TestCase.TestClassInfo outerClass = test.addClassInfo(outerClassType, "Test"); 60 for (int i = 0; i < groupedAnnotations.size(); ++i) { 61 TestAnnotationInfos annotations = groupedAnnotations.get(i); 62 TestCase.TestClassInfo inter = outerClass.addInnerClassInfo(ClassType.INTERFACE, "InnerInterface" + i); 63 annotations.annotate(inter); 64 65 TestCase.TestFieldInfo interField = inter.addFieldInfo("interField" + i); 66 annotations.annotate(interField); 67 68 TestCase.TestMethodInfo interMethod = inter.addMethodInfo("interMethod" + i + "()"); 69 annotations.annotate(interMethod); 70 71 TestCase.TestMethodInfo interStaticMethod = inter.addMethodInfo("interStaticMethod" + i + "()", "static"); 72 annotations.annotate(interStaticMethod); 73 74 TestCase.TestClassInfo localClassInStaticMethod = interStaticMethod.addLocalClassInfo("Local1" + i); 75 annotations.annotate(localClassInStaticMethod); 76 77 TestCase.TestMethodInfo interDefaultMethod = inter.addMethodInfo("interDefaultMethod" + i + "()", "default"); 78 annotations.annotate(interDefaultMethod); 79 80 TestCase.TestClassInfo localClassInDefaultMethod = interDefaultMethod.addLocalClassInfo("Local2" + i); 81 annotations.annotate(localClassInDefaultMethod); 82 } 83 testCases.add(test); 84 } 85 } 86 return testCases; 87 } 88 89 public static void main(String[] args) throws TestFailedException { 90 new RuntimeAnnotationsForInnerInterfaceTest().test(); 91 } 92} 93