langtools/test/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsTest.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.
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 31750
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.classfile
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 31750
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 31750
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
31750
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    31
 * @library /tools/lib /tools/javac/lib ../lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build WorkAnnotations TestCase ClassType TestAnnotationInfo
31750
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    34
 * @build RuntimeParameterAnnotationsTest AnnotationsTestBase RuntimeParameterAnnotationsTestBase
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    35
 * @run main RuntimeParameterAnnotationsTest
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    36
 */
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
import java.util.ArrayList;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    39
import java.util.List;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    40
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
 * RuntimeParameterAnnotationsTest is a test which checks that RuntimeVisibleParameterAnnotationsAttribute
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    43
 * and RuntimeInvisibleParameterAnnotationsAttribute are generated properly for constructors,
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    44
 * for static and abstract methods of class, for abstract, default and static methods of interface.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    45
 * The test checks both single and repeatable annotations.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    46
 * All possible combinations of retention policies are tested.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    47
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    48
 * The test generates source code, compiles it and checks the byte code.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    49
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    50
 * See README.txt for more information.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    51
 */
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    52
public class RuntimeParameterAnnotationsTest extends RuntimeParameterAnnotationsTestBase {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    53
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    54
    @Override
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    55
    public List<TestCase> generateTestCases() {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    56
        List<TestCase> testCases = new ArrayList<>();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    57
        for (List<TestAnnotationInfos> groupedAnnotations : groupAnnotations(getAllCombinationsOfAnnotations())) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    58
            for (ClassType classType : new ClassType[]{ClassType.CLASS, ClassType.INTERFACE}) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    59
                TestCase test = new TestCase();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    60
                for (int i = 0; i < groupedAnnotations.size(); i++) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    61
                    TestAnnotationInfos annotations = groupedAnnotations.get(i);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    62
                    TestCase.TestClassInfo clazz = test.addClassInfo(classType, "Test" + i, "abstract");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    63
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    64
                    initMethod(annotations, clazz, "<init>");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    65
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    66
                    initMethod(annotations, clazz, "method1");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    67
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    68
                    initMethod(annotations, clazz, "method2",
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    69
                            classType == ClassType.CLASS ? "abstract" : "default");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    70
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    71
                    initMethod(annotations, clazz, "staticMethod", "static");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    72
                }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    73
                testCases.add(test);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    74
            }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    75
        }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    76
        return testCases;
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    77
    }
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
     * Adds a method to the {@code testCase} with {@code methodName}.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    81
     *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    82
     * @param annotations a list of annotations
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    83
     * @param clazz a test class
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    84
     * @param methodName a method name
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    85
     * @param mods an array of modifiers
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    86
     */
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    87
    private void initMethod(TestAnnotationInfos annotations, TestCase.TestClassInfo clazz, String methodName, String...mods) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    88
        String methodDescriptor = methodName + "(int, double, java.lang.String)";
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    89
        TestCase.TestMethodInfo method = clazz.addMethodInfo(methodDescriptor, mods);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    90
        TestCase.TestParameterInfo p1 = method.addParameter("int", "a");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    91
        annotations.annotate(p1);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    92
        method.addParameter("double", "b");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    93
        TestCase.TestParameterInfo p3 = method.addParameter("String", "c");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    94
        annotations.annotate(p3);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    95
    }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    96
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    97
    public static void main(String[] args) throws TestFailedException {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    98
        new RuntimeParameterAnnotationsTest().test();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    99
    }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
   100
}