"Introduce backing property" intention: don't suggest if property has @JvmField annotation #KT-27156 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
ca335880eb
commit
487b1e96be
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
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.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
@@ -39,6 +40,7 @@ class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(KtP
|
|||||||
companion object {
|
companion object {
|
||||||
fun canIntroduceBackingProperty(property: KtProperty): Boolean {
|
fun canIntroduceBackingProperty(property: KtProperty): Boolean {
|
||||||
val name = property.name ?: return false
|
val name = property.name ?: return false
|
||||||
|
if (property.hasJvmFieldAnnotation()) return false
|
||||||
|
|
||||||
val bindingContext = property.getResolutionFacade().analyzeWithAllCompilerChecks(listOf(property)).bindingContext
|
val bindingContext = property.getResolutionFacade().analyzeWithAllCompilerChecks(listOf(property)).bindingContext
|
||||||
val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property) as? PropertyDescriptor ?: return false
|
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");
|
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")
|
@TestMetadata("semicolon.kt")
|
||||||
public void testSemicolon() throws Exception {
|
public void testSemicolon() throws Exception {
|
||||||
runTest("idea/testData/intentions/introduceBackingProperty/semicolon.kt");
|
runTest("idea/testData/intentions/introduceBackingProperty/semicolon.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user