langtools/test/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForGenericMethodTest.java
author jjg
Thu, 31 Mar 2016 15:20:50 -0700
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
permissions -rw-r--r--
8152897: refactor ToolBox to allow reduced documented dependencies Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31750
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     1
/*
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
31750
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     4
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     8
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    13
 * accompanied this code).
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    14
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    18
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    21
 * questions.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    22
 */
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    23
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    24
/*
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    25
 * @test
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    26
 * @bug 8044411
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    27
 * @summary Tests the RuntimeParameterVisibleAnnotations/RuntimeParameterInvisibleAnnotations attribute.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    28
 *          Checks that the attribute is generated for bridge method.
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 31750
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.classfile
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 31750
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 31750
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.main
31750
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    32
 * @library /tools/lib /tools/javac/lib ../lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    34
 * @build WorkAnnotations TestCase ClassType TestAnnotationInfo
31750
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    35
 * @build RuntimeParameterAnnotationsForGenericMethodTest AnnotationsTestBase RuntimeParameterAnnotationsTestBase
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    36
 * @run main RuntimeParameterAnnotationsForGenericMethodTest
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    37
 */
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    38
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    39
import java.util.ArrayList;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    40
import java.util.List;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    41
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    42
/**
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    43
 * RuntimeParameterAnnotationsGenericMethodTest is a test which check that
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    44
 * RuntimeVisibleParameterAnnotationsAttribute and
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    45
 * RuntimeInvisibleParameterAnnotationsAttribute are generated for both
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    46
 * generic and appropriate bridge methods.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    47
 * All possible combinations of retention policies are tested.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    48
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    49
 * The test generates class which looks as follows:
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    50
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    51
 * public class Test extends java.util.ArrayList<Integer> {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    52
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    53
 *     public boolean add(here some annotations java.lang.Integer) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    54
 *         return false;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    55
 *     }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    56
 * }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    57
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    58
 * Thereafter, various of combinations of annotations are applied
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    59
 * to the add, the source is compiled and the generated byte code is checked.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    60
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    61
 * See README.txt for more information.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    62
 */
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    63
public class RuntimeParameterAnnotationsForGenericMethodTest extends RuntimeParameterAnnotationsTestBase {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    64
    @Override
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    65
    public List<TestCase> generateTestCases() {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    66
        List<TestCase> testCases = new ArrayList<>();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    67
        for (TestAnnotationInfos annotations : getAllCombinationsOfAnnotations()) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    68
            // generate: public class Test extends java.util.ArrayList<Integer>
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    69
            TestCase testCase = new TestCase();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    70
            TestCase.TestClassInfo clazz = testCase.addClassInfo("java.util.ArrayList<Integer>", ClassType.CLASS, "Test");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    71
            TestCase.TestParameterInfo parameter = clazz.addMethodInfo("add(java.lang.Integer)", "public").addParameter("Integer", "i");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    72
            annotations.annotate(parameter);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    73
            TestCase.TestParameterInfo synParameter = clazz.addMethodInfo("add(java.lang.Object)", true, "public").addParameter("Object", "i");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    74
            annotations.annotate(synParameter);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    75
            testCases.add(testCase);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    76
        }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    77
        return testCases;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    78
    }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    79
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    80
    public static void main(String[] args) throws TestFailedException {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    81
        new RuntimeParameterAnnotationsForGenericMethodTest().test();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    82
    }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    83
}