Formatter: fix line break before OperationReference in elvis

#KT-22362 Fixed
This commit is contained in:
Dmitry Gridin
2019-11-01 15:50:39 +07:00
parent 247619c565
commit d321f4626f
4 changed files with 24 additions and 1 deletions
@@ -615,7 +615,7 @@ abstract class KotlinCommonBlock(
}
if (nodePsi.operationToken == ELVIS && nodePsi.getStrictParentOfType<KtStringTemplateExpression>() == null) {
return { childElement ->
if (childElement.elementType == OPERATION_REFERENCE) {
if (childElement.elementType == OPERATION_REFERENCE && (childElement.psi as? KtOperationReferenceExpression)?.operationSignTokenType == ELVIS) {
Wrap.createWrap(settings.kotlinCustomSettings.WRAP_ELVIS_EXPRESSIONS, true)
} else {
null
@@ -0,0 +1,10 @@
infix fun String.concat(other: String): String = this
fun binaryContext(anchor: String?) {
val v1 = "1234567890... add many chars ...1234567890" concat "b"
val v2 = anchor
?: "1234567890... add many chars ...1234567890" concat "b"
val v3 = anchor
?: "1234567890... add many chars ...1234567890" concat "1234567890... add many chars ...1234567890" concat "1234567890... add many chars ...1234567890" concat "b"
}
// SET_INT: WRAP_ELVIS_EXPRESSIONS = 2
@@ -0,0 +1,8 @@
infix fun String.concat(other: String): String = this
fun binaryContext(anchor: String?) {
val v1 = "1234567890... add many chars ...1234567890" concat "b"
val v2 = anchor ?: "1234567890... add many chars ...1234567890" concat "b"
val v3 = anchor ?: "1234567890... add many chars ...1234567890" concat "1234567890... add many chars ...1234567890" concat "1234567890... add many chars ...1234567890" concat "b"
}
// SET_INT: WRAP_ELVIS_EXPRESSIONS = 2
@@ -245,6 +245,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
runTest("idea/testData/formatter/ElvisIndent.after.kt");
}
@TestMetadata("ElvisWithOperationReference.after.kt")
public void testElvisWithOperationReference() throws Exception {
runTest("idea/testData/formatter/ElvisWithOperationReference.after.kt");
}
@TestMetadata("ElvisWrap.after.kt")
public void testElvisWrap() throws Exception {
runTest("idea/testData/formatter/ElvisWrap.after.kt");