langtools/test/tools/javac/classfiles/attributes/annotations/RuntimeAnnotationsForInnerClassTest.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 RuntimeVisibleAnnotations/RuntimeInvisibleAnnotations 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 RuntimeAnnotationsForInnerClassTest AnnotationsTestBase RuntimeAnnotationsTestBase
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    35
 * @run main RuntimeAnnotationsForInnerClassTest
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
 * The test checks that RuntimeVisibleAnnotationsAttribute and RuntimeInvisibleAnnotationsAttribute
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    43
 * are generated properly for inner classes, for constructors, for methods, for fields.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    44
 * The test checks both single and repeatable annotations. In addition, all possible combinations
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    45
 * of retention policies are tested.
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    46
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    47
 * 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
    48
 *
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    49
 * See README.txt for more information.
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 RuntimeAnnotationsForInnerClassTest extends RuntimeAnnotationsTestBase {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    52
    @Override
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    53
    public List<TestCase> generateTestCases() {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    54
        List<TestCase> testCases = new ArrayList<>();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    55
        for (List<TestAnnotationInfos> groupedAnnotations : groupAnnotations(getAllCombinationsOfAnnotations())) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    56
            for (ClassType outerClassType : ClassType.values()) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    57
                TestCase test = new TestCase();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    58
                TestCase.TestClassInfo outerClazz = test.addClassInfo(outerClassType, "Test");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    59
                for (int i = 0; i < groupedAnnotations.size(); ++i) {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    60
                    TestAnnotationInfos annotations = groupedAnnotations.get(i);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    61
                    TestCase.TestClassInfo clazz = outerClazz.addInnerClassInfo(ClassType.CLASS, "InnerClass" + i, "static");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    62
                    annotations.annotate(clazz);
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
                    TestCase.TestMethodInfo constructor = clazz.addMethodInfo("<init>()");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    65
                    annotations.annotate(constructor);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    66
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    67
                    TestCase.TestClassInfo localClassInConstructor = constructor.addLocalClassInfo("Local1" + i);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    68
                    annotations.annotate(localClassInConstructor);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    69
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    70
                    TestCase.TestMethodInfo innerClazzMethod = clazz.addMethodInfo("innerClassMethod" + i + "()");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    71
                    annotations.annotate(innerClazzMethod);
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
                    TestCase.TestClassInfo localClassInClassMethod = innerClazzMethod.addLocalClassInfo("Local2" + i);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    74
                    annotations.annotate(localClassInClassMethod);
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
                    TestCase.TestMethodInfo innerStaticClazzMethod = clazz.addMethodInfo("innerStaticClassMethod" + i + "()", "static");
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    77
                    annotations.annotate(innerStaticClazzMethod);
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
                    TestCase.TestClassInfo localClassInStaticMethod = innerStaticClazzMethod.addLocalClassInfo("Local3" + i);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    80
                    annotations.annotate(localClassInStaticMethod);
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
                testCases.add(test);
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    83
            }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    84
        }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    85
        return testCases;
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
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    88
    public static void main(String[] args) throws TestFailedException {
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    89
        new RuntimeAnnotationsForInnerClassTest().test();
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    90
    }
c65c37c0c691 8044411: Implement classfile tests for RuntimeAnnotations and RuntimeParameterAnnotations attribute.
aeremeev
parents:
diff changeset
    91
}