diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index 486f7ca2f66..7b0fb085f1a 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -615,7 +615,7 @@ abstract class KotlinCommonBlock( } if (nodePsi.operationToken == ELVIS && nodePsi.getStrictParentOfType() == 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 diff --git a/idea/testData/formatter/ElvisWithOperationReference.after.kt b/idea/testData/formatter/ElvisWithOperationReference.after.kt new file mode 100644 index 00000000000..e307ee1a85f --- /dev/null +++ b/idea/testData/formatter/ElvisWithOperationReference.after.kt @@ -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 diff --git a/idea/testData/formatter/ElvisWithOperationReference.kt b/idea/testData/formatter/ElvisWithOperationReference.kt new file mode 100644 index 00000000000..4df14b913f1 --- /dev/null +++ b/idea/testData/formatter/ElvisWithOperationReference.kt @@ -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 diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index e56924b9916..c7d8837d599 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -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");