langtools/test/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java
author aeremeev
Tue, 12 Aug 2014 13:24:40 +0400
changeset 26101 d5dd2ecd2353
child 27552 8a4b2d3639c1
permissions -rw-r--r--
8042251: Implement classfile tests for InnerClasses attribute. Reviewed-by: jjg, anazarov, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     1
/*
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     4
 *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     8
 *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    13
 * accompanied this code).
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    14
 *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    18
 *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    21
 * questions.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    22
 */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    23
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    24
import com.sun.tools.classfile.Attribute;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    25
import com.sun.tools.classfile.ClassFile;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    26
import com.sun.tools.classfile.InnerClasses_attribute;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    27
import com.sun.tools.classfile.InnerClasses_attribute.Info;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    28
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    29
import java.util.ArrayList;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    30
import java.util.Arrays;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    31
import java.util.HashMap;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    32
import java.util.HashSet;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    33
import java.util.List;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    34
import java.util.Map;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    35
import java.util.Set;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    36
import java.util.stream.Collectors;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    37
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    38
/**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    39
 * Base class for tests of inner classes attribute.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    40
 * The scenario of tests:
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    41
 *   1. set possible values of class modifiers.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    42
 *   2. according to set class modifiers, a test generates sources
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    43
 * and golden data with {@code generateTestCases}.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    44
 *   3. a test loops through all test cases and checks InnerClasses
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    45
 * attribute with {@code test}.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    46
 *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    47
 * Example, possible flags for outer class are {@code Modifier.PRIVATE and Modifier.PUBLIC},
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    48
 * possible flags for inner class are {@code Modifier.EMPTY}.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    49
 * At the second step the test generates two test cases:
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    50
 *   1. public class A {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    51
 *        public class B {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    52
 *          class C {}
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    53
 *        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    54
 *      }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    55
 *   2. public class A {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    56
 *        private class B {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    57
 *          class C {}
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    58
 *        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    59
 *      }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    60
 */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    61
public abstract class InnerClassesTestBase extends TestResult {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    62
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    63
    private Modifier[] outerAccessModifiers = {Modifier.EMPTY, Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC};
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    64
    private Modifier[] outerOtherModifiers = {Modifier.EMPTY, Modifier.STATIC, Modifier.FINAL, Modifier.ABSTRACT};
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    65
    private Modifier[] innerAccessModifiers = outerAccessModifiers;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    66
    private Modifier[] innerOtherModifiers = outerOtherModifiers;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    67
    private boolean isForbiddenWithoutStaticInOuterMods = false;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    68
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    69
    private ClassType outerClassType;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    70
    private ClassType innerClassType;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    71
    private boolean hasSyntheticClass;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    72
    private String prefix = "";
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    73
    private String suffix = "";
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    74
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    75
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    76
     * Sets properties.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    77
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    78
     * Returns generated list of test cases. Method is called in {@code test()}.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    79
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    80
    public abstract void setProperties();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    81
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    82
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    83
     * Runs the test.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    84
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    85
     * @param classToTest expected name of outer class
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    86
     * @param skipClasses classes that names should not be checked
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    87
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    88
    public void test(String classToTest, String...skipClasses) throws TestFailedException {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    89
        try {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    90
            for (TestCase test : generateTestCases()) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    91
                addTestCase(test.getSource());
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    92
                test(classToTest, test, skipClasses);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    93
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    94
        } catch (Exception e) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    95
            addFailure(e);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    96
        } finally {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    97
            checkStatus();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    98
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
    99
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   100
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   101
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   102
     * If {@code flag} is {@code true} an outer class can not have static modifier.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   103
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   104
     * @param flag if {@code true} the outer class can not have static modifier
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   105
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   106
    public void setForbiddenWithoutStaticInOuterMods(boolean flag) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   107
        isForbiddenWithoutStaticInOuterMods = flag;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   108
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   109
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   110
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   111
     * Sets the possible access flags of an outer class.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   112
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   113
     * @param mods the possible access flags of an outer class
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   114
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   115
    public void setOuterAccessModifiers(Modifier...mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   116
        outerAccessModifiers = mods;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   117
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   118
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   119
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   120
     * Sets the possible flags of an outer class.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   121
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   122
     * @param mods the possible flags of an outer class
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   123
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   124
    public void setOuterOtherModifiers(Modifier...mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   125
        outerOtherModifiers = mods;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   126
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   127
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   128
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   129
     * Sets the possible access flags of an inner class.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   130
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   131
     * @param mods the possible access flags of an inner class
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   132
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   133
    public void setInnerAccessModifiers(Modifier...mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   134
        innerAccessModifiers = mods;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   135
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   136
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   137
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   138
     * Sets the possible flags of an inner class.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   139
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   140
     * @param mods the possible flags of an inner class
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   141
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   142
    public void setInnerOtherModifiers(Modifier...mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   143
        innerOtherModifiers = mods;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   144
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   145
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   146
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   147
     * Sets the suffix for the generated source.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   148
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   149
     * @param suffix a suffix
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   150
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   151
    public void setSuffix(String suffix) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   152
        this.suffix = suffix;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   153
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   154
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   155
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   156
     * Sets the prefix for the generated source.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   157
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   158
     * @param prefix a prefix
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   159
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   160
    public void setPrefix(String prefix) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   161
        this.prefix = prefix;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   162
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   163
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   164
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   165
     * If {@code true} synthetic class is generated.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   166
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   167
     * @param hasSyntheticClass if {@code true} synthetic class is generated
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   168
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   169
    public void setHasSyntheticClass(boolean hasSyntheticClass) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   170
        this.hasSyntheticClass = hasSyntheticClass;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   171
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   172
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   173
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   174
     * Sets the inner class type.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   175
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   176
     * @param innerClassType the inner class type
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   177
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   178
    public void setInnerClassType(ClassType innerClassType) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   179
        this.innerClassType = innerClassType;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   180
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   181
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   182
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   183
     * Sets the outer class type.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   184
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   185
     * @param outerClassType the outer class type
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   186
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   187
    public void setOuterClassType(ClassType outerClassType) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   188
        this.outerClassType = outerClassType;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   189
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   190
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   191
    private void test(String classToTest, TestCase test, String...skipClasses) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   192
        printf("Testing :\n%s\n", test.getSource());
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   193
        try {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   194
            Map<String, Set<String>> class2Flags = test.getFlags();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   195
            ClassFile cf = readClassFile(compile(test.getSource())
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   196
                    .getClasses().get(classToTest));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   197
            InnerClasses_attribute innerClasses = (InnerClasses_attribute)
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   198
                    cf.getAttribute(Attribute.InnerClasses);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   199
            int count = 0;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   200
            for (Attribute a : cf.attributes.attrs) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   201
                if (a instanceof InnerClasses_attribute) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   202
                    ++count;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   203
                }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   204
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   205
            assertEquals(1, count, "Number of inner classes attribute");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   206
            if (innerClasses == null) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   207
                return;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   208
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   209
            assertEquals(cf.constant_pool.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   210
                    getUTF8Info(innerClasses.attribute_name_index).value, "InnerClasses",
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   211
                    "innerClasses.attribute_name_index");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   212
            // Inner Classes attribute consists of length (2 bytes)
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   213
            // and 8 bytes for each inner class's entry.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   214
            assertEquals(innerClasses.attribute_length,
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   215
                    2 + 8 * class2Flags.size(), "innerClasses.attribute_length");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   216
            assertEquals(innerClasses.number_of_classes,
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   217
                    class2Flags.size(), "innerClasses.number_of_classes");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   218
            Set<String> visitedClasses = new HashSet<>();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   219
            for (Info e : innerClasses.classes) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   220
                String baseName = cf.constant_pool.getClassInfo(
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   221
                        e.inner_class_info_index).getBaseName();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   222
                if (cf.major_version >= 51 && e.inner_name_index == 0) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   223
                    assertEquals(e.outer_class_info_index, 0,
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   224
                        "outer_class_info_index "
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   225
                                + "in case of inner_name_index is zero : "
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   226
                                + baseName);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   227
                }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   228
                String className = baseName.replaceFirst(".*\\$", "");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   229
                assertTrue(class2Flags.containsKey(className),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   230
                        className);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   231
                assertTrue(visitedClasses.add(className),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   232
                        "there are no duplicates in attribute : " + className);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   233
                assertEquals(e.inner_class_access_flags.getInnerClassFlags(),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   234
                        class2Flags.get(className),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   235
                        "inner_class_access_flags " + className);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   236
                if (!Arrays.asList(skipClasses).contains(className)) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   237
                        assertEquals(
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   238
                            cf.constant_pool.getClassInfo(e.inner_class_info_index).getBaseName(),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   239
                            classToTest + "$" + className,
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   240
                            "inner_class_info_index of " + className);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   241
                    if (e.outer_class_info_index > 0) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   242
                        assertEquals(
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   243
                                cf.constant_pool.getClassInfo(e.outer_class_info_index).getName(),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   244
                                classToTest,
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   245
                                "outer_class_info_index of " + className);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   246
                    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   247
                }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   248
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   249
        } catch (Exception e) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   250
            addFailure(e);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   251
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   252
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   253
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   254
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   255
     * Methods generates list of test cases. Method generates all possible combinations
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   256
     * of acceptable flags for nested inner classes.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   257
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   258
     * @return generated list of test cases
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   259
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   260
    protected List<TestCase> generateTestCases() {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   261
        setProperties();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   262
        List<TestCase> list = new ArrayList<>();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   263
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   264
        List<List<Modifier>> outerMods = getAllCombinations(outerAccessModifiers, outerOtherModifiers);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   265
        List<List<Modifier>> innerMods = getAllCombinations(innerAccessModifiers, innerOtherModifiers);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   266
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   267
        for (List<Modifier> outerMod : outerMods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   268
            if (isForbiddenWithoutStaticInOuterMods && !outerMod.contains(Modifier.STATIC)) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   269
                continue;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   270
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   271
            StringBuilder sb = new StringBuilder();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   272
            sb.append("public class InnerClassesSrc {")
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   273
                    .append(toString(outerMod)).append(' ')
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   274
                    .append(outerClassType).append(' ')
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   275
                    .append(prefix).append(' ').append('\n');
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   276
            int count = 0;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   277
            Map<String, Set<String>> class2Flags = new HashMap<>();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   278
            List<String> syntheticClasses = new ArrayList<>();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   279
            for (List<Modifier> innerMod : innerMods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   280
                ++count;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   281
                String privateConstructor = "";
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   282
                if (hasSyntheticClass && !innerMod.contains(Modifier.ABSTRACT)) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   283
                    privateConstructor = "private A" + count + "() {}";
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   284
                    syntheticClasses.add("new A" + count + "();");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   285
                }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   286
                sb.append(toString(innerMod)).append(' ');
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   287
                sb.append(String.format("%s A%d {%s}\n", innerClassType, count, privateConstructor));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   288
                Set<String> flags = getFlags(innerClassType, innerMod);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   289
                class2Flags.put("A" + count, flags);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   290
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   291
            if (hasSyntheticClass) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   292
                // Source to generate synthetic classes
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   293
                sb.append(syntheticClasses.stream().collect(Collectors.joining(" ", "{", "}")));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   294
                class2Flags.put("1", new HashSet<>(Arrays.asList("ACC_STATIC", "ACC_SYNTHETIC")));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   295
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   296
            sb.append(suffix).append("\n}");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   297
            getAdditionalFlags(class2Flags, outerClassType, outerMod.toArray(new Modifier[outerMod.size()]));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   298
            list.add(new TestCase(sb.toString(), class2Flags));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   299
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   300
        return list;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   301
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   302
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   303
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   304
     * Methods returns flags which must have type.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   305
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   306
     * @param type class, interface, enum or annotation
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   307
     * @param mods modifiers
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   308
     * @return set of access flags
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   309
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   310
    protected Set<String> getFlags(ClassType type, List<Modifier> mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   311
        Set<String> flags = mods.stream()
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   312
                .map(Modifier::getString)
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   313
                .filter(str -> !str.isEmpty())
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   314
                .map(str -> "ACC_" + str.toUpperCase())
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   315
                .collect(Collectors.toSet());
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   316
        type.addSpecificFlags(flags);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   317
        return flags;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   318
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   319
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   320
    private List<List<Modifier>> getAllCombinations(Modifier[] accessModifiers, Modifier[] otherModifiers) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   321
        List<List<Modifier>> list = new ArrayList<>();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   322
        for (Modifier access : accessModifiers) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   323
            for (int i = 0; i < otherModifiers.length; ++i) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   324
                Modifier mod1 = otherModifiers[i];
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   325
                for (int j = i + 1; j < otherModifiers.length; ++j) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   326
                    Modifier mod2 = otherModifiers[j];
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   327
                    if (isForbidden(mod1, mod2)) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   328
                        continue;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   329
                    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   330
                    list.add(Arrays.asList(access, mod1, mod2));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   331
                }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   332
                if (mod1 == Modifier.EMPTY) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   333
                    list.add(Arrays.asList(access));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   334
                }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   335
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   336
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   337
        return list;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   338
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   339
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   340
    private boolean isForbidden(Modifier mod1, Modifier mod2) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   341
        return mod1 == Modifier.FINAL && mod2 == Modifier.ABSTRACT
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   342
                || mod1 == Modifier.ABSTRACT && mod2 == Modifier.FINAL;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   343
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   344
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   345
    private String toString(List<Modifier> mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   346
        return mods.stream()
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   347
                .map(Modifier::getString)
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   348
                .filter(s -> !s.isEmpty())
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   349
                .collect(Collectors.joining(" "));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   350
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   351
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   352
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   353
     * Method is called in generateTestCases().
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   354
     * If you need to add additional access flags, you should override this method.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   355
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   356
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   357
     * @param class2Flags map with flags
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   358
     * @param type class, interface, enum or @annotation
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   359
     * @param mods modifiers
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   360
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   361
    public void getAdditionalFlags(Map<String, Set<String>> class2Flags, ClassType type, Modifier...mods) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   362
        class2Flags.values().forEach(type::addFlags);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   363
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   364
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   365
    public enum ClassType {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   366
        CLASS("class") {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   367
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   368
            public void addSpecificFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   369
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   370
        },
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   371
        INTERFACE("interface") {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   372
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   373
            public void addFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   374
                flags.add("ACC_STATIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   375
                flags.add("ACC_PUBLIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   376
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   377
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   378
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   379
            public void addSpecificFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   380
                flags.add("ACC_INTERFACE");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   381
                flags.add("ACC_ABSTRACT");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   382
                flags.add("ACC_STATIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   383
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   384
        },
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   385
        ANNOTATION("@interface") {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   386
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   387
            public void addFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   388
                flags.add("ACC_STATIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   389
                flags.add("ACC_PUBLIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   390
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   391
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   392
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   393
            public void addSpecificFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   394
                flags.add("ACC_INTERFACE");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   395
                flags.add("ACC_ABSTRACT");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   396
                flags.add("ACC_STATIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   397
                flags.add("ACC_ANNOTATION");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   398
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   399
        },
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   400
        ENUM("enum") {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   401
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   402
            public void addSpecificFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   403
                flags.add("ACC_ENUM");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   404
                flags.add("ACC_FINAL");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   405
                flags.add("ACC_STATIC");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   406
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   407
        },
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   408
        OTHER("") {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   409
            @Override
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   410
            public void addSpecificFlags(Set<String> flags) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   411
            }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   412
        };
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   413
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   414
        private final String classType;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   415
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   416
        private ClassType(String clazz) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   417
            this.classType = clazz;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   418
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   419
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   420
        public abstract void addSpecificFlags(Set<String> flags);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   421
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   422
        public String toString() {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   423
            return classType;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   424
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   425
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   426
        public void addFlags(Set<String> set) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   427
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   428
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   429
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   430
    public enum Modifier {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   431
        PUBLIC("public"), PRIVATE("private"),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   432
        PROTECTED("protected"), DEFAULT("default"),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   433
        FINAL("final"), ABSTRACT("abstract"),
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   434
        STATIC("static"), EMPTY("");
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   435
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   436
        private final String str;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   437
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   438
        private Modifier(String str) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   439
            this.str = str;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   440
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   441
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   442
        public String getString() {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   443
            return str;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   444
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   445
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff changeset
   446
}