Convert property to function: remove annotation use-site target

#KT-36834 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-02-20 12:12:59 +09:00
committed by Vladimir Dolzhenko
parent d5e71ebef1
commit d8ab046136
4 changed files with 26 additions and 0 deletions
@@ -83,6 +83,11 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(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))
}
@@ -0,0 +1,8 @@
annotation class A
annotation class B
interface Foo {
@get:A
@B
val <caret>bar: String
}
@@ -0,0 +1,8 @@
annotation class A
annotation class B
interface Foo {
@A
@B
fun getBar(): String
}
@@ -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");