diff options
author | nickreid <nickreid@google.com> | 2022-06-08 23:35:02 -0700 |
---|---|---|
committer | Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> | 2022-06-08 23:35:02 -0700 |
commit | 4a0c2d4a757db6258a59b62dec1e499d1419cb1f (patch) | |
tree | 935efcc0812fc1250811b1603015659f3b79b7cd /core/src/main/java/com/facebook | |
parent | d71487b6c76b23a5b4c580185c9e48f3694f0b96 (diff) | |
download | ktfmt-4a0c2d4a757db6258a59b62dec1e499d1419cb1f.tar.gz |
Prevent adjacent unary operators from merging (#328)
Summary: Pull Request resolved: https://github.com/facebookincubator/ktfmt/pull/328
Reviewed By: strulovich
Differential Revision: D37003050
Pulled By: cgrushko
fbshipit-source-id: 010cd6a400d88aed8e253718658ec93464dd0b5f
Diffstat (limited to 'core/src/main/java/com/facebook')
-rw-r--r-- | core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt index 490184e..358fe50 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt @@ -111,7 +111,6 @@ import org.jetbrains.kotlin.psi.KtTypeParameter import org.jetbrains.kotlin.psi.KtTypeParameterList import org.jetbrains.kotlin.psi.KtTypeProjection import org.jetbrains.kotlin.psi.KtTypeReference -import org.jetbrains.kotlin.psi.KtUnaryExpression import org.jetbrains.kotlin.psi.KtUserType import org.jetbrains.kotlin.psi.KtValueArgument import org.jetbrains.kotlin.psi.KtValueArgumentList @@ -1137,19 +1136,33 @@ class KotlinInputAstVisitor( builder.close() } - override fun visitUnaryExpression(expression: KtUnaryExpression) { + override fun visitPostfixExpression(expression: KtPostfixExpression) { builder.sync(expression) builder.block(ZERO) { - visit(expression.baseExpression) - builder.token(expression.operationReference.text) + val baseExpression = expression.baseExpression + val operator = expression.operationReference.text + + visit(baseExpression) + if (baseExpression is KtPostfixExpression && + baseExpression.operationReference.text.last() == operator.first()) { + builder.space() + } + builder.token(operator) } } override fun visitPrefixExpression(expression: KtPrefixExpression) { builder.sync(expression) builder.block(ZERO) { - builder.token(expression.operationReference.text) - visit(expression.baseExpression) + val baseExpression = expression.baseExpression + val operator = expression.operationReference.text + + builder.token(operator) + if (baseExpression is KtPrefixExpression && + operator.last() == baseExpression.operationReference.text.first()) { + builder.space() + } + visit(baseExpression) } } |