Convert property to function: fix incorrectly conversion when property has explicit generic type

#KT-29192 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-05-15 11:44:49 +09:00
committed by Dmitry Gridin
parent 354f8f0bf1
commit 6ff776ba65
4 changed files with 21 additions and 0 deletions
@@ -75,6 +75,11 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
.first { it !is PsiWhiteSpace }
.nextSibling
property.deleteChildRange(dropPropertyFrom, getter.prevSibling)
val typeReference = property.typeReference
if (typeReference != null) {
property.addAfter(psiFactory.createWhiteSpace(), typeReference)
}
}
}
property.setName(newName)
@@ -0,0 +1,6 @@
class Test {
val <caret>foo: Foo<String>
get() = Foo()
}
class Foo<T>
@@ -0,0 +1,5 @@
class Test {
fun getFoo(): Foo<String> = Foo()
}
class Foo<T>
@@ -6614,6 +6614,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/convertPropertyToFunction/expressionBody.kt");
}
@TestMetadata("expressionBodyWithGenericType.kt")
public void testExpressionBodyWithGenericType() throws Exception {
runTest("idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt");
}
@TestMetadata("initializer.kt")
public void testInitializer() throws Exception {
runTest("idea/testData/intentions/convertPropertyToFunction/initializer.kt");