diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt index 283b292d6ab..cb058b00872 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt @@ -83,6 +83,11 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention(Kt } } property.setName(newName) + property.annotationEntries.forEach { + if (it.useSiteTarget != null) { + it.replace(psiFactory.createAnnotationEntry("@${it.shortName}${it.valueArgumentList?.text ?: ""}")) + } + } originalProperty.replace(psiFactory.createFunction(property.text)) } diff --git a/idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt b/idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt new file mode 100644 index 00000000000..860a5e4ee51 --- /dev/null +++ b/idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt @@ -0,0 +1,8 @@ +annotation class A +annotation class B + +interface Foo { + @get:A + @B + val bar: String +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt.after b/idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt.after new file mode 100644 index 00000000000..f7192d8fc01 --- /dev/null +++ b/idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt.after @@ -0,0 +1,8 @@ +annotation class A +annotation class B + +interface Foo { + @A + @B + fun getBar(): String +} \ 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 c6adee11e8a..11380b1a0da 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -5893,6 +5893,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/convertPropertyToFunction"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); } + @TestMetadata("annotationUseSiteTarget.kt") + public void testAnnotationUseSiteTarget() throws Exception { + runTest("idea/testData/intentions/convertPropertyToFunction/annotationUseSiteTarget.kt"); + } + @TestMetadata("blockBody.kt") public void testBlockBody() throws Exception { runTest("idea/testData/intentions/convertPropertyToFunction/blockBody.kt");