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 3517c3511..8293fd4b0 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,7 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) { } catch (ReflectiveOperationException e1) { try { Tree type = (Tree) BindingPatternTree.class.getMethod("getType").invoke(node); - Name name = (Name) BindingPatternTree.class.getMethod("getName").invoke(node); + Name name = (Name) BindingPatternTree.class.getMethod("getBinding").invoke(node); visitBindingPattern(/* modifiers= */ null, type, name); } catch (ReflectiveOperationException e2) { e2.addSuppressed(e1); diff --git a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java index b6549f4a8..31d59f171 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java @@ -48,7 +48,7 @@ public class FormatterIntegrationTest { private static final ImmutableSet JAVA14_TESTS = - ImmutableSet.of("I477", "Records", "RSLs", "Var", "ExpressionSwitch", "I574"); + ImmutableSet.of("I477", "Records", "RSLs", "Var", "ExpressionSwitch", "I574", "I594"); private static final ImmutableSet JAVA16_TESTS = ImmutableSet.of("I588"); diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I594.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I594.input new file mode 100644 index 000000000..98f667e39 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I594.input @@ -0,0 +1,7 @@ +public class I594 { + public void thisIsNotFormattedCorrectly(Object something){ + if(something instanceof String somethingAsString){ + return; + } + } +} diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I594.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I594.output new file mode 100644 index 000000000..7c519a2d9 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I594.output @@ -0,0 +1,7 @@ +public class I594 { + public void thisIsNotFormattedCorrectly(Object something) { + if (something instanceof String somethingAsString) { + return; + } + } +}