diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml
index 260a9236541..4d90a9beb7e 100644
--- a/idea/resources/META-INF/plugin-common.xml
+++ b/idea/resources/META-INF/plugin-common.xml
@@ -1496,6 +1496,11 @@
Kotlin
+
+ org.jetbrains.kotlin.idea.intentions.ConvertToAlsoIntention
+ Kotlin
+
+
org.jetbrains.kotlin.idea.intentions.ConvertToWithIntention
Kotlin
diff --git a/idea/resources/intentionDescriptions/ConvertToAlsoIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertToAlsoIntention/after.kt.template
new file mode 100644
index 00000000000..e8a12278093
--- /dev/null
+++ b/idea/resources/intentionDescriptions/ConvertToAlsoIntention/after.kt.template
@@ -0,0 +1,7 @@
+fun foo() {
+ val a = MyClass().also {
+ it.setFoo(1)
+ it.setBar(2)
+ it.setBaz(3)
+ }
+}
\ No newline at end of file
diff --git a/idea/resources/intentionDescriptions/ConvertToAlsoIntention/before.kt.template b/idea/resources/intentionDescriptions/ConvertToAlsoIntention/before.kt.template
new file mode 100644
index 00000000000..ba64950471d
--- /dev/null
+++ b/idea/resources/intentionDescriptions/ConvertToAlsoIntention/before.kt.template
@@ -0,0 +1,6 @@
+fun foo() {
+ val a = MyClass()
+ a.setFoo(1)
+ a.setBar(2)
+ a.setBaz(3)
+}
\ No newline at end of file
diff --git a/idea/resources/intentionDescriptions/ConvertToAlsoIntention/description.html b/idea/resources/intentionDescriptions/ConvertToAlsoIntention/description.html
new file mode 100644
index 00000000000..04c3a0b44b3
--- /dev/null
+++ b/idea/resources/intentionDescriptions/ConvertToAlsoIntention/description.html
@@ -0,0 +1,5 @@
+
+
+This intention converts several calls with the same receiver to also.
+
+
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertDotQualifiedToScopeIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertDotQualifiedToScopeIntention.kt
index e4ad41287de..88c3f02e693 100644
--- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertDotQualifiedToScopeIntention.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertDotQualifiedToScopeIntention.kt
@@ -25,11 +25,13 @@ abstract class ConvertDotQualifiedToScopeIntention(
text: String
) : ConvertToScopeIntention(KtDotQualifiedExpression::class.java, text) {
+ override val isParameterScopeFunction = false
+
override fun isApplicableTo(element: KtDotQualifiedExpression, caretOffset: Int): Boolean {
val receiverExpression = element.getLeftMostReceiverExpression()
if (receiverExpression.mainReference?.resolve() is PsiClass) return false
val receiverExpressionText = receiverExpression.text
- if (receiverExpressionText in BLACKLIST_RECEIVER_NAME) return false
+ if (receiverExpressionText == scopeReceiverName) return false
if (!isApplicableWithGivenReceiverText(element, receiverExpressionText)) return false
val nextSibling = element.getDotQualifiedSiblingIfAny(forward = true)
if (nextSibling != null && isApplicableWithGivenReceiverText(nextSibling, receiverExpressionText)) return true
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToApplyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToApplyIntention.kt
index 4df9fe60832..43e11fdc5ea 100644
--- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToApplyIntention.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToApplyIntention.kt
@@ -20,9 +20,16 @@ import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments
-class ConvertToApplyIntention : ConvertToScopeIntention(
- KtExpression::class.java, "Convert to apply"
+sealed class ConvertToApplyOrAlsoIntention(isAlso: Boolean) : ConvertToScopeIntention(
+ KtExpression::class.java, "Convert to ${scopeFunctionName(isAlso)}"
) {
+
+ companion object {
+ fun scopeFunctionName(isParameterScopeFunction: Boolean) = if (isParameterScopeFunction) "also" else "apply"
+ }
+
+ override val isParameterScopeFunction = isAlso
+
override fun findCallExpressionFrom(scopeExpression: KtExpression) =
((scopeExpression as? KtProperty)?.initializer as? KtQualifiedExpression)?.callExpression
@@ -79,6 +86,10 @@ class ConvertToApplyIntention : ConvertToScopeIntention(
if (element !is KtProperty) return null
val receiverExpressionText = element.name ?: return null
return factory.createProperty(receiverExpressionText, element.typeReference?.text, element.isVar,
- "${element.initializer?.text}.apply{}")
+ "${element.initializer?.text}.${scopeFunctionName(isParameterScopeFunction)}{}")
}
-}
\ No newline at end of file
+}
+
+class ConvertToApplyIntention : ConvertToApplyOrAlsoIntention(isAlso = false)
+
+class ConvertToAlsoIntention : ConvertToApplyOrAlsoIntention(isAlso = true)
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt
index cb0c05914d2..2ce17ef81bb 100644
--- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt
@@ -26,7 +26,10 @@ abstract class ConvertToScopeIntention(
text: String
) : SelfTargetingIntention(elementType, text) {
- protected val BLACKLIST_RECEIVER_NAME = listOf("this", "it")
+ abstract val isParameterScopeFunction: Boolean
+
+ protected val scopeReceiverName: String
+ get() = if (isParameterScopeFunction) "it" else "this"
protected abstract fun createScopeExpression(factory: KtPsiFactory, element: TExpression): KtExpression?
@@ -54,7 +57,7 @@ abstract class ConvertToScopeIntention(
if (expression is KtProperty) expression
else findFirstExpressionToMove(receiverExpressionText, expression)
val firstExpressionToMove = if (expression is KtProperty) expression.nextSibling else firstTargetExpression
- blockExpression.moveRangeInto(firstExpressionToMove, lastExpressionToMove)
+ blockExpression.moveRangeInto(firstExpressionToMove, lastExpressionToMove, factory)
parent.addBefore(scopeBlockExpression, firstTargetExpression)
parent.deleteChildRange(firstTargetExpression, lastExpressionToMove)
@@ -71,14 +74,19 @@ abstract class ConvertToScopeIntention(
lambdaArguments.firstOrNull()?.getLambdaExpression()?.bodyExpression
private fun KtBlockExpression.moveRangeInto(
- firstElement: PsiElement, lastElement: PsiElement
+ firstElement: PsiElement, lastElement: PsiElement, psiFactory: KtPsiFactory
) {
addRange(firstElement, lastElement)
children.filterIsInstance(KtDotQualifiedExpression::class.java)
- .forEach { it.deleteFirstReceiver() }
+ .forEach {
+ val replaced = it.deleteFirstReceiver()
+ if (isParameterScopeFunction) {
+ replaced.replace(psiFactory.createExpressionByPattern("$scopeReceiverName.$0", replaced))
+ }
+ }
}
- private fun KtCallExpression.isApplicable() = lambdaArguments.isEmpty() && valueArguments.all { it.text !in BLACKLIST_RECEIVER_NAME }
+ private fun KtCallExpression.isApplicable() = lambdaArguments.isEmpty() && valueArguments.all { it.text != scopeReceiverName }
private fun findFirstExpressionToMove(receiverExpressionText: String, expression: KtExpression) =
findBoundaryExpression(receiverExpressionText, expression, forward = false)
diff --git a/idea/testData/intentions/convertToAlso/.intention b/idea/testData/intentions/convertToAlso/.intention
new file mode 100644
index 00000000000..fd5cb528d26
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/.intention
@@ -0,0 +1 @@
+org.jetbrains.kotlin.idea.intentions.ConvertToAlsoIntention
diff --git a/idea/testData/intentions/convertToAlso/itParameter.kt b/idea/testData/intentions/convertToAlso/itParameter.kt
new file mode 100644
index 00000000000..d4433cc8315
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/itParameter.kt
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+// IS_APPLICABLE: false
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2(a: MyClass) = Unit
+ fun foo3() = Unit
+
+ fun foo4(it: MyClass) {
+ val a = MyClass()
+ a.foo1()
+ a.foo2(it)
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/itParameter2.kt b/idea/testData/intentions/convertToAlso/itParameter2.kt
new file mode 100644
index 00000000000..6665512bd0e
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/itParameter2.kt
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+// IS_APPLICABLE: false
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2(a: MyClass) = Unit
+ fun foo3() = Unit
+
+ fun foo4(it: MyClass) {
+ val a = MyClass()
+ a.foo1()
+ a.foo2(it)
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/methodChain.kt b/idea/testData/intentions/convertToAlso/methodChain.kt
new file mode 100644
index 00000000000..6f7c727bff6
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/methodChain.kt
@@ -0,0 +1,14 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4() {
+ val a = MyClass()
+ a.foo1().foo2().foo3()
+ a.foo2()
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/methodChain.kt.after b/idea/testData/intentions/convertToAlso/methodChain.kt.after
new file mode 100644
index 00000000000..027856156c8
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/methodChain.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4() {
+ val a = MyClass().also {
+ it.foo1().foo2().foo3()
+ it.foo2()
+ it.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/methodChainWithItParameter.kt b/idea/testData/intentions/convertToAlso/methodChainWithItParameter.kt
new file mode 100644
index 00000000000..794112733ec
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/methodChainWithItParameter.kt
@@ -0,0 +1,17 @@
+// WITH_RUNTIME
+// IS_APPLICABLE: false
+
+class MyClass {
+ fun foo1(a: MyClass): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4() {
+ listOf().forEach {
+ val a = MyClass()
+ a.foo1(it).foo2().foo3()
+ a.foo2()
+ a.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt b/idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt
new file mode 100644
index 00000000000..8508467dbf7
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt
@@ -0,0 +1,14 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(a: MyClass): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4() {
+ val a = MyClass()
+ a.foo1(this).foo2().foo3()
+ a.foo2()
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt.after b/idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt.after
new file mode 100644
index 00000000000..d7e1b86c152
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(a: MyClass): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4() {
+ val a = MyClass().also {
+ it.foo1(this).foo2().foo3()
+ it.foo2()
+ it.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/normal.kt b/idea/testData/intentions/convertToAlso/normal.kt
new file mode 100644
index 00000000000..3861e44ece4
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/normal.kt
@@ -0,0 +1,14 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4() {
+ val a = MyClass()
+ a.foo1()
+ a.foo2()
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/normal.kt.after b/idea/testData/intentions/convertToAlso/normal.kt.after
new file mode 100644
index 00000000000..06cbd7d6948
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/normal.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4() {
+ val a = MyClass().also {
+ it.foo1()
+ it.foo2()
+ it.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/normal2.kt b/idea/testData/intentions/convertToAlso/normal2.kt
new file mode 100644
index 00000000000..fc916d20946
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/normal2.kt
@@ -0,0 +1,14 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(a: MyClass) {
+ val a = MyClass()
+ a.foo1()
+ a.foo2()
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/normal2.kt.after b/idea/testData/intentions/convertToAlso/normal2.kt.after
new file mode 100644
index 00000000000..be3f38f35cb
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/normal2.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(a: MyClass) {
+ val a = MyClass().also {
+ it.foo1()
+ it.foo2()
+ it.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/normal3.kt b/idea/testData/intentions/convertToAlso/normal3.kt
new file mode 100644
index 00000000000..7e99d66ecc9
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/normal3.kt
@@ -0,0 +1,14 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(a: MyClass) {
+ val a = MyClass()
+ a.foo1()
+ a.foo2()
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/normal3.kt.after b/idea/testData/intentions/convertToAlso/normal3.kt.after
new file mode 100644
index 00000000000..be3f38f35cb
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/normal3.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(a: MyClass) {
+ val a = MyClass().also {
+ it.foo1()
+ it.foo2()
+ it.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/untilItParameter.kt b/idea/testData/intentions/convertToAlso/untilItParameter.kt
new file mode 100644
index 00000000000..c1109417570
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/untilItParameter.kt
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2(a: MyClass) = Unit
+ fun foo3() = Unit
+
+ fun foo4(it: MyClass) {
+ val a = MyClass()
+ a.foo1()
+ a.foo3()
+ a.foo2(it)
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/untilItParameter.kt.after b/idea/testData/intentions/convertToAlso/untilItParameter.kt.after
new file mode 100644
index 00000000000..c43b8f73841
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/untilItParameter.kt.after
@@ -0,0 +1,16 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2(a: MyClass) = Unit
+ fun foo3() = Unit
+
+ fun foo4(it: MyClass) {
+ val a = MyClass().also {
+ it.foo1()
+ it.foo3()
+ }
+ a.foo2(it)
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/var.kt b/idea/testData/intentions/convertToAlso/var.kt
new file mode 100644
index 00000000000..834f65165bc
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/var.kt
@@ -0,0 +1,14 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4() {
+ var a = MyClass()
+ a.foo1()
+ a.foo2()
+ a.foo3()
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/var.kt.after b/idea/testData/intentions/convertToAlso/var.kt.after
new file mode 100644
index 00000000000..38c6d5168c2
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/var.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4() {
+ var a = MyClass().also {
+ it.foo1()
+ it.foo2()
+ it.foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt b/idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt
new file mode 100644
index 00000000000..9ab6a8cef87
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt
@@ -0,0 +1,20 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(a: MyClass) {
+ // top comment
+ val a = MyClass()
+ // here is comment
+ a.foo1()
+ // comment
+
+ // bbb
+ a.foo2()
+ a.foo3()
+ // last comment won't be in
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt.after b/idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt.after
new file mode 100644
index 00000000000..9a22fb58e91
--- /dev/null
+++ b/idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt.after
@@ -0,0 +1,21 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(a: MyClass) {
+ // top comment
+ val a = MyClass().also {
+ // here is comment
+ it.foo1()
+ // comment
+
+ // bbb
+ it.foo2()
+ it.foo3()
+ }
+ // last comment won't be in
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt b/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt
index 794112733ec..d03a460846c 100644
--- a/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt
+++ b/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt
@@ -1,5 +1,4 @@
// WITH_RUNTIME
-// IS_APPLICABLE: false
class MyClass {
fun foo1(a: MyClass): MyClass = this
diff --git a/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt.after b/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt.after
new file mode 100644
index 00000000000..59a6eb210b0
--- /dev/null
+++ b/idea/testData/intentions/convertToApply/methodChainWithItParameter.kt.after
@@ -0,0 +1,17 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(a: MyClass): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4() {
+ listOf().forEach {
+ val a = MyClass().apply {
+ foo1(it).foo2().foo3()
+ foo2()
+ foo3()
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToRun/itReceiver.kt b/idea/testData/intentions/convertToRun/itReceiver.kt
index 753d242c788..08dadf684ab 100644
--- a/idea/testData/intentions/convertToRun/itReceiver.kt
+++ b/idea/testData/intentions/convertToRun/itReceiver.kt
@@ -1,16 +1,13 @@
// WITH_RUNTIME
-// IS_APPLICABLE: false
class MyClass {
fun foo1() = Unit
fun foo2() = Unit
fun foo3() = Unit
- fun foo4(a: MyClass) {
- a.let {
- it.foo1()
- it.foo2()
- it.foo3()
- }
+ fun foo4(it: MyClass) {
+ it.foo1()
+ it.foo2()
+ it.foo3()
}
}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToRun/itReceiver.kt.after b/idea/testData/intentions/convertToRun/itReceiver.kt.after
new file mode 100644
index 00000000000..8470ca2307b
--- /dev/null
+++ b/idea/testData/intentions/convertToRun/itReceiver.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(it: MyClass) {
+ it.run {
+ foo1()
+ foo2()
+ foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt b/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt
index 4d41f35623b..258bc8e1e3f 100644
--- a/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt
+++ b/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt
@@ -1,5 +1,4 @@
// WITH_RUNTIME
-// IS_APPLICABLE: false
class MyClass {
fun foo1(a: MyClass): MyClass = this
diff --git a/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt.after b/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt.after
new file mode 100644
index 00000000000..733d6342ff0
--- /dev/null
+++ b/idea/testData/intentions/convertToRun/methodChainWithItParameter.kt.after
@@ -0,0 +1,16 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(a: MyClass): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4(a: MyClass) {
+ listOf().forEach {
+ a.run {
+ foo1(it).foo2().foo3()
+ foo2()
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToWith/itReceiver.kt b/idea/testData/intentions/convertToWith/itReceiver.kt
index 753d242c788..08dadf684ab 100644
--- a/idea/testData/intentions/convertToWith/itReceiver.kt
+++ b/idea/testData/intentions/convertToWith/itReceiver.kt
@@ -1,16 +1,13 @@
// WITH_RUNTIME
-// IS_APPLICABLE: false
class MyClass {
fun foo1() = Unit
fun foo2() = Unit
fun foo3() = Unit
- fun foo4(a: MyClass) {
- a.let {
- it.foo1()
- it.foo2()
- it.foo3()
- }
+ fun foo4(it: MyClass) {
+ it.foo1()
+ it.foo2()
+ it.foo3()
}
}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToWith/itReceiver.kt.after b/idea/testData/intentions/convertToWith/itReceiver.kt.after
new file mode 100644
index 00000000000..076a6f155a4
--- /dev/null
+++ b/idea/testData/intentions/convertToWith/itReceiver.kt.after
@@ -0,0 +1,15 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1() = Unit
+ fun foo2() = Unit
+ fun foo3() = Unit
+
+ fun foo4(it: MyClass) {
+ with(it) {
+ foo1()
+ foo2()
+ foo3()
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt b/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt
index 4d41f35623b..258bc8e1e3f 100644
--- a/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt
+++ b/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt
@@ -1,5 +1,4 @@
// WITH_RUNTIME
-// IS_APPLICABLE: false
class MyClass {
fun foo1(a: MyClass): MyClass = this
diff --git a/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt.after b/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt.after
new file mode 100644
index 00000000000..68212bcf69a
--- /dev/null
+++ b/idea/testData/intentions/convertToWith/methodChainWithItParameter.kt.after
@@ -0,0 +1,16 @@
+// WITH_RUNTIME
+
+class MyClass {
+ fun foo1(a: MyClass): MyClass = this
+ fun foo2(): MyClass = this
+ fun foo3(): MyClass = this
+
+ fun foo4(a: MyClass) {
+ listOf().forEach {
+ with(a) {
+ foo1(it).foo2().foo3()
+ foo2()
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
index 1d754b6770d..9757eb5d9b4 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
@@ -7004,6 +7004,74 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
}
}
+ @TestMetadata("idea/testData/intentions/convertToAlso")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ConvertToAlso extends AbstractIntentionTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInConvertToAlso() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertToAlso"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("itParameter.kt")
+ public void testItParameter() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/itParameter.kt");
+ }
+
+ @TestMetadata("itParameter2.kt")
+ public void testItParameter2() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/itParameter2.kt");
+ }
+
+ @TestMetadata("methodChain.kt")
+ public void testMethodChain() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/methodChain.kt");
+ }
+
+ @TestMetadata("methodChainWithItParameter.kt")
+ public void testMethodChainWithItParameter() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/methodChainWithItParameter.kt");
+ }
+
+ @TestMetadata("methodChainWithThisParameter.kt")
+ public void testMethodChainWithThisParameter() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/methodChainWithThisParameter.kt");
+ }
+
+ @TestMetadata("normal.kt")
+ public void testNormal() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/normal.kt");
+ }
+
+ @TestMetadata("normal2.kt")
+ public void testNormal2() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/normal2.kt");
+ }
+
+ @TestMetadata("normal3.kt")
+ public void testNormal3() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/normal3.kt");
+ }
+
+ @TestMetadata("untilItParameter.kt")
+ public void testUntilItParameter() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/untilItParameter.kt");
+ }
+
+ @TestMetadata("var.kt")
+ public void testVar() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/var.kt");
+ }
+
+ @TestMetadata("withCommentAndSpaces.kt")
+ public void testWithCommentAndSpaces() throws Exception {
+ runTest("idea/testData/intentions/convertToAlso/withCommentAndSpaces.kt");
+ }
+ }
+
@TestMetadata("idea/testData/intentions/convertToApply")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)