langtools/test/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.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:
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     1
/*
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     4
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     8
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    13
 * accompanied this code).
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    14
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    18
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    21
 * questions.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    22
 */
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    23
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    24
/*
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    25
 * @test
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    26
 * @bug 8042931
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    27
 * @summary Checking EnclosingMethod attribute of anonymous/local class.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    28
 * @library /tools/lib /tools/javac/lib ../lib
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 30846
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 30846
diff changeset
    31
 *          jdk.jdeps/com.sun.tools.classfile
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    33
 * @run main EnclosingMethodTest
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    34
 */
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    35
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    36
import com.sun.tools.classfile.Attribute;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    37
import com.sun.tools.classfile.ClassFile;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    38
import com.sun.tools.classfile.EnclosingMethod_attribute;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    39
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    40
import java.io.File;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    41
import java.io.FilenameFilter;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    42
import java.lang.annotation.Retention;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    43
import java.lang.annotation.RetentionPolicy;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    44
import java.util.HashMap;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    45
import java.util.HashSet;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    46
import java.util.Map;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    47
import java.util.Set;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    48
import java.util.stream.Stream;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    49
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    50
/**
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    51
 * The test checks the enclosing method attribute of anonymous/local classes.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    52
 * The top-level class contains the anonymous and local classes to be tested. The test examines
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    53
 * each inner class and determine whether the class should have the EnclosingMethod attribute or not.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    54
 * Golden information about enclosing methods are held in annotation {@code ExpectedEnclosingMethod}.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    55
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    56
 * The test assumes that a class must have the EnclosingMethod attribute if the class is annotated or
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    57
 * if its parent class is annotated in case of anonymous class. In addition, classes
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    58
 * named {@code VariableInitializer} are introduced to test variable initializer cases. These classes
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    59
 * must not have the enclosing method attribute, but its anonymous derived class must.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    60
 * After classification of classes, the test checks whether classes contain the correct enclosing
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    61
 * method attribute in case of anonymous/local class, or checks whether classes do not contain
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    62
 * the EnclosingMethod attribute, otherwise.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    63
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    64
 * Test cases:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    65
 *   top-level class as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    66
 *     1. anonymous and local classes in static initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    67
 *     2. anonymous and local classes in instance initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    68
 *     3. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    69
 *     4. anonymous and local classes in constructor;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    70
 *     5. anonymous and local classes in method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    71
 *     6. static and instance variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    72
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    73
 *   inner class as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    74
 *     1. anonymous and local classes in static initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    75
 *     2. anonymous and local classes in instance initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    76
 *     3. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    77
 *     4. anonymous and local classes in constructor;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    78
 *     5. anonymous and local classes in method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    79
 *     6. static and instance variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    80
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    81
 *   enum as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    82
 *     1. anonymous and local classes in static initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    83
 *     2. anonymous and local classes in instance initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    84
 *     3. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    85
 *     4. anonymous and local classes in constructor;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    86
 *     5. anonymous and local classes in method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    87
 *     6. static and instance variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    88
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    89
 *   interface as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    90
 *     1. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    91
 *     2. anonymous and local classes in static method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    92
 *     3. anonymous and local classes in default method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    93
 *     4. static variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    94
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    95
 *   annotation as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    96
 *     1. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    97
 *     2. static variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    98
 */
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    99
public class EnclosingMethodTest extends TestResult {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   100
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   101
    private final Map<Class<?>, ExpectedEnclosingMethod> class2EnclosingMethod = new HashMap<>();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   102
    private final Set<Class<?>> noEnclosingMethod = new HashSet<>();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   103
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   104
    public EnclosingMethodTest() throws ClassNotFoundException {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   105
        Class<EnclosingMethodTest> outerClass = EnclosingMethodTest.class;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   106
        String outerClassName = outerClass.getSimpleName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   107
        File testClasses = getClassDir();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   108
        FilenameFilter filter = (dir, name) -> name.matches(outerClassName + ".*\\.class");
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   109
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   110
        for (File file : testClasses.listFiles(filter)) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   111
            Class<?> clazz = Class.forName(file.getName().replace(".class", ""));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   112
            if (clazz.isAnonymousClass()) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   113
                // anonymous class cannot be annotated, information is in its parent class.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   114
                ExpectedEnclosingMethod declaredAnnotation =
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   115
                        clazz.getSuperclass().getDeclaredAnnotation(ExpectedEnclosingMethod.class);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   116
                class2EnclosingMethod.put(clazz, declaredAnnotation);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   117
            } else {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   118
                ExpectedEnclosingMethod enclosingMethod = clazz.getDeclaredAnnotation(ExpectedEnclosingMethod.class);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   119
                // if class is annotated and it does not contain information for variable initializer cases,
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   120
                // then it must have the enclosing method attribute.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   121
                if (enclosingMethod != null && !clazz.getSimpleName().contains("VariableInitializer")) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   122
                    class2EnclosingMethod.put(clazz, enclosingMethod);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   123
                } else {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   124
                    noEnclosingMethod.add(clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   125
                }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   126
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   127
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   128
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   129
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   130
    public void test() throws TestFailedException {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   131
        try {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   132
            testEnclosingMethodAttribute();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   133
            testLackOfEnclosingMethodAttribute();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   134
        } finally {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   135
            checkStatus();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   136
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   137
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   138
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   139
    private void testLackOfEnclosingMethodAttribute() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   140
        for (Class<?> clazz : noEnclosingMethod) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   141
            try {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   142
                addTestCase("Class should not have EnclosingMethod attribute : " + clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   143
                ClassFile classFile = readClassFile(clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   144
                checkEquals(countEnclosingMethodAttributes(classFile),
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   145
                        0l, "number of the EnclosingMethod attribute in the class is zero : "
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   146
                                + classFile.getName());
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   147
            } catch (Exception e) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   148
                addFailure(e);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   149
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   150
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   151
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   152
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   153
    private void testEnclosingMethodAttribute() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   154
        class2EnclosingMethod.forEach((clazz, enclosingMethod) -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   155
            try {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   156
                String info = enclosingMethod.info() + " "
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   157
                        + (clazz.isAnonymousClass() ? "anonymous" : "local");
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   158
                addTestCase(info);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   159
                printf("Testing test case : %s\n", info);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   160
                ClassFile classFile = readClassFile(clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   161
                String className = clazz.getName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   162
                checkEquals(countEnclosingMethodAttributes(classFile), 1l,
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   163
                        "number of the EnclosingMethod attribute in the class is one : "
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   164
                                + clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   165
                EnclosingMethod_attribute attr = (EnclosingMethod_attribute)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   166
                        classFile.getAttribute(Attribute.EnclosingMethod);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   167
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   168
                if (!checkNotNull(attr, "the EnclosingMethod attribute is not null : " + className)) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   169
                    // stop checking, attr is null. test case failed
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   170
                    return;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   171
                }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   172
                checkEquals(classFile.constant_pool.getUTF8Value(attr.attribute_name_index),
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   173
                        "EnclosingMethod",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   174
                        "attribute_name_index of EnclosingMethod attribute in the class : " + className);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   175
                checkEquals(attr.attribute_length, 4,
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   176
                        "attribute_length of EnclosingMethod attribute in the class : " + className);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   177
                String expectedClassName = enclosingMethod.enclosingClazz().getName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   178
                checkEquals(classFile.constant_pool.getClassInfo(attr.class_index).getName(),
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   179
                        expectedClassName, String.format(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   180
                        "enclosing class of EnclosingMethod attribute in the class %s is %s",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   181
                                className, expectedClassName));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   182
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   183
                String expectedMethodName = enclosingMethod.enclosingMethod();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   184
                if (expectedMethodName.isEmpty()) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   185
                    // class does not have an enclosing method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   186
                    checkEquals(attr.method_index, 0, String.format(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   187
                            "enclosing method of EnclosingMethod attribute in the class %s is null", className));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   188
                } else {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   189
                    String methodName = classFile.constant_pool.getNameAndTypeInfo(attr.method_index).getName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   190
                    checkTrue(methodName.startsWith(expectedMethodName), String.format(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   191
                            "enclosing method of EnclosingMethod attribute in the class %s" +
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   192
                                    " is method name %s" +
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   193
                                    ", actual method name is %s",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   194
                            className, expectedMethodName, methodName));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   195
                }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   196
            } catch (Exception e) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   197
                addFailure(e);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   198
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   199
        });
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   200
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   201
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   202
    private long countEnclosingMethodAttributes(ClassFile classFile) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   203
        return Stream.of(classFile.attributes.attrs)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   204
                .filter(x -> x instanceof EnclosingMethod_attribute)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   205
                .count();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   206
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   207
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   208
    @Retention(RetentionPolicy.RUNTIME)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   209
    public @interface ExpectedEnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   210
        String info();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   211
        Class<?> enclosingClazz();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   212
        String enclosingMethod() default "";
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   213
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   214
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   215
    public static void main(String[] args) throws ClassNotFoundException, TestFailedException {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   216
        new EnclosingMethodTest().test();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   217
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   218
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   219
    // Test cases: enclosing class is a top-level class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   220
    static {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   221
        // anonymous and local classes in static initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   222
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   223
                info = "EnclosingStaticInitialization in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   224
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   225
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   226
        class EnclosingStaticInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   227
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   228
        new EnclosingStaticInitialization() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   229
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   230
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   231
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   232
    {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   233
        // anonymous and local classes in instance initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   234
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   235
                info = "EnclosingInitialization in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   236
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   237
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   238
        class EnclosingInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   239
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   240
        new EnclosingInitialization() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   241
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   242
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   243
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   244
    Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   245
        // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   246
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   247
                info = "EnclosingLambda in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   248
                enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   249
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   250
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   251
        class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   252
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   253
        new EnclosingLambda() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   254
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   255
    };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   256
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   257
    EnclosingMethodTest(int i) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   258
        // anonymous and local classes in constructor
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   259
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   260
                info = "EnclosingConstructor in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   261
                enclosingMethod = "<init>",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   262
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   263
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   264
        class EnclosingConstructor {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   265
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   266
        new EnclosingConstructor() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   267
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   268
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   269
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   270
    void method() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   271
        // anonymous and local classes in method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   272
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   273
                info = "EnclosingMethod in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   274
                enclosingMethod = "method",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   275
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   276
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   277
        class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   278
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   279
        new EnclosingMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   280
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   281
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   282
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   283
    @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   284
            info = "VariableInitializer in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   285
            enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   286
    )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   287
    static class VariableInitializer {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   288
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   289
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   290
    // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   291
    private static final VariableInitializer cvi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   292
    };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   293
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   294
    // instance variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   295
    private final VariableInitializer ivi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   296
    };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   297
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   298
    // Test cases: enclosing class is an inner class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   299
    public static class notEnclosing01 {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   300
        static {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   301
            // anonymous and local classes in static initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   302
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   303
                    info = "EnclosingStaticInitialization in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   304
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   305
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   306
            class EnclosingStaticInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   307
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   308
            new EnclosingStaticInitialization() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   309
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   310
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   311
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   312
        {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   313
            // anonymous and local classes in instance initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   314
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   315
                    info = "EnclosingInitialization in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   316
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   317
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   318
            class EnclosingInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   319
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   320
            new EnclosingInitialization() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   321
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   322
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   323
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   324
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   325
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   326
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   327
                    info = "EnclosingLambda in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   328
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   329
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   330
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   331
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   332
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   333
            new EnclosingLambda() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   334
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   335
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   336
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   337
        notEnclosing01() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   338
            // anonymous and local classes in constructor
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   339
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   340
                    info = "EnclosingConstructor in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   341
                    enclosingMethod = "<init>",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   342
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   343
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   344
            class EnclosingConstructor {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   345
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   346
            new EnclosingConstructor() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   347
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   348
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   349
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   350
        void method() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   351
            // anonymous and local classes in method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   352
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   353
                    info = "EnclosingMethod in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   354
                    enclosingMethod = "method",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   355
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   356
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   357
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   358
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   359
            new EnclosingMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   360
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   361
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   362
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   363
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   364
                info = "VariableInitializer in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   365
                enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   366
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   367
        static class VariableInitializer {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   368
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   369
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   370
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   371
        private static final VariableInitializer cvi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   372
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   373
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   374
        // instance variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   375
        private final VariableInitializer ivi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   376
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   377
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   378
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   379
    // Test cases: enclosing class is an interface
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   380
    public interface notEnclosing02 {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   381
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   382
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   383
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   384
                    info = "EnclosingLambda in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   385
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   386
                    enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   387
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   388
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   389
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   390
            new EnclosingLambda() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   391
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   392
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   393
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   394
        static void staticMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   395
            // anonymous and local classes in static method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   396
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   397
                    info = "EnclosingMethod in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   398
                    enclosingMethod = "staticMethod",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   399
                    enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   400
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   401
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   402
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   403
            new EnclosingMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   404
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   405
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   406
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   407
        default void defaultMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   408
            // anonymous and local classes in default method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   409
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   410
                    info = "EnclosingMethod in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   411
                    enclosingMethod = "defaultMethod",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   412
                    enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   413
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   414
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   415
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   416
            new EnclosingMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   417
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   418
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   419
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   420
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   421
                info = "VariableInitializer in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   422
                enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   423
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   424
        static class VariableInitializer {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   425
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   426
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   427
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   428
        VariableInitializer cvi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   429
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   430
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   431
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   432
    // Test cases: enclosing class is an enum
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   433
    public enum notEnclosing03 {;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   434
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   435
        static {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   436
            // anonymous and local classes in static initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   437
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   438
                    info = "EnclosingStaticInitialization in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   439
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   440
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   441
            class EnclosingStaticInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   442
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   443
            new EnclosingStaticInitialization() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   444
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   445
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   446
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   447
        {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   448
            // anonymous and local classes in instance initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   449
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   450
                    info = "EnclosingInitialization in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   451
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   452
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   453
            class EnclosingInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   454
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   455
            new EnclosingInitialization() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   456
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   457
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   458
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   459
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   460
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   461
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   462
                    info = "EnclosingLambda in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   463
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   464
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   465
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   466
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   467
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   468
            new EnclosingLambda() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   469
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   470
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   471
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   472
        notEnclosing03() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   473
            // anonymous and local classes in constructor
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   474
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   475
                    info = "EnclosingConstructor in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   476
                    enclosingMethod = "<init>",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   477
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   478
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   479
            class EnclosingConstructor {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   480
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   481
            new EnclosingConstructor() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   482
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   483
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   484
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   485
        void method() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   486
            // anonymous and local classes in method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   487
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   488
                    info = "EnclosingMethod in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   489
                    enclosingMethod = "method",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   490
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   491
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   492
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   493
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   494
            new EnclosingMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   495
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   496
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   497
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   498
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   499
                info = "VariableInitializer in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   500
                enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   501
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   502
        static class VariableInitializer {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   503
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   504
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   505
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   506
        private static final VariableInitializer cvi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   507
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   508
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   509
        // instance variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   510
        private final VariableInitializer ivi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   511
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   512
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   513
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   514
    // Test cases: enclosing class is an annotation
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   515
    public @interface notEnclosing04 {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   516
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   517
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   518
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   519
                    info = "EnclosingLambda in notEnclosing04",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   520
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   521
                    enclosingClazz = notEnclosing04.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   522
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   523
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   524
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   525
            new EnclosingLambda() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   526
            };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   527
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   528
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   529
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   530
                info = "VariableInitializer in notEnclosing04",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   531
                enclosingClazz = notEnclosing04.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   532
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   533
        static class VariableInitializer {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   534
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   535
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   536
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   537
        VariableInitializer cvi = new VariableInitializer() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   538
        };
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   539
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   540
}