diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt index d61f890daa1..741b179173c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -272,6 +272,16 @@ public class BuilderByPattern { return this } + public fun appendExpressions(expressions: Iterable, separator: String = ","): BuilderByPattern { + for ((index, expression) in expressions.withIndex()) { + if (index > 0) { + appendFixedText(separator) + } + appendExpression(expression) + } + return this + } + public fun appendTypeReference(typeRef: KtTypeReference?): BuilderByPattern { if (typeRef != null) { patternBuilder.append("$" + arguments.size()) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt index 4be59ffd54c..f7c1733a9fd 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt @@ -167,26 +167,30 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention(javaClass(), "DeMorgan Law") { @@ -54,12 +52,7 @@ public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetin val operands = splitBooleanSequence(baseExpression)!!.asReversed() val newExpression = KtPsiFactory(element).buildExpression { - for ((i, operand) in operands.withIndex()) { - if (i > 0) { - appendFixedText(operatorText) - } - appendExpression(operand.negate()) - } + appendExpressions(operands.map { it.negate() }, separator = operatorText) } element.replace(newExpression) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt index dbb6b1f2bc1..075fab32c71 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt @@ -46,10 +46,7 @@ public class EliminateWhenSubjectIntention : JetSelfTargetingIntention 0) appendFixedText(",") - appendExpression(condition.toExpression(subject)) - } + appendExpressions(entry.conditions.map { it.toExpression(subject) }) } appendFixedText("->") diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt index 5a17098d6f0..63d661a3a97 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getSubjectTo import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceSubject import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* -import java.util.ArrayList +import java.util.* public class IfToWhenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace 'if' with 'when'") { override fun applicabilityRange(element: KtIfExpression): TextRange? { @@ -43,10 +43,8 @@ public class IfToWhenIntention : JetSelfTargetingRangeIntention( orBranches.addOrBranches(condition) } - for ((i, expr) in orBranches.withIndex()) { - if (i > 0) appendFixedText(",") - appendExpression(expr) - } + appendExpressions(orBranches) + appendFixedText("->") val thenBranch = ifExpression.getThen() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt index b6ed8fbede6..6fd84d31c9d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt @@ -68,10 +68,7 @@ public class WhenToIfIntention : JetSelfTargetingRangeIntention { return buildExpression { - for ((i, condition) in conditions.withIndex()) { - if (i > 0) appendFixedText("||") - appendExpression(condition.toExpression(subject)) - } + appendExpressions(conditions.map { it.toExpression(subject) }, separator = "||") } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceGetOrSetIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceGetOrSetIntention.kt index 83cd5e44262..9b8fbfceca3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceGetOrSetIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceGetOrSetIntention.kt @@ -102,12 +102,7 @@ class ReplaceGetOrSetIntention : JetSelfTargetingRangeIntention 0) { - appendFixedText(",") - } - appendExpression(argument.getArgumentExpression()) - } + appendExpressions(arguments.map { it.getArgumentExpression() }) appendFixedText("]")