Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaolans committed Apr 29, 2020
1 parent 7982487 commit 018096a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/prettier-plugin-java/src/printers/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,22 @@ class ClassesPrettierVisitor {

content = rejectAndJoinSeps(separators, classBodyDeclsVisited);

// edge case when we have SemiColons
let shouldHardline = false;
ctx.classBodyDeclaration.forEach(elt => {
if (
(elt.children.classMemberDeclaration &&
!elt.children.classMemberDeclaration[0].children.Semicolon) ||
elt.children.constructorDeclaration
) {
shouldHardline = true;
}
});

if (
!(
ctx.classBodyDeclaration[0].children.classMemberDeclaration !==
undefined &&
ctx.classBodyDeclaration[0].children.classMemberDeclaration[0]
.children.Semicolon !== undefined
)
(ctx.classBodyDeclaration[0].children.classMemberDeclaration ||
ctx.classBodyDeclaration[0].children.constructorDeclaration) &&
shouldHardline
) {
content = rejectAndConcat([hardline, content]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class LocalClassDeclaration {}
}

class ClassWithSemicolon {

private FieldOneClass fieldOne;
}

0 comments on commit 018096a

Please sign in to comment.