-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix line breaks in switch expression #394
Conversation
Generate changelog in
|
sync(node); | ||
// Also format switch expressions as statement body instead of inlining them | ||
boolean statementBody = node.getBodyKind() == LambdaExpressionTree.BodyKind.STATEMENT | ||
|| node.getBody().getKind() == Kind.SWITCH_EXPRESSION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix for case 1. This has to be in the Java14InputAstVisitor.java
class to not break java 11 compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add some kind of todo to collapse once we drop 11 (probably several years out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the todo.
But tbh, once we drop java 11 compat, we would collapse the whole Java14InputAstVisitor
with the base class.
boolean first = true; | ||
for (ExpressionTree expression : node.getExpressions()) { | ||
if (!first) { | ||
token(","); | ||
builder.space(); | ||
builder.breakOp(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix for case 2.
@@ -226,12 +231,30 @@ public Void visitCase(CaseTree node, Void unused) { | |||
token("-"); | |||
token(">"); | |||
builder.space(); | |||
scan(node.getBody(), null); | |||
if (node.getBody().getKind() == BLOCK) { | |||
visitBlock( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For collapsing empty case blocks: case ENUM -> {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding this as a source comment? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the comment 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice, found the comments very helpful in understanding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Released 2.0.1 |
Before this PR
Switch expressions were incorrectly formatted in two cases as reported in #383:
After this PR
==COMMIT_MSG==
Fix line breaks in switch expression
==COMMIT_MSG==
cc @pkoenig10