1/*
2 * Copyright (c) 2015, 2016, 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 *          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 * @library /tools/lib /tools/javac/lib ../lib
33 * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
34 * @build WorkAnnotations TestCase ClassType TestAnnotationInfo
35 * @build RuntimeAnnotationsForGenericMethodTest AnnotationsTestBase RuntimeAnnotationsTestBase
36 * @run main RuntimeAnnotationsForGenericMethodTest
37 */
38
39import java.util.ArrayList;
40import java.util.List;
41
42/**
43 * RuntimeAnnotationsGenericMethodTest is a test which check that
44 * RuntimeVisibleAnnotationsAttribute and RuntimeInvisibleAnnotationsAttribute
45 * are generated for both generic and appropriate bridge methods.
46 * All possible combinations of retention policies are tested.
47 *
48 * The test generates class which looks as follows:
49 *
50 * public class Test extends java.util.ArrayList<Integer> {
51 *     here some annotations
52 *     public boolean add(java.lang.Integer) {
53 *         return false;
54 *     }
55 * }
56 *
57 * Thereafter, various of combinations of annotations are applied
58 * to the add, the source is compiled and the generated byte code is checked.
59 *
60 * See README.txt for more information.
61 */
62public class RuntimeAnnotationsForGenericMethodTest extends RuntimeAnnotationsTestBase {
63
64    @Override
65    public List<TestCase> generateTestCases() {
66        List<TestCase> testCases = new ArrayList<>();
67        for (List<TestAnnotationInfos> groupedAnnotations : groupAnnotations(getAllCombinationsOfAnnotations())) {
68            TestCase testCase = new TestCase();
69            for (int i = 0; i < groupedAnnotations.size(); ++i) {
70                TestAnnotationInfos annotations = groupedAnnotations.get(i);
71                // generate: public class Test extends java.util.ArrayList<Integer>
72                TestCase.TestClassInfo clazz = testCase.addClassInfo("java.util.ArrayList<Integer>", ClassType.CLASS, "Test" + i);
73                TestCase.TestMethodInfo method = clazz.addMethodInfo("add(java.lang.Integer)", "public");
74                method.addParameter("Integer", "i");
75                annotations.annotate(method);
76                TestCase.TestMethodInfo synMethod = clazz.addMethodInfo("add(java.lang.Object)", true, "public");
77                annotations.annotate(synMethod);
78            }
79            testCases.add(testCase);
80        }
81        return testCases;
82    }
83
84    public static void main(String[] args) throws TestFailedException {
85        new RuntimeAnnotationsForGenericMethodTest().test();
86    }
87}
88