Introduce backing property: fix false positive for const property #KT-28341 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
7080559cb4
commit
e5f0f2489f
@@ -40,6 +40,7 @@ class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(KtP
|
||||
companion object {
|
||||
fun canIntroduceBackingProperty(property: KtProperty): Boolean {
|
||||
val name = property.name ?: return false
|
||||
if (property.hasModifier(KtTokens.CONST_KEYWORD)) return false
|
||||
if (property.hasJvmFieldAnnotation()) return false
|
||||
|
||||
val bindingContext = property.getResolutionFacade().analyzeWithAllCompilerChecks(listOf(property)).bindingContext
|
||||
@@ -61,8 +62,7 @@ class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(KtP
|
||||
val getter = property.getter
|
||||
if (getter == null) {
|
||||
createGetter(property)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
replaceFieldReferences(getter, property.name!!)
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(KtP
|
||||
val setter = property.setter
|
||||
if (setter == null) {
|
||||
createSetter(property)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
replaceFieldReferences(setter, property.name!!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
class C {
|
||||
companion object {
|
||||
const val <caret>CONST = 1
|
||||
}
|
||||
}
|
||||
@@ -9289,6 +9289,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/introduceBackingProperty/backingFieldRef.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("const.kt")
|
||||
public void testConst() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceBackingProperty/const.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inapplicableAbstractProperty.kt")
|
||||
public void testInapplicableAbstractProperty() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceBackingProperty/inapplicableAbstractProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user