Skip to content

Commit

Permalink
fix(printer): break and indent binary expression with cast properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkiesel authored and clementdessoude committed Jul 22, 2023
1 parent 20da8ea commit b1b9e7c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/prettier-plugin-java/src/printers/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,17 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter {
ctx.variableInitializer![0].children.expression![0].children
.ternaryExpression !== undefined
) {
const firstPrimary =
const unaryExpressions =
ctx.variableInitializer![0].children.expression![0].children
.ternaryExpression[0].children.binaryExpression[0].children
.unaryExpression[0].children.primary[0];
.unaryExpression;
const firstPrimary = unaryExpressions[0].children.primary[0];

// Cast Expression
if (
firstPrimary.children.primaryPrefix[0].children.castExpression !==
undefined
undefined &&
unaryExpressions.length === 1
) {
const groupId = Symbol("assignment");
return group([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ public void method() {
new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more").bar(10);
foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more").bar(10);
}

public void binaryExpressionWithCast() {
double availability = (double) successfulCount / (successfulCount + failureCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ public void method() {
foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
.bar(10);
}

public void binaryExpressionWithCast() {
double availability =
(double) successfulCount / (successfulCount + failureCount);
}
}

0 comments on commit b1b9e7c

Please sign in to comment.