langtools/test/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
child 35359 f04501964016
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
     2
 * Copyright (c) 2014, 2015, 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
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.classfile
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.main
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    33
 * @build EnclosingMethodTest TestBase TestResult InMemoryFileManager ToolBox
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    34
 * @run main EnclosingMethodTest
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    37
import com.sun.tools.classfile.Attribute;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    38
import com.sun.tools.classfile.ClassFile;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    39
import com.sun.tools.classfile.EnclosingMethod_attribute;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    40
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    41
import java.io.File;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    42
import java.io.FilenameFilter;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    43
import java.lang.annotation.Retention;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    44
import java.lang.annotation.RetentionPolicy;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    45
import java.util.HashMap;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    46
import java.util.HashSet;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    47
import java.util.Map;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    48
import java.util.Set;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    49
import java.util.stream.Stream;
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
/**
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    52
 * The test checks the enclosing method attribute of anonymous/local classes.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    53
 * 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
    54
 * 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
    55
 * Golden information about enclosing methods are held in annotation {@code ExpectedEnclosingMethod}.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    56
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    57
 * 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
    58
 * 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
    59
 * named {@code VariableInitializer} are introduced to test variable initializer cases. These classes
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    60
 * 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
    61
 * 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
    62
 * 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
    63
 * the EnclosingMethod attribute, otherwise.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    64
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    65
 * Test cases:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    66
 *   top-level class as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    67
 *     1. anonymous and local classes in static initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    68
 *     2. anonymous and local classes in instance initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    69
 *     3. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    70
 *     4. anonymous and local classes in constructor;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    71
 *     5. anonymous and local classes in method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    72
 *     6. static and instance variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    73
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    74
 *   inner class as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    75
 *     1. anonymous and local classes in static initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    76
 *     2. anonymous and local classes in instance initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    77
 *     3. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    78
 *     4. anonymous and local classes in constructor;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    79
 *     5. anonymous and local classes in method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    80
 *     6. static and instance variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    81
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    82
 *   enum as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    83
 *     1. anonymous and local classes in static initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    84
 *     2. anonymous and local classes in instance initializer;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    85
 *     3. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    86
 *     4. anonymous and local classes in constructor;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    87
 *     5. anonymous and local classes in method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    88
 *     6. static and instance variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    89
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    90
 *   interface as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    91
 *     1. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    92
 *     2. anonymous and local classes in static method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    93
 *     3. anonymous and local classes in default method;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    94
 *     4. static variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    95
 *
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    96
 *   annotation as enclosing class:
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    97
 *     1. anonymous and local classes in lambda;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    98
 *     2. static variable initializer.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
    99
 */
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   100
public class EnclosingMethodTest extends TestResult {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   101
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   102
    private final Map<Class<?>, ExpectedEnclosingMethod> class2EnclosingMethod = new HashMap<>();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   103
    private final Set<Class<?>> noEnclosingMethod = new HashSet<>();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   104
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   105
    public EnclosingMethodTest() throws ClassNotFoundException {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   106
        Class<EnclosingMethodTest> outerClass = EnclosingMethodTest.class;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   107
        String outerClassName = outerClass.getSimpleName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   108
        File testClasses = getClassDir();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   109
        FilenameFilter filter = (dir, name) -> name.matches(outerClassName + ".*\\.class");
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   110
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   111
        for (File file : testClasses.listFiles(filter)) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   112
            Class<?> clazz = Class.forName(file.getName().replace(".class", ""));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   113
            if (clazz.isAnonymousClass()) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   114
                // anonymous class cannot be annotated, information is in its parent class.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   115
                ExpectedEnclosingMethod declaredAnnotation =
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   116
                        clazz.getSuperclass().getDeclaredAnnotation(ExpectedEnclosingMethod.class);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   117
                class2EnclosingMethod.put(clazz, declaredAnnotation);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   118
            } else {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   119
                ExpectedEnclosingMethod enclosingMethod = clazz.getDeclaredAnnotation(ExpectedEnclosingMethod.class);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   120
                // 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
   121
                // then it must have the enclosing method attribute.
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   122
                if (enclosingMethod != null && !clazz.getSimpleName().contains("VariableInitializer")) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   123
                    class2EnclosingMethod.put(clazz, enclosingMethod);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   124
                } else {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   125
                    noEnclosingMethod.add(clazz);
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   131
    public void test() throws TestFailedException {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   132
        try {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   133
            testEnclosingMethodAttribute();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   134
            testLackOfEnclosingMethodAttribute();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   135
        } finally {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   136
            checkStatus();
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   140
    private void testLackOfEnclosingMethodAttribute() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   141
        for (Class<?> clazz : noEnclosingMethod) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   142
            try {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   143
                addTestCase("Class should not have EnclosingMethod attribute : " + clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   144
                ClassFile classFile = readClassFile(clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   145
                checkEquals(countEnclosingMethodAttributes(classFile),
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   146
                        0l, "number of the EnclosingMethod attribute in the class is zero : "
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   147
                                + classFile.getName());
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   148
            } catch (Exception e) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   149
                addFailure(e);
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   154
    private void testEnclosingMethodAttribute() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   155
        class2EnclosingMethod.forEach((clazz, enclosingMethod) -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   156
            try {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   157
                String info = enclosingMethod.info() + " "
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   158
                        + (clazz.isAnonymousClass() ? "anonymous" : "local");
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   159
                addTestCase(info);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   160
                printf("Testing test case : %s\n", info);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   161
                ClassFile classFile = readClassFile(clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   162
                String className = clazz.getName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   163
                checkEquals(countEnclosingMethodAttributes(classFile), 1l,
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   164
                        "number of the EnclosingMethod attribute in the class is one : "
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   165
                                + clazz);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   166
                EnclosingMethod_attribute attr = (EnclosingMethod_attribute)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   167
                        classFile.getAttribute(Attribute.EnclosingMethod);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   168
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   169
                if (!checkNotNull(attr, "the EnclosingMethod attribute is not null : " + className)) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   170
                    // stop checking, attr is null. test case failed
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   171
                    return;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   172
                }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   173
                checkEquals(classFile.constant_pool.getUTF8Value(attr.attribute_name_index),
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   174
                        "EnclosingMethod",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   175
                        "attribute_name_index of EnclosingMethod attribute in the class : " + className);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   176
                checkEquals(attr.attribute_length, 4,
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   177
                        "attribute_length of EnclosingMethod attribute in the class : " + className);
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   178
                String expectedClassName = enclosingMethod.enclosingClazz().getName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   179
                checkEquals(classFile.constant_pool.getClassInfo(attr.class_index).getName(),
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   180
                        expectedClassName, String.format(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   181
                        "enclosing class of EnclosingMethod attribute in the class %s is %s",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   182
                                className, expectedClassName));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   183
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   184
                String expectedMethodName = enclosingMethod.enclosingMethod();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   185
                if (expectedMethodName.isEmpty()) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   186
                    // class does not have an enclosing method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   187
                    checkEquals(attr.method_index, 0, String.format(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   188
                            "enclosing method of EnclosingMethod attribute in the class %s is null", className));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   189
                } else {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   190
                    String methodName = classFile.constant_pool.getNameAndTypeInfo(attr.method_index).getName();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   191
                    checkTrue(methodName.startsWith(expectedMethodName), String.format(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   192
                            "enclosing method of EnclosingMethod attribute in the class %s" +
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   193
                                    " is method name %s" +
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   194
                                    ", actual method name is %s",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   195
                            className, expectedMethodName, methodName));
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   196
                }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   197
            } catch (Exception e) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   198
                addFailure(e);
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   203
    private long countEnclosingMethodAttributes(ClassFile classFile) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   204
        return Stream.of(classFile.attributes.attrs)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   205
                .filter(x -> x instanceof EnclosingMethod_attribute)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   206
                .count();
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   209
    @Retention(RetentionPolicy.RUNTIME)
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   210
    public @interface ExpectedEnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   211
        String info();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   212
        Class<?> enclosingClazz();
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   213
        String enclosingMethod() default "";
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   216
    public static void main(String[] args) throws ClassNotFoundException, TestFailedException {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   217
        new EnclosingMethodTest().test();
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   220
    // Test cases: enclosing class is a top-level class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   221
    static {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   222
        // anonymous and local classes in static initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   223
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   224
                info = "EnclosingStaticInitialization in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   225
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   226
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   227
        class EnclosingStaticInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   228
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   229
        new EnclosingStaticInitialization() {
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
    {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   234
        // anonymous and local classes in instance initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   235
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   236
                info = "EnclosingInitialization in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   237
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   238
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   239
        class EnclosingInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   240
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   241
        new EnclosingInitialization() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   245
    Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   246
        // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   247
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   248
                info = "EnclosingLambda in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   249
                enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   250
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   251
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   252
        class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   253
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   254
        new EnclosingLambda() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   258
    EnclosingMethodTest(int i) {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   259
        // anonymous and local classes in constructor
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   260
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   261
                info = "EnclosingConstructor in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   262
                enclosingMethod = "<init>",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   263
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   264
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   265
        class EnclosingConstructor {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   266
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   267
        new EnclosingConstructor() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   271
    void method() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   272
        // anonymous and local classes in method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   273
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   274
                info = "EnclosingMethod in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   275
                enclosingMethod = "method",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   276
                enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   277
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   278
        class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   279
        }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   280
        new EnclosingMethod() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   284
    @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   285
            info = "VariableInitializer in EnclosingMethodTest",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   286
            enclosingClazz = EnclosingMethodTest.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   287
    )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   288
    static class VariableInitializer {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   291
    // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   292
    private static final VariableInitializer cvi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   295
    // instance variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   296
    private final VariableInitializer ivi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   299
    // Test cases: enclosing class is an inner class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   300
    public static class notEnclosing01 {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   301
        static {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   302
            // anonymous and local classes in static initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   303
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   304
                    info = "EnclosingStaticInitialization in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   305
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   306
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   307
            class EnclosingStaticInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   308
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   309
            new EnclosingStaticInitialization() {
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
        {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   314
            // anonymous and local classes in instance initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   315
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   316
                    info = "EnclosingInitialization in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   317
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   318
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   319
            class EnclosingInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   320
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   321
            new EnclosingInitialization() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   325
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   326
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   327
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   328
                    info = "EnclosingLambda in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   329
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   330
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   331
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   332
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   333
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   334
            new EnclosingLambda() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   338
        notEnclosing01() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   339
            // anonymous and local classes in constructor
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   340
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   341
                    info = "EnclosingConstructor in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   342
                    enclosingMethod = "<init>",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   343
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   344
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   345
            class EnclosingConstructor {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   346
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   347
            new EnclosingConstructor() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   351
        void method() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   352
            // anonymous and local classes in method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   353
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   354
                    info = "EnclosingMethod in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   355
                    enclosingMethod = "method",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   356
                    enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   357
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   358
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   359
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   360
            new EnclosingMethod() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   364
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   365
                info = "VariableInitializer in notEnclosing01",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   366
                enclosingClazz = notEnclosing01.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   367
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   368
        static class VariableInitializer {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   371
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   372
        private static final VariableInitializer cvi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   375
        // instance variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   376
        private final VariableInitializer ivi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   380
    // Test cases: enclosing class is an interface
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   381
    public interface notEnclosing02 {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   382
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   383
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   384
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   385
                    info = "EnclosingLambda in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   386
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   387
                    enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   388
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   389
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   390
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   391
            new EnclosingLambda() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   395
        static void staticMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   396
            // anonymous and local classes in static method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   397
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   398
                    info = "EnclosingMethod in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   399
                    enclosingMethod = "staticMethod",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   400
                    enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   401
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   402
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   403
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   404
            new EnclosingMethod() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   408
        default void defaultMethod() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   409
            // anonymous and local classes in default method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   410
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   411
                    info = "EnclosingMethod in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   412
                    enclosingMethod = "defaultMethod",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   413
                    enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   414
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   415
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   416
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   417
            new EnclosingMethod() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   421
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   422
                info = "VariableInitializer in notEnclosing02",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   423
                enclosingClazz = notEnclosing02.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   424
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   425
        static class VariableInitializer {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   428
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   429
        VariableInitializer cvi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   433
    // Test cases: enclosing class is an enum
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   434
    public enum notEnclosing03 {;
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   435
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   436
        static {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   437
            // anonymous and local classes in static initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   438
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   439
                    info = "EnclosingStaticInitialization in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   440
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   441
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   442
            class EnclosingStaticInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   443
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   444
            new EnclosingStaticInitialization() {
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
        {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   449
            // anonymous and local classes in instance initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   450
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   451
                    info = "EnclosingInitialization in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   452
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   453
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   454
            class EnclosingInitialization {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   455
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   456
            new EnclosingInitialization() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   460
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   461
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   462
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   463
                    info = "EnclosingLambda in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   464
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   465
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   466
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   467
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   468
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   469
            new EnclosingLambda() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   473
        notEnclosing03() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   474
            // anonymous and local classes in constructor
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   475
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   476
                    info = "EnclosingConstructor in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   477
                    enclosingMethod = "<init>",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   478
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   479
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   480
            class EnclosingConstructor {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   481
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   482
            new EnclosingConstructor() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   486
        void method() {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   487
            // anonymous and local classes in method
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   488
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   489
                    info = "EnclosingMethod in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   490
                    enclosingMethod = "method",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   491
                    enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   492
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   493
            class EnclosingMethod {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   494
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   495
            new EnclosingMethod() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   499
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   500
                info = "VariableInitializer in notEnclosing03",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   501
                enclosingClazz = notEnclosing03.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   502
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   503
        static class VariableInitializer {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   506
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   507
        private static final VariableInitializer cvi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   510
        // instance variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   511
        private final VariableInitializer ivi = new VariableInitializer() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   515
    // Test cases: enclosing class is an annotation
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   516
    public @interface notEnclosing04 {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   517
        Runnable lambda = () -> {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   518
            // anonymous and local classes in lambda
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   519
            @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   520
                    info = "EnclosingLambda in notEnclosing04",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   521
                    enclosingMethod = "lambda",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   522
                    enclosingClazz = notEnclosing04.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   523
            )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   524
            class EnclosingLambda {
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   525
            }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   526
            new EnclosingLambda() {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   530
        @ExpectedEnclosingMethod(
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   531
                info = "VariableInitializer in notEnclosing04",
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   532
                enclosingClazz = notEnclosing04.class
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   533
        )
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   534
        static class VariableInitializer {
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
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   537
        // static variable initializer
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   538
        VariableInitializer cvi = new VariableInitializer() {
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
    }
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents:
diff changeset
   541
}