Extract Interface: Fix type import when converting parameter to property
#KT-18736 Fixed
This commit is contained in:
@@ -80,7 +80,17 @@ private fun KtParameter.needToBeAbstract(targetClass: KtClassOrObject): Boolean
|
|||||||
return hasModifier(KtTokens.ABSTRACT_KEYWORD) || targetClass is KtClass && targetClass.isInterface()
|
return hasModifier(KtTokens.ABSTRACT_KEYWORD) || targetClass is KtClass && targetClass.isInterface()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtParameter.toProperty(): KtProperty = KtPsiFactory(this).createProperty(text)
|
private fun KtParameter.toProperty(): KtProperty =
|
||||||
|
KtPsiFactory(this)
|
||||||
|
.createProperty(text)
|
||||||
|
.also {
|
||||||
|
val originalTypeRef = typeReference
|
||||||
|
val generatedTypeRef = it.typeReference
|
||||||
|
if (originalTypeRef != null && generatedTypeRef != null) {
|
||||||
|
// Preserve copyable user data of original type reference
|
||||||
|
generatedTypeRef.replace(originalTypeRef)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun doAddCallableMember(
|
fun doAddCallableMember(
|
||||||
memberCopy: KtCallableDeclaration,
|
memberCopy: KtCallableDeclaration,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
class Foo
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
import foo.Z
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
interface ISomething {
|
||||||
|
val z: Z
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
class Z
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
class Z
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// NAME: ISomething
|
||||||
|
// TARGET_FILE_NAME: addImportOnParameterPullUp.1.kt
|
||||||
|
import foo.Z
|
||||||
|
|
||||||
|
class <caret>C(
|
||||||
|
// INFO: {checked: "true", toAbstract: "true"}
|
||||||
|
val z: Z
|
||||||
|
)
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// NAME: ISomething
|
||||||
|
// TARGET_FILE_NAME: addImportOnParameterPullUp.1.kt
|
||||||
|
import foo.Z
|
||||||
|
|
||||||
|
class C(
|
||||||
|
// INFO: {checked: "true", toAbstract: "true"}
|
||||||
|
override val z: Z
|
||||||
|
) : ISomething
|
||||||
+5
@@ -4039,6 +4039,11 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
|||||||
runTest("idea/testData/refactoring/extractInterface/abstractedMemberUsingPrivate.kt");
|
runTest("idea/testData/refactoring/extractInterface/abstractedMemberUsingPrivate.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addImportOnParameterPullUp.kt")
|
||||||
|
public void testAddImportOnParameterPullUp() throws Exception {
|
||||||
|
runTest("idea/testData/refactoring/extractInterface/addImportOnParameterPullUp.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("addInterface.kt")
|
@TestMetadata("addInterface.kt")
|
||||||
public void testAddInterface() throws Exception {
|
public void testAddInterface() throws Exception {
|
||||||
runTest("idea/testData/refactoring/extractInterface/addInterface.kt");
|
runTest("idea/testData/refactoring/extractInterface/addInterface.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user