FIR IDE: Enable ChangeVariableMutabilityFix for MUST_BE_INITIALIZED.

This commit is contained in:
Mark Punzalan
2021-03-10 22:08:33 +00:00
committed by Ilya Kirillov
parent 09fb2cd746
commit bb790195a2
11 changed files with 80 additions and 9 deletions
@@ -1127,7 +1127,7 @@ fun main(args: Array<String>) {
model("quickfix/lateinit", pattern = pattern, filenameStartsLowerCase = true) model("quickfix/lateinit", pattern = pattern, filenameStartsLowerCase = true)
model("quickfix/modifiers", pattern = pattern, filenameStartsLowerCase = true, recursive = false) model("quickfix/modifiers", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
model("quickfix/override/typeMismatchOnOverride", pattern = pattern, filenameStartsLowerCase = true, recursive = false) model("quickfix/override/typeMismatchOnOverride", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
model("quickfix/variables/changeMutability", pattern = pattern, filenameStartsLowerCase = true, recursive = false) model("quickfix/variables/changeMutability", pattern = pattern, filenameStartsLowerCase = true)
} }
testClass<AbstractHLInspectionTest> { testClass<AbstractHLInspectionTest> {
@@ -61,6 +61,7 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() {
registerPsiQuickFixes(KtFirDiagnostic.VarAnnotationParameter::class, ChangeVariableMutabilityFix.VAR_ANNOTATION_PARAMETER_FACTORY) registerPsiQuickFixes(KtFirDiagnostic.VarAnnotationParameter::class, ChangeVariableMutabilityFix.VAR_ANNOTATION_PARAMETER_FACTORY)
registerPsiQuickFixes(KtFirDiagnostic.InapplicableLateinitModifier::class, ChangeVariableMutabilityFix.LATEINIT_VAL_FACTORY) registerPsiQuickFixes(KtFirDiagnostic.InapplicableLateinitModifier::class, ChangeVariableMutabilityFix.LATEINIT_VAL_FACTORY)
registerPsiQuickFixes(KtFirDiagnostic.ValWithSetter::class, ChangeVariableMutabilityFix.VAL_WITH_SETTER_FACTORY) registerPsiQuickFixes(KtFirDiagnostic.ValWithSetter::class, ChangeVariableMutabilityFix.VAL_WITH_SETTER_FACTORY)
registerPsiQuickFixes(KtFirDiagnostic.MustBeInitialized::class, ChangeVariableMutabilityFix.MUST_BE_INITIALIZED_FACTORY)
} }
override val list: KtQuickFixesList = KtQuickFixesList.createCombined( override val list: KtQuickFixesList = KtQuickFixesList.createCombined(
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.quickfix package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.InspectionProfileEntry
import org.jetbrains.kotlin.test.uitls.IgnoreTests import org.jetbrains.kotlin.test.uitls.IgnoreTests
import java.nio.file.Paths import java.nio.file.Paths
@@ -22,6 +23,10 @@ abstract class AbstractHighLevelQuickFixTest : AbstractQuickFixTest() {
} }
} }
// TODO: Enable these as more actions/inspections are enabled, and/or add more FIR-specific directives
override fun checkForUnexpectedErrors() {} override fun checkForUnexpectedErrors() {}
override fun checkAvailableActionsAreExpected(actions: List<IntentionAction>) {} override fun checkAvailableActionsAreExpected(actions: List<IntentionAction>) {}
override fun parseInspectionsToEnable(beforeFileName: String, beforeFileText: String): List<InspectionProfileEntry> {
return emptyList()
}
} }
@@ -695,7 +695,7 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
} }
public void testAllFilesPresentInChangeMutability() throws Exception { public void testAllFilesPresentInChangeMutability() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/variables/changeMutability"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, false); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/variables/changeMutability"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
} }
@TestMetadata("capturedMemberValInitialization.kt") @TestMetadata("capturedMemberValInitialization.kt")
@@ -762,5 +762,63 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
public void testVarAnnotationParameter() throws Exception { public void testVarAnnotationParameter() throws Exception {
runTest("idea/testData/quickfix/variables/changeMutability/varAnnotationParameter.kt"); runTest("idea/testData/quickfix/variables/changeMutability/varAnnotationParameter.kt");
} }
@TestMetadata("idea/testData/quickfix/variables/changeMutability/canBeVal")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class CanBeVal extends AbstractHighLevelQuickFixTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInCanBeVal() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/variables/changeMutability/canBeVal"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
}
@TestMetadata("const.kt")
public void testConst() throws Exception {
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/const.kt");
}
@TestMetadata("delegatedProperty.kt")
public void testDelegatedProperty() throws Exception {
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/delegatedProperty.kt");
}
@TestMetadata("delegatedProperty2.kt")
public void testDelegatedProperty2() throws Exception {
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/delegatedProperty2.kt");
}
@TestMetadata("delegatedProperty3.kt")
public void testDelegatedProperty3() throws Exception {
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/delegatedProperty3.kt");
}
@TestMetadata("multiVariable.kt")
public void testMultiVariable() throws Exception {
runTest("idea/testData/quickfix/variables/changeMutability/canBeVal/multiVariable.kt");
}
@TestMetadata("singleVariable.kt")
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");
}
}
} }
} }
@@ -13,3 +13,4 @@ class Delegate {
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) { operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
} }
} }
/* FIR_COMPARISON */
@@ -11,3 +11,4 @@ fun test() {
} }
class Delegate class Delegate
/* FIR_COMPARISON */
@@ -3,3 +3,4 @@ class Test {
var foo<caret> var foo<caret>
get() = 1 get() = 1
} }
/* FIR_COMPARISON */
@@ -3,3 +3,4 @@ class Test {
val foo val foo
get() = 1 get() = 1
} }
/* FIR_COMPARISON */
@@ -5,3 +5,4 @@ class Test {
return 1 return 1
} }
} }
/* FIR_COMPARISON */
@@ -5,3 +5,4 @@ class Test {
return 1 return 1
} }
} }
/* FIR_COMPARISON */
@@ -12,3 +12,4 @@ class Test {
return 1 return 1
} }
} }
/* FIR_COMPARISON */