Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter {

const elseOnSameLine =
hasTrailingLineComments(ctx.statement[0]) ||
hasLeadingLineComments(ctx.Else[0])
hasLeadingLineComments(ctx.Else[0]) ||
!ctx.statement[0].children.statementWithoutTrailingSubstatement?.[0]
.children.block
? hardline
: " ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ public void forEachWithEmptyStatement(List<String> list) {
}

public void ifElseWithEmptyStatements() {
if (test); else {
if (test);
else {
System.out.println("one");
}

if (test) {
System.out.println("two");
} else;

if (test); else;
if (test);
else;
}

public void ifElseWithEmptyStatementsWithComments() {
if (test) /*test*/; else {
if (test) /*test*/;
else {
System.out.println("one");
}

if (test); /*test*/else {
if (test);
/*test*/else {
System.out.println("one");
}

Expand All @@ -65,9 +69,11 @@ public void ifElseWithEmptyStatementsWithComments() {
System.out.println("two");
} else;/*test*/

if (test); /*test*/else;/*test*/
if (test);
/*test*/else;/*test*/

if (test) /*test*/; else /*test*/;
if (test) /*test*/;
else /*test*/;
}

public void simpleWhileWithEmptyStatement(boolean one) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ default Shape rotate(double angle) {
}

default String areaMessage() {
if (this instanceof Circle) return "Circle: " + area(); else if (
this instanceof Rectangle
) return "Rectangle: " + area(); else if (
this instanceof RightTriangle
) return "Triangle: " + area();
if (this instanceof Circle) return "Circle: " + area();
else if (this instanceof Rectangle) return "Rectangle: " + area();
else if (this instanceof RightTriangle) return "Triangle: " + area();
// :(
throw new IllegalArgumentException();
}
Expand Down