RuntimeParameterAnnotationsForGenericMethodTest.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 RuntimeParameterVisibleAnnotations/RuntimeParameterInvisibleAnnotations attribute. 28 * Checks that the attribute is generated for bridge method. 29 * @modules jdk.jdeps/com.sun.tools.classfile 30 * jdk.compiler/com.sun.tools.javac.api 31 * jdk.compiler/com.sun.tools.javac.main 32 * jdk.jdeps/com.sun.tools.javap 33 * @library /tools/lib /tools/javac/lib ../lib 34 * @build WorkAnnotations TestBase TestResult InMemoryFileManager ToolBox 35 * @build TestCase ClassType TestAnnotationInfo 36 * @build RuntimeParameterAnnotationsForGenericMethodTest AnnotationsTestBase RuntimeParameterAnnotationsTestBase 37 * @run main RuntimeParameterAnnotationsForGenericMethodTest 38 */ 39 40import java.util.ArrayList; 41import java.util.List; 42 43/** 44 * RuntimeParameterAnnotationsGenericMethodTest is a test which check that 45 * RuntimeVisibleParameterAnnotationsAttribute and 46 * RuntimeInvisibleParameterAnnotationsAttribute are generated for both 47 * generic and appropriate bridge methods. 48 * All possible combinations of retention policies are tested. 49 * 50 * The test generates class which looks as follows: 51 * 52 * public class Test extends java.util.ArrayList<Integer> { 53 * 54 * public boolean add(here some annotations java.lang.Integer) { 55 * return false; 56 * } 57 * } 58 * 59 * Thereafter, various of combinations of annotations are applied 60 * to the add, the source is compiled and the generated byte code is checked. 61 * 62 * See README.txt for more information. 63 */ 64public class RuntimeParameterAnnotationsForGenericMethodTest extends RuntimeParameterAnnotationsTestBase { 65 @Override 66 public List<TestCase> generateTestCases() { 67 List<TestCase> testCases = new ArrayList<>(); 68 for (TestAnnotationInfos annotations : getAllCombinationsOfAnnotations()) { 69 // generate: public class Test extends java.util.ArrayList<Integer> 70 TestCase testCase = new TestCase(); 71 TestCase.TestClassInfo clazz = testCase.addClassInfo("java.util.ArrayList<Integer>", ClassType.CLASS, "Test"); 72 TestCase.TestParameterInfo parameter = clazz.addMethodInfo("add(java.lang.Integer)", "public").addParameter("Integer", "i"); 73 annotations.annotate(parameter); 74 TestCase.TestParameterInfo synParameter = clazz.addMethodInfo("add(java.lang.Object)", true, "public").addParameter("Object", "i"); 75 annotations.annotate(synParameter); 76 testCases.add(testCase); 77 } 78 return testCases; 79 } 80 81 public static void main(String[] args) throws TestFailedException { 82 new RuntimeParameterAnnotationsForGenericMethodTest().test(); 83 } 84} 85