50 " case null: i++; break LABEL;" +
51 " default: i++; break;" +
52 " }" +
53 " }" +
54 " int t2(Integer i) {" +
55 " return switch (i) {" +
56 " case null: break LABEL;" +
57 " default: yield 2;" +
58 " }" +
59 " }" +
60 "}";
61
62 public static void main(String[] args) throws Exception {
63 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
64 String sourceVersion = Integer.toString(Runtime.version().feature());
65 assert tool != null;
66 DiagnosticListener<JavaFileObject> noErrors = d -> {};
67
68 StringWriter out = new StringWriter();
69 JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
70 List.of("-XDdev", "--enable-preview", "-source", sourceVersion), null,
71 Arrays.asList(new MyFileObject(CODE)));
72 List<String> labels = new ArrayList<>();
73 new TreePathScanner<Void, Void>() {
74 @Override
75 public Void visitBreak(BreakTree node, Void p) {
76 Name label = node.getLabel();
77 labels.add(label != null ? label.toString() : null);
78 return super.visitBreak(node, p);
79 }
80 }.scan(ct.parse(), null);
81
82 List<String> expected = Arrays.asList("LABEL", null, "LABEL");
83
84 if (!expected.equals(labels)) {
85 throw new AssertionError("Unexpected labels found: " + labels);
86 }
87 }
88
89 static class MyFileObject extends SimpleJavaFileObject {
90 private String text;
|
50 " case null: i++; break LABEL;" +
51 " default: i++; break;" +
52 " }" +
53 " }" +
54 " int t2(Integer i) {" +
55 " return switch (i) {" +
56 " case null: break LABEL;" +
57 " default: yield 2;" +
58 " }" +
59 " }" +
60 "}";
61
62 public static void main(String[] args) throws Exception {
63 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
64 String sourceVersion = Integer.toString(Runtime.version().feature());
65 assert tool != null;
66 DiagnosticListener<JavaFileObject> noErrors = d -> {};
67
68 StringWriter out = new StringWriter();
69 JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
70 List.of("-XDdev"), null,
71 Arrays.asList(new MyFileObject(CODE)));
72 List<String> labels = new ArrayList<>();
73 new TreePathScanner<Void, Void>() {
74 @Override
75 public Void visitBreak(BreakTree node, Void p) {
76 Name label = node.getLabel();
77 labels.add(label != null ? label.toString() : null);
78 return super.visitBreak(node, p);
79 }
80 }.scan(ct.parse(), null);
81
82 List<String> expected = Arrays.asList("LABEL", null, "LABEL");
83
84 if (!expected.equals(labels)) {
85 throw new AssertionError("Unexpected labels found: " + labels);
86 }
87 }
88
89 static class MyFileObject extends SimpleJavaFileObject {
90 private String text;
|