Skip to content

Commit

Permalink
fix: fix formating for variable arity parameters with variable modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
clementdessoude committed Dec 5, 2019
1 parent 9169fd6 commit 0d611e0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/prettier-plugin-java/src/printers/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,22 @@ class ClassesPrettierVisitor {
variableArityParameter(ctx) {
const variableModifier = this.mapVisit(ctx.variableModifier);
const unannType = this.visit(ctx.unannType);
const annotation = this.mapVisit(ctx.annotation);
const annotations = this.mapVisit(ctx.annotation);
const identifier = ctx.Identifier[0];

return rejectAndConcat([
const unannTypePrinted =
ctx.annotation === undefined
? concat([unannType, ctx.DotDotDot[0]])
: unannType;
const annotationsPrinted =
ctx.annotation === undefined
? annotations
: concat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]);

return rejectAndJoin(" ", [
join(" ", variableModifier),
unannType,
join(" ", annotation),
concat([ctx.DotDotDot[0], " "]),
unannTypePrinted,
annotationsPrinted,
identifier
]);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/prettier-plugin-java/test/unit-test/args/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ public void longListOfParametersThatShouldBreak(String one, Integer two, String

void lastParameterDotDotDot(String str1, String... str2) {
}

// TODO: uncomment when the parser variable arity bug is fixed (see #139)
// void variableArityParameters(Object @Nullable... errorMessageArgs) {}

void variableArityParameters(final String... strings) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public void longListOfParametersThatShouldBreak(
) {}

void lastParameterDotDotDot(String str1, String... str2) {}

// TODO: uncomment when the parser variable arity bug is fixed (see #139)
// void variableArityParameters(Object @Nullable... errorMessageArgs) {}
void variableArityParameters(final String... strings) {}
}

0 comments on commit 0d611e0

Please sign in to comment.