From 7928cf4ba05e3b9e858be655dc43e60f0335dacd Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Fri, 26 Aug 2022 00:53:21 +0200 Subject: [jdk19] Add support for new guard pattern --- test/pretty/resource/before/Switch19.java | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/pretty/resource/before/Switch19.java (limited to 'test/pretty/resource/before/Switch19.java') diff --git a/test/pretty/resource/before/Switch19.java b/test/pretty/resource/before/Switch19.java new file mode 100644 index 00000000..05b27928 --- /dev/null +++ b/test/pretty/resource/before/Switch19.java @@ -0,0 +1,33 @@ +// version 19: +public class Switch19 { + String switchPatternMatching(Object o) { + return switch (o) { + case Integer i -> String.format("int %d", i); + case Long l -> String.format("long %d", l); + case Double d -> String.format("double %f", d); + case String s -> String.format("String %s", s); + default -> o.toString(); + }; + } + + String switchNull(Object o) { + return switch (o) { + case null, default -> "?"; + }; + } + + String switchGuardPattern(Object o) { + return switch (o) { + case String s when s.length() > 1 -> s; + case String s -> s; + default -> o.toString(); + }; + } + + String switchParenthesizedPattern(Object o) { + return switch (o) { + case (String s) -> s; + default -> o.toString(); + }; + } +} -- cgit