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 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 []) {} +}