"Introduce backing property" intention: don't suggest if property has @JvmField annotation #KT-27156 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-10-12 01:50:57 +09:00
committed by Mikhail Glukhikh
parent ca335880eb
commit 487b1e96be
3 changed files with 13 additions and 0 deletions
@@ -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<KtProperty>(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
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
class Test {
@JvmField
val foo<caret> = 1
}
@@ -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");