9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8042251
27 * @summary Testing InnerClasses_attribute of inner classes in local class.
28 * @library /tools/lib /tools/javac/lib ../lib
29 * @modules java.base/jdk.internal.classfile.impl
30 * jdk.compiler/com.sun.tools.javac.api
31 * jdk.compiler/com.sun.tools.javac.main
32 * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
33 * @build InnerClassesTestBase
34 * @run main InnerClassesInLocalClassTest
35 */
36
37 import java.util.*;
38
39 public class InnerClassesInLocalClassTest extends InnerClassesTestBase {
40
41 private final static Modifier[] LOCAL_CLASS_MODIFIERS =
42 new Modifier[]{Modifier.EMPTY, Modifier.ABSTRACT, Modifier.FINAL};
43 private final static String CLASS_TEMPLATE =
44 "public %CLASS% OuterClass {\n" +
45 "%SOURCE%\n" +
46 "}";
47
48 private final List<Data> innerClassesData;
49
50 public InnerClassesInLocalClassTest() {
51 innerClassesData = new ArrayList<>();
52 for (Modifier outerModifier : LOCAL_CLASS_MODIFIERS) {
53 StringBuilder sb = new StringBuilder();
54 sb.append(outerModifier.getString()).append(' ');
55 sb.append("class Local {");
56 Map<String, Set<String>> class2Flags = new HashMap<>();
57 for (int i = 0; i < LOCAL_CLASS_MODIFIERS.length; ++i) {
58 Modifier innerModifier = LOCAL_CLASS_MODIFIERS[i];
59 sb.append(innerModifier.getString()).append(' ')
60 .append("class").append(' ')
61 .append('A').append(i).append("{}\n");
62 class2Flags.put("A" + i, getFlags(innerModifier));
63 }
64 sb.append("};");
65 class2Flags.put("1Local", getFlags(outerModifier));
66 innerClassesData.add(new Data(sb.toString(), class2Flags));
67 }
68 }
69
70 public static void main(String[] args) throws TestFailedException {
71 InnerClassesTestBase test = new InnerClassesInLocalClassTest();
72 test.test("OuterClass$1Local", "1Local");
73 }
74
75 @Override
133 list.addAll(generate(template,
134 String.format("%s %s void method() {",
135 modifier.getString(),
136 otherMod.getString()),
137 "}"));
138 }
139 }
140 return list;
141 }
142
143 private List<TestCase> staticAndInstanceInitializer(String template) {
144 List<TestCase> list = new ArrayList<>();
145 for (Modifier modifier : new Modifier[]{Modifier.EMPTY, Modifier.STATIC}) {
146 list.addAll(generate(template, modifier.getString() + "{", "}"));
147 }
148 return list;
149 }
150
151 private Set<String> getFlags(Modifier modifier) {
152 HashSet<String> set = new HashSet<>();
153 if (modifier != Modifier.EMPTY) {
154 set.add("ACC_" + modifier.getString().toUpperCase());
155 }
156 return set;
157 }
158
159 /**
160 * Class represents part of sources which is inserted in other code.
161 */
162 private static class Data {
163 public final String sources;
164 public final Map<String, Set<String>> class2Flags;
165
166 public Data(String sources, Map<String, Set<String>> class2Flags) {
167 this.sources = sources;
168 this.class2Flags = class2Flags;
169 }
170 }
171 }
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8042251
27 * @summary Testing InnerClasses_attribute of inner classes in local class.
28 * @library /tools/lib /tools/javac/lib ../lib
29 * @enablePreview
30 * @modules java.base/jdk.internal.classfile.impl
31 * jdk.compiler/com.sun.tools.javac.api
32 * jdk.compiler/com.sun.tools.javac.main
33 * @enablePreview
34 * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
35 * @build InnerClassesTestBase
36 * @run main InnerClassesInLocalClassTest
37 */
38
39 import java.util.*;
40
41 public class InnerClassesInLocalClassTest extends InnerClassesTestBase {
42
43 private final static Modifier[] LOCAL_CLASS_MODIFIERS =
44 new Modifier[]{Modifier.EMPTY, Modifier.ABSTRACT, Modifier.FINAL};
45 private final static String CLASS_TEMPLATE =
46 "public %CLASS% OuterClass {\n" +
47 "%SOURCE%\n" +
48 "}";
49
50 private final List<Data> innerClassesData;
51
52 public InnerClassesInLocalClassTest() {
53 innerClassesData = new ArrayList<>();
54 for (Modifier outerModifier : LOCAL_CLASS_MODIFIERS) {
55 StringBuilder sb = new StringBuilder();
56 sb.append(outerModifier.getString()).append(' ');
57 sb.append("class Local { int f; "); // impose identity to make testing predictable.
58 Map<String, Set<String>> class2Flags = new HashMap<>();
59 for (int i = 0; i < LOCAL_CLASS_MODIFIERS.length; ++i) {
60 Modifier innerModifier = LOCAL_CLASS_MODIFIERS[i];
61 sb.append(innerModifier.getString()).append(' ')
62 .append("class").append(' ')
63 .append('A').append(i).append("{}\n");
64 class2Flags.put("A" + i, getFlags(innerModifier));
65 }
66 sb.append("};");
67 class2Flags.put("1Local", getFlags(outerModifier));
68 innerClassesData.add(new Data(sb.toString(), class2Flags));
69 }
70 }
71
72 public static void main(String[] args) throws TestFailedException {
73 InnerClassesTestBase test = new InnerClassesInLocalClassTest();
74 test.test("OuterClass$1Local", "1Local");
75 }
76
77 @Override
135 list.addAll(generate(template,
136 String.format("%s %s void method() {",
137 modifier.getString(),
138 otherMod.getString()),
139 "}"));
140 }
141 }
142 return list;
143 }
144
145 private List<TestCase> staticAndInstanceInitializer(String template) {
146 List<TestCase> list = new ArrayList<>();
147 for (Modifier modifier : new Modifier[]{Modifier.EMPTY, Modifier.STATIC}) {
148 list.addAll(generate(template, modifier.getString() + "{", "}"));
149 }
150 return list;
151 }
152
153 private Set<String> getFlags(Modifier modifier) {
154 HashSet<String> set = new HashSet<>();
155 set.add("ACC_IDENTITY");
156 if (modifier != Modifier.EMPTY) {
157 set.add("ACC_" + modifier.getString().toUpperCase());
158 }
159 return set;
160 }
161
162 /**
163 * Class represents part of sources which is inserted in other code.
164 */
165 private static class Data {
166 public final String sources;
167 public final Map<String, Set<String>> class2Flags;
168
169 public Data(String sources, Map<String, Set<String>> class2Flags) {
170 this.sources = sources;
171 this.class2Flags = class2Flags;
172 }
173 }
174 }
|