diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt index 43f4253e5a5..b308081e884 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt @@ -111,7 +111,7 @@ sealed class ConvertToScopeIntention( (prev + listOf(this) + next) to referenceName } } - if (targets.size < 2) return null + if (targets.isEmpty()) return null return targets to referenceName } diff --git a/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt b/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt index 744285fe8ad..76690da5271 100644 --- a/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt +++ b/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt @@ -1,5 +1,4 @@ // WITH_RUNTIME -// IS_APPLICABLE: false class Foo { fun foo(i: Int) {} @@ -11,6 +10,7 @@ fun test() { listOf(1).forEach { val f = Foo() f.foo(1) + f.foo(2) bar(it, f) } } \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt.after b/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt.after new file mode 100644 index 00000000000..4a360a866a7 --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToAlso/callExpression5.kt.after @@ -0,0 +1,17 @@ +// WITH_RUNTIME + +class Foo { + fun foo(i: Int) {} +} + +fun bar(i: Int, f: Foo) {} + +fun test() { + listOf(1).forEach { + val f = Foo().also { + it.foo(1) + it.foo(2) + } + bar(it, f) + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt b/idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt new file mode 100644 index 00000000000..9504dedaf6f --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C() + c.foo() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt.after b/idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt.after new file mode 100644 index 00000000000..a2dd5a3a4f7 --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt.after @@ -0,0 +1,11 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C().also { + it.foo() + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt b/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt index 50f3741c266..6be741928c3 100644 --- a/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt +++ b/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt @@ -1,5 +1,4 @@ // WITH_RUNTIME -// IS_APPLICABLE: false class Foo { fun foo(i: Int) {} @@ -7,6 +6,7 @@ class Foo { fun test(f: Foo) { val f = Foo() f.foo(1) + f.foo(2) bar(2, this) } } diff --git a/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt.after b/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt.after new file mode 100644 index 00000000000..d9190226e0b --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToApply/callExpression5.kt.after @@ -0,0 +1,15 @@ +// WITH_RUNTIME + +class Foo { + fun foo(i: Int) {} + + fun test(f: Foo) { + val f = Foo().apply { + foo(1) + foo(2) + } + bar(2, this) + } +} + +fun bar(i: Int, f: Foo) {} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToApply/singleCall.kt b/idea/testData/intentions/convertToScope/convertToApply/singleCall.kt new file mode 100644 index 00000000000..9504dedaf6f --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToApply/singleCall.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C() + c.foo() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToApply/singleCall.kt.after b/idea/testData/intentions/convertToScope/convertToApply/singleCall.kt.after new file mode 100644 index 00000000000..9277d2266c0 --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToApply/singleCall.kt.after @@ -0,0 +1,11 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C().apply { + foo() + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.kt b/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.kt index d32e1286c1c..065119c1e2b 100644 --- a/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.kt +++ b/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.kt @@ -1,5 +1,4 @@ // WITH_RUNTIME -// IS_APPLICABLE: false class MyClass { fun foo1(a: MyClass): MyClass = this @@ -9,5 +8,7 @@ class MyClass { fun foo4(a: MyClass) { a.foo1(this).foo2().foo3() a.foo2() + a.foo3() + a.foo1(this).foo2().foo3() } } \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.kt.after b/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.kt.after new file mode 100644 index 00000000000..3f75a930628 --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToRun/methodChainWithThisParameter.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) { + a.foo1(this).foo2().foo3() + a.run { + foo2() + foo3() + } + a.foo1(this).foo2().foo3() + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToRun/singleCall.kt b/idea/testData/intentions/convertToScope/convertToRun/singleCall.kt new file mode 100644 index 00000000000..9504dedaf6f --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToRun/singleCall.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C() + c.foo() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToRun/singleCall.kt.after b/idea/testData/intentions/convertToScope/convertToRun/singleCall.kt.after new file mode 100644 index 00000000000..d11dfa579c1 --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToRun/singleCall.kt.after @@ -0,0 +1,12 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C() + c.run { + foo() + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.kt b/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.kt index d32e1286c1c..065119c1e2b 100644 --- a/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.kt +++ b/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.kt @@ -1,5 +1,4 @@ // WITH_RUNTIME -// IS_APPLICABLE: false class MyClass { fun foo1(a: MyClass): MyClass = this @@ -9,5 +8,7 @@ class MyClass { fun foo4(a: MyClass) { a.foo1(this).foo2().foo3() a.foo2() + a.foo3() + a.foo1(this).foo2().foo3() } } \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.kt.after b/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.kt.after new file mode 100644 index 00000000000..183f9015acd --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToWith/methodChainWithThisParameter.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) { + a.foo1(this).foo2().foo3() + with(a) { + foo2() + foo3() + } + a.foo1(this).foo2().foo3() + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToWith/singleCall.kt b/idea/testData/intentions/convertToScope/convertToWith/singleCall.kt new file mode 100644 index 00000000000..9504dedaf6f --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToWith/singleCall.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C() + c.foo() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToScope/convertToWith/singleCall.kt.after b/idea/testData/intentions/convertToScope/convertToWith/singleCall.kt.after new file mode 100644 index 00000000000..18aa6b4c476 --- /dev/null +++ b/idea/testData/intentions/convertToScope/convertToWith/singleCall.kt.after @@ -0,0 +1,12 @@ +// WITH_RUNTIME + +class C { + fun foo() {} +} + +fun test() { + val c = C() + with(c) { + foo() + } +} \ 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 b55ff82d587..b63438ba36b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -7553,6 +7553,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/convertToScope/convertToAlso/onProperty.kt"); } + @TestMetadata("singleCall.kt") + public void testSingleCall() throws Exception { + runTest("idea/testData/intentions/convertToScope/convertToAlso/singleCall.kt"); + } + @TestMetadata("untilItParameter.kt") public void testUntilItParameter() throws Exception { runTest("idea/testData/intentions/convertToScope/convertToAlso/untilItParameter.kt"); @@ -7641,6 +7646,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/convertToScope/convertToApply/onProperty.kt"); } + @TestMetadata("singleCall.kt") + public void testSingleCall() throws Exception { + runTest("idea/testData/intentions/convertToScope/convertToApply/singleCall.kt"); + } + @TestMetadata("thisParameter.kt") public void testThisParameter() throws Exception { runTest("idea/testData/intentions/convertToScope/convertToApply/thisParameter.kt"); @@ -7744,6 +7754,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/convertToScope/convertToRun/onProperty.kt"); } + @TestMetadata("singleCall.kt") + public void testSingleCall() throws Exception { + runTest("idea/testData/intentions/convertToScope/convertToRun/singleCall.kt"); + } + @TestMetadata("thisParameter.kt") public void testThisParameter() throws Exception { runTest("idea/testData/intentions/convertToScope/convertToRun/thisParameter.kt"); @@ -7842,6 +7857,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/convertToScope/convertToWith/onProperty.kt"); } + @TestMetadata("singleCall.kt") + public void testSingleCall() throws Exception { + runTest("idea/testData/intentions/convertToScope/convertToWith/singleCall.kt"); + } + @TestMetadata("thisParameter.kt") public void testThisParameter() throws Exception { runTest("idea/testData/intentions/convertToScope/convertToWith/thisParameter.kt");