From acfe9c5c34e7be0ce46fb79aea4d6f4597ff6767 Mon Sep 17 00:00:00 2001 From: cushon Date: Thu, 19 Dec 2019 14:46:50 -0800 Subject: [PATCH 1/2] Fix a crash on c-style arrays in parameters Fixes https://github.com/google/google-java-format/issues/374 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=286467734 --- .../googlejavaformat/java/JavaInputAstVisitor.java | 6 ++++-- .../com/google/googlejavaformat/java/testdata/I374.input | 9 +++++++++ .../google/googlejavaformat/java/testdata/I374.output | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.input create mode 100644 core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.output diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index c0f645654..b3f6e5ade 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -2542,18 +2542,20 @@ private void visitToDeclare( String equals, Optional trailing) { sync(node); + TypeWithDims extractedDims = DimensionHelpers.extractDims(node.getType(), SortedDims.YES); + Optional typeWithDims = Optional.of(extractedDims); declareOne( kind, annotationsDirection, Optional.of(node.getModifiers()), - node.getType(), + extractedDims.node, node.getName(), "", equals, initializer, trailing, /* receiverExpression= */ Optional.empty(), - /* typeWithDims= */ Optional.empty()); + typeWithDims); } /** Does not omit the leading '<', which should be associated with the type name. */ diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.input new file mode 100644 index 000000000..2364f0c16 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.input @@ -0,0 +1,9 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@interface MyTypeAnno {} + +public class GjfFailure { + void m(int a @MyTypeAnno []) {} +} \ No newline at end of file diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.output new file mode 100644 index 000000000..a36919e4d --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I374.output @@ -0,0 +1,9 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@interface MyTypeAnno {} + +public class GjfFailure { + void m(int a @MyTypeAnno []) {} +} From 56ec8f9af121ec78447a2fb2a959d4443c8062f5 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 19 Dec 2019 17:15:38 -0800 Subject: [PATCH 2/2] Add SBT plugin to readme Fixes #391 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=286493206 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 72d881944..c5fdee230 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ Implementation`. * [Cosium/maven-git-code-format](https://github.com/Cosium/maven-git-code-format): A maven plugin that automatically deploys google-java-format as a pre-commit git hook. +* SBT plugins + * [sbt/sbt-java-formatter](https://github.com/sbt/sbt-java-formatter) * [maltzj/google-style-precommit-hook](https://github.com/maltzj/google-style-precommit-hook): A pre-commit (pre-commit.com) hook that will automatically run GJF whenever you commit code to your repository