diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt index c583d5a8011..d3f29941aa6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt @@ -75,6 +75,11 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention(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) diff --git a/idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt b/idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt new file mode 100644 index 00000000000..ace3789e046 --- /dev/null +++ b/idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt @@ -0,0 +1,6 @@ +class Test { + val foo: Foo + get() = Foo() +} + +class Foo \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt.after b/idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt.after new file mode 100644 index 00000000000..910b14e3bfe --- /dev/null +++ b/idea/testData/intentions/convertPropertyToFunction/expressionBodyWithGenericType.kt.after @@ -0,0 +1,5 @@ +class Test { + fun getFoo(): Foo = Foo() +} + +class 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 7050220355e..c677e94b0c7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -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");