Skip to content
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

For --google_style, break between ( and long condition expressions #325

Closed
wants to merge 1 commit into from

Conversation

nreid260
Copy link
Contributor

@nreid260 nreid260 commented Jun 2, 2022

Fixes #319

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 2, 2022
@nreid260 nreid260 changed the title For --gogole_style, break between ( and long condition expressions For --google_style, break between ( and long condition expressions Jun 2, 2022
@nreid260 nreid260 force-pushed the if_cond branch 2 times, most recently from 3b526b9 to 4ce0ae6 Compare June 2, 2022 17:12
@cgrushko
Copy link
Contributor

cgrushko commented Jun 6, 2022

Importing for easier review

@facebook-github-bot
Copy link
Contributor

@cgrushko has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment on lines 701 to 725
private fun emitKeywordWithCondition(keyword: String, condition: KtExpression?) {
if (condition == null) {
builder.token(keyword)
return
}

builder.block(ZERO) {
builder.token(keyword)
builder.space()
builder.token("(")
if (isGoogleStyle) {
builder.block(expressionBreakIndent) {
builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO)
visit(condition)
builder.breakOp(Doc.FillMode.UNIFIED, "", expressionBreakNegativeIndent)
}
} else {
builder.block(ZERO) {
visit(condition)
}
}
}
builder.token(")")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We organize methods by chronological order if possible, so caller before callee. Could you move these below all callers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -698,6 +698,31 @@ class KotlinInputAstVisitor(
return extractCallExpression(this)?.lambdaArguments?.isNotEmpty() ?: false
}

private fun emitKeywordWithCondition(keyword: String, condition: KtExpression?) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a KDoc.

We usually state example of the content this parses, so something alike:

/** Emits a key word followed by a condition, e.g. `if (b)` or `while (c <d )` */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@strulovich strulovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@facebook-github-bot
Copy link
Contributor

@cgrushko has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@nreid260 nreid260 deleted the if_cond branch May 11, 2023 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Long expression inside parentheses causes only trailing ) to be on new line
4 participants