Change function signature: add/change receiver type

#KT-21799 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-10 17:31:50 +09:00
committed by klunnii
parent 9f3ce099ee
commit f20a6b7fe1
6 changed files with 51 additions and 2 deletions
@@ -338,8 +338,15 @@ class ChangeMemberFunctionSignatureFix private constructor(
} as KtParameterList
ShortenReferences.DEFAULT.process(newParameterList)
if (patternFunction.receiverTypeReference == null && function.receiverTypeReference != null) {
function.setReceiverTypeReference(null)
val patternFunctionReceiver = patternFunction.receiverTypeReference
if (patternFunctionReceiver == null) {
if (function.receiverTypeReference != null) {
function.setReceiverTypeReference(null)
}
} else {
function.setReceiverTypeReference(patternFunction.receiverTypeReference)?.let {
ShortenReferences.DEFAULT.process(it)
}
}
val patternTypeParameterList = patternFunction.typeParameterList
@@ -0,0 +1,8 @@
// "Change function signature to 'fun Int.foo(a: String)'" "true"
abstract class C {
abstract fun Int.foo(a: String)
}
class B : C() {
<caret>override fun foo(a: Int) {}
}
@@ -0,0 +1,8 @@
// "Change function signature to 'fun Int.foo(a: String)'" "true"
abstract class C {
abstract fun Int.foo(a: String)
}
class B : C() {
override fun Int.foo(a: String) {}
}
@@ -0,0 +1,8 @@
// "Change function signature to 'fun Int.foo(a: String)'" "true"
abstract class C {
abstract fun Int.foo(a: String)
}
class B : C() {
<caret>override fun String.foo(a: Int) {}
}
@@ -0,0 +1,8 @@
// "Change function signature to 'fun Int.foo(a: String)'" "true"
abstract class C {
abstract fun Int.foo(a: String)
}
class B : C() {
override fun Int.foo(a: String) {}
}
@@ -10162,6 +10162,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/override/nothingToOverride/addFunctionNonUnitReturnType.kt");
}
@TestMetadata("addFunctionReciever.kt")
public void testAddFunctionReciever() throws Exception {
runTest("idea/testData/quickfix/override/nothingToOverride/addFunctionReciever.kt");
}
@TestMetadata("addFunctionSealedClass.kt")
public void testAddFunctionSealedClass() throws Exception {
runTest("idea/testData/quickfix/override/nothingToOverride/addFunctionSealedClass.kt");
@@ -10226,6 +10231,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/override/nothingToOverride"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
}
@TestMetadata("changeFunctionReciever.kt")
public void testChangeFunctionReciever() throws Exception {
runTest("idea/testData/quickfix/override/nothingToOverride/changeFunctionReciever.kt");
}
@TestMetadata("changeParameterType.kt")
public void testChangeParameterType() throws Exception {
runTest("idea/testData/quickfix/override/nothingToOverride/changeParameterType.kt");