Convert to scope function: enable on single function call
#KT-29099 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e1fdf0aa43
commit
5f7dee4194
@@ -111,7 +111,7 @@ sealed class ConvertToScopeIntention(
|
|||||||
(prev + listOf(this) + next) to referenceName
|
(prev + listOf(this) + next) to referenceName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (targets.size < 2) return null
|
if (targets.isEmpty()) return null
|
||||||
return targets to referenceName
|
return targets to referenceName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IS_APPLICABLE: false
|
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
fun foo(i: Int) {}
|
fun foo(i: Int) {}
|
||||||
@@ -11,6 +10,7 @@ fun test() {
|
|||||||
listOf(1).forEach {
|
listOf(1).forEach {
|
||||||
val f = Foo()<caret>
|
val f = Foo()<caret>
|
||||||
f.foo(1)
|
f.foo(1)
|
||||||
|
f.foo(2)
|
||||||
bar(it, f)
|
bar(it, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+17
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C()
|
||||||
|
c.foo()<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C().also {
|
||||||
|
it.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IS_APPLICABLE: false
|
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
fun foo(i: Int) {}
|
fun foo(i: Int) {}
|
||||||
@@ -7,6 +6,7 @@ class Foo {
|
|||||||
fun test(f: Foo) {
|
fun test(f: Foo) {
|
||||||
val f = Foo()<caret>
|
val f = Foo()<caret>
|
||||||
f.foo(1)
|
f.foo(1)
|
||||||
|
f.foo(2)
|
||||||
bar(2, this)
|
bar(2, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -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) {}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C()
|
||||||
|
c.foo()<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C().apply {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,5 +1,4 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IS_APPLICABLE: false
|
|
||||||
|
|
||||||
class MyClass {
|
class MyClass {
|
||||||
fun foo1(a: MyClass): MyClass = this
|
fun foo1(a: MyClass): MyClass = this
|
||||||
@@ -9,5 +8,7 @@ class MyClass {
|
|||||||
fun foo4(a: MyClass) {
|
fun foo4(a: MyClass) {
|
||||||
a.foo1(this).foo2().foo3()
|
a.foo1(this).foo2().foo3()
|
||||||
a.foo2()<caret>
|
a.foo2()<caret>
|
||||||
|
a.foo3()
|
||||||
|
a.foo1(this).foo2().foo3()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+16
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C()
|
||||||
|
c.foo()<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C()
|
||||||
|
c.run {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,5 +1,4 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IS_APPLICABLE: false
|
|
||||||
|
|
||||||
class MyClass {
|
class MyClass {
|
||||||
fun foo1(a: MyClass): MyClass = this
|
fun foo1(a: MyClass): MyClass = this
|
||||||
@@ -9,5 +8,7 @@ class MyClass {
|
|||||||
fun foo4(a: MyClass) {
|
fun foo4(a: MyClass) {
|
||||||
a.foo1(this).foo2().foo3()
|
a.foo1(this).foo2().foo3()
|
||||||
a.foo2()<caret>
|
a.foo2()<caret>
|
||||||
|
a.foo3()
|
||||||
|
a.foo1(this).foo2().foo3()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+16
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C()
|
||||||
|
c.foo()<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val c = C()
|
||||||
|
with(c) {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7553,6 +7553,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/convertToScope/convertToAlso/onProperty.kt");
|
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")
|
@TestMetadata("untilItParameter.kt")
|
||||||
public void testUntilItParameter() throws Exception {
|
public void testUntilItParameter() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertToScope/convertToAlso/untilItParameter.kt");
|
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");
|
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")
|
@TestMetadata("thisParameter.kt")
|
||||||
public void testThisParameter() throws Exception {
|
public void testThisParameter() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertToScope/convertToApply/thisParameter.kt");
|
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");
|
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")
|
@TestMetadata("thisParameter.kt")
|
||||||
public void testThisParameter() throws Exception {
|
public void testThisParameter() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertToScope/convertToRun/thisParameter.kt");
|
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");
|
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")
|
@TestMetadata("thisParameter.kt")
|
||||||
public void testThisParameter() throws Exception {
|
public void testThisParameter() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertToScope/convertToWith/thisParameter.kt");
|
runTest("idea/testData/intentions/convertToScope/convertToWith/thisParameter.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user