From b46d1f0f2526044676e7ed5cca07a6f745772c0d Mon Sep 17 00:00:00 2001 From: Tim Koopman Date: Wed, 27 May 2020 21:25:31 +0800 Subject: [PATCH] Add support for yield statement --- .../java/java14/Java14InputAstVisitor.java | 6 ++++- .../java/testdata/java14.input | 19 ++++++++++++++ .../java/testdata/java14.output | 25 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java index 6585c6f6e..78cfd66b1 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java @@ -60,7 +60,11 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) { @Override public Void visitYield(YieldTree node, Void aVoid) { sync(node); - return super.visitYield(node, aVoid); + token("yield"); + builder.space(); + scan(node.getValue(), null); + token(";"); + return null; } @Override diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.input index 10d45221b..5c8027791 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.input +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.input @@ -47,4 +47,23 @@ class Java14 { { for (var arg : List.of()) {} } + + { + int f = switch (i) { + case 0 -> 0; + default -> { + yield n / i; + } + }; + + int g = switch (i) { + case 0: yield 0; + default: yield n/i; + }; + + switch (i) { + case 0 -> { System.out.println("0"); } + default -> System.out.println("default"); + } + } } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.output index 9779198b1..d0d9f6722 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/java14.output @@ -48,4 +48,29 @@ class Java14 { { for (var arg : List.of()) {} } + + { + int f = + switch (i) { + case 0 -> 0; + default -> { + yield n / i; + } + }; + + int g = + switch (i) { + case 0: + yield 0; + default: + yield n / i; + }; + + switch (i) { + case 0 -> { + System.out.println("0"); + } + default -> System.out.println("default"); + } + } }