From 487b1e96be0b49e2d15930436f8bf53c887dfb8e Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Fri, 12 Oct 2018 01:50:57 +0900 Subject: [PATCH] "Introduce backing property" intention: don't suggest if property has @JvmField annotation #KT-27156 Fixed --- .../idea/intentions/IntroduceBackingPropertyIntention.kt | 2 ++ .../intentions/introduceBackingProperty/jvmField.kt | 6 ++++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 idea/testData/intentions/introduceBackingProperty/jvmField.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt index 1e58ec9d353..1db3e1273ef 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall +import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -39,6 +40,7 @@ class IntroduceBackingPropertyIntention : SelfTargetingIntention(KtP companion object { fun canIntroduceBackingProperty(property: KtProperty): Boolean { val name = property.name ?: return false + if (property.hasJvmFieldAnnotation()) return false val bindingContext = property.getResolutionFacade().analyzeWithAllCompilerChecks(listOf(property)).bindingContext val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property) as? PropertyDescriptor ?: return false diff --git a/idea/testData/intentions/introduceBackingProperty/jvmField.kt b/idea/testData/intentions/introduceBackingProperty/jvmField.kt new file mode 100644 index 00000000000..081b8538d11 --- /dev/null +++ b/idea/testData/intentions/introduceBackingProperty/jvmField.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +class Test { + @JvmField + val foo = 1 +} \ 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 c292f485358..7db4b1db6c3 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -9239,6 +9239,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/introduceBackingProperty/inapplicableNoBackingField.kt"); } + @TestMetadata("jvmField.kt") + public void testJvmField() throws Exception { + runTest("idea/testData/intentions/introduceBackingProperty/jvmField.kt"); + } + @TestMetadata("semicolon.kt") public void testSemicolon() throws Exception { runTest("idea/testData/intentions/introduceBackingProperty/semicolon.kt");