1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
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 /* @test
25 * @bug 8034854
26 * @summary Verify that nested enums have correct abstract flag in the InnerClasses attribute.
27 * @library /tools/lib
28 * @modules jdk.compiler/com.sun.tools.javac.api
29 * jdk.compiler/com.sun.tools.javac.main
30 * jdk.compiler/com.sun.tools.javac.util
31 * @build toolbox.ToolBox toolbox.JavacTask
32 * @build T8068517
33 * @run main T8068517
34 */
35
36 import com.sun.tools.javac.util.Assert;
37 import java.util.Arrays;
38 import javax.tools.JavaFileManager;
39 import javax.tools.StandardLocation;
40 import javax.tools.ToolProvider;
41
42 import toolbox.JavacTask;
43 import toolbox.ToolBox;
44
45 public class T8068517 {
46
47 public static void main(String[] args) throws Exception {
48 new T8068517().run();
49 }
50
51 void run() throws Exception {
52 runTest("class A {\n" +
53 " enum AInner implements Runnable {\n" +
54 " A {\n" +
55 " public void run() {}\n" +
56 " };\n" +
57 " }\n" +
58 "}\n",
59 "class B {\n" +
60 " A.AInner a;\n" +
61 "}");
62 runTest("class A {\n" +
63 " enum AInner implements Runnable {\n" +
64 " A {\n" +
65 " public void run() {}\n" +
66 " };\n" +
67 " }\n" +
68 " AInner aInner;\n" +
69 "}\n",
70 "class B {\n" +
71 " void test(A a) {;\n" +
72 " switch (a.aInner) {\n" +
73 " case A: break;\n" +
74 " }\n" +
75 " };\n" +
76 "}");
77 runTest("class A {\n" +
78 " enum AInner implements Runnable {\n" +
79 " A {\n" +
80 " public void run() {}\n" +
81 " };\n" +
82 " }\n" +
83 " AInner aInner;\n" +
84 "}\n",
85 "class B {\n" +
86 " void test(A a) {;\n" +
87 " System.err.println(a.aInner.toString());\n" +
88 " };\n" +
89 "}");
90 runTest("class A {\n" +
91 " enum AInner implements Runnable {\n" +
92 " A {\n" +
93 " public void run() {}\n" +
94 " };\n" +
95 " }\n" +
96 " AInner aInner() {\n" +
97 " return null;\n" +
98 " }\n" +
99 "}\n",
100 "class B {\n" +
101 " void test(A a) {;\n" +
102 " System.err.println(a.aInner().toString());\n" +
103 " };\n" +
104 "}");
105 }
106
107 void runTest(String aJava, String bJava) throws Exception {
108 try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
109 ToolBox tb = new ToolBox();
110 try (var memoryFM1 = new ToolBox.MemoryFileManager(fm, false);
111 var memoryFM2 = new ToolBox.MemoryFileManager(fm, false)) {
112 new JavacTask(tb).fileManager(memoryFM1)
113 .sources(aJava, bJava)
114 .run();
115 new JavacTask(tb).fileManager(memoryFM2)
116 .sources(bJava, aJava)
117 .run();
118
119 Assert.check(Arrays.equals(memoryFM1.getFileBytes(StandardLocation.CLASS_OUTPUT, "B"),
120 memoryFM2.getFileBytes(StandardLocation.CLASS_OUTPUT, "B")));
121 }
122 }
123 }
124 }