2
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
27
* @summary Check javac can generate code for protected enums accessible through subclassing.
29
* @modules jdk.compiler/com.sun.tools.javac.api
30
* jdk.compiler/com.sun.tools.javac.main
31
* jdk.compiler/com.sun.tools.javac.util
32
* @build toolbox.ToolBox toolbox.JavacTask
33
* @run main EnumAccessible
36
import java.nio.file.Files;
37
import java.nio.file.Path;
38
import java.nio.file.Paths;
40
import java.util.Objects;
42
import toolbox.TestRunner;
43
import toolbox.JavacTask;
44
import toolbox.JavaTask;
46
import toolbox.ToolBox;
48
public class EnumAccessible extends TestRunner {
52
public static void main(String... args) throws Exception {
53
new EnumAccessible().runTests();
61
public void runTests() throws Exception {
62
runTests(m -> new Object[] { Paths.get(m.getName()) });
66
public void testPattern(Path base) throws Exception {
67
Path current = base.resolve(".");
68
Path src = current.resolve("src");
69
Path classes = current.resolve("classes");
70
tb.writeJavaFiles(src,
75
public static class B {
80
public static void main(String... args) {
89
public static class E extends B {
90
public void run(C arg) {
92
default: System.out.println("OK");
99
Files.createDirectories(classes);
104
.files(tb.findJavaFiles(src))
105
.run(Task.Expect.SUCCESS)
108
var out = new JavaTask(tb)
109
.classpath(classes.toString())
113
.getOutputLines(Task.OutputKind.STDOUT);
115
var expectedOut = List.of("OK");
117
if (!Objects.equals(expectedOut, out)) {
118
throw new AssertionError("Incorrect Output, expected: " + expectedOut +