Add "Change to val" quick fix for MUST_BE_INITIALIZED
#KT-15723 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
a46c6ce5df
commit
c87bc2123c
@@ -128,5 +128,15 @@ class ChangeVariableMutabilityFix(
|
||||
return ChangeVariableMutabilityFix(property, makeVar = false, actionText = "Change to val")
|
||||
}
|
||||
}
|
||||
|
||||
val MUST_BE_INITIALIZED_FACTORY = object : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val property = Errors.MUST_BE_INITIALIZED.cast(diagnostic).psiElement as? KtProperty ?: return null
|
||||
val getter = property.getter ?: return null
|
||||
if (!getter.hasBody()) return null
|
||||
if (getter.hasBlockBody() && property.typeReference == null) return null
|
||||
return ChangeVariableMutabilityFix(property, makeVar = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,5 +639,6 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
|
||||
ACCIDENTAL_OVERRIDE.registerFactory(MakePrivateAndOverrideMemberFix.AccidentalOverrideFactory)
|
||||
|
||||
MUST_BE_INITIALIZED.registerFactory(ChangeVariableMutabilityFix.MUST_BE_INITIALIZED_FACTORY)
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Change to val" "true"
|
||||
class Test {
|
||||
var foo<caret>
|
||||
get() = 1
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// "Change to val" "true"
|
||||
class Test {
|
||||
val foo
|
||||
get() = 1
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Change to val" "true"
|
||||
class Test {
|
||||
var foo: Int<caret>
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// "Change to val" "true"
|
||||
class Test {
|
||||
val foo: Int
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Change to val" "false"
|
||||
// ACTION: Add initializer
|
||||
// ACTION: Convert member to extension
|
||||
// ACTION: Initialize with constructor parameter
|
||||
// ACTION: Introduce backing property
|
||||
// ACTION: Move to companion object
|
||||
// ACTION: Specify type explicitly
|
||||
// ERROR: Property must be initialized
|
||||
class Test {
|
||||
var foo<caret>
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
@@ -14542,6 +14542,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
public void testSingleVariable() throws Exception {
|
||||
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/singleVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("uninitializedWithGetter.kt")
|
||||
public void testUninitializedWithGetter() throws Exception {
|
||||
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/uninitializedWithGetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("uninitializedWithGetter2.kt")
|
||||
public void testUninitializedWithGetter2() throws Exception {
|
||||
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/uninitializedWithGetter2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("uninitializedWithGetter3.kt")
|
||||
public void testUninitializedWithGetter3() throws Exception {
|
||||
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/uninitializedWithGetter3.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user