FIR IDE: RemoveNulalbleFix quickfix
This commit is contained in:
committed by
Ilya Kirillov
parent
b10de3dd2d
commit
4bedf41f9c
+1
-1
@@ -1171,7 +1171,7 @@ fun main(args: Array<String>) {
|
|||||||
model("quickfix/expressions", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/expressions", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
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/nullables/unsafeInfixCall", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/nullables", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
model("quickfix/override", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
|
model("quickfix/override", 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/replaceInfixOrOperatorCall", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/replaceInfixOrOperatorCall", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
|
|||||||
@@ -132,6 +132,9 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() {
|
|||||||
registerApplicator(WrapWithSafeLetCallFixFactories.forUnsafeInfixCall)
|
registerApplicator(WrapWithSafeLetCallFixFactories.forUnsafeInfixCall)
|
||||||
registerApplicator(WrapWithSafeLetCallFixFactories.forUnsafeOperatorCall)
|
registerApplicator(WrapWithSafeLetCallFixFactories.forUnsafeOperatorCall)
|
||||||
registerApplicator(WrapWithSafeLetCallFixFactories.forArgumentTypeMismatch)
|
registerApplicator(WrapWithSafeLetCallFixFactories.forArgumentTypeMismatch)
|
||||||
|
|
||||||
|
registerPsiQuickFixes(KtFirDiagnostic.NullableSupertype::class, RemoveNullableFix.removeForSuperType)
|
||||||
|
registerPsiQuickFixes(KtFirDiagnostic.InapplicableLateinitModifier::class, RemoveNullableFix.removeForLateInitProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val returnTypes = KtQuickFixesListBuilder.registerPsiQuickFix {
|
private val returnTypes = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||||
|
|||||||
Generated
+80
-47
@@ -1133,76 +1133,109 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/nullables/unsafeInfixCall")
|
@TestMetadata("idea/testData/quickfix/nullables")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class UnsafeInfixCall extends AbstractHighLevelQuickFixTest {
|
public static class Nullables extends AbstractHighLevelQuickFixTest {
|
||||||
private void runTest(String testDataFilePath) throws Exception {
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInUnsafeInfixCall() throws Exception {
|
public void testAllFilesPresentInNullables() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/nullables/unsafeInfixCall"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/nullables"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("noComparison.kt")
|
@TestMetadata("removeRedundantNullable.kt")
|
||||||
public void testNoComparison() throws Exception {
|
public void testRemoveRedundantNullable() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/noComparison.kt");
|
runTest("idea/testData/quickfix/nullables/removeRedundantNullable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeComparisonInCondition.kt")
|
@TestMetadata("removeSupertypeNullable1.kt")
|
||||||
public void testUnsafeComparisonInCondition() throws Exception {
|
public void testRemoveSupertypeNullable1() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInCondition.kt");
|
runTest("idea/testData/quickfix/nullables/removeSupertypeNullable1.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeComparisonInLogic.kt")
|
@TestMetadata("removeSupertypeNullable2.kt")
|
||||||
public void testUnsafeComparisonInLogic() throws Exception {
|
public void testRemoveSupertypeNullable2() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInLogic.kt");
|
runTest("idea/testData/quickfix/nullables/removeSupertypeNullable2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeComparisonInWhen.kt")
|
@TestMetadata("removeUselessNullable.kt")
|
||||||
public void testUnsafeComparisonInWhen() throws Exception {
|
public void testRemoveUselessNullable() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhen.kt");
|
runTest("idea/testData/quickfix/nullables/removeUselessNullable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeComparisonInWhile.kt")
|
@TestMetadata("idea/testData/quickfix/nullables/unsafeInfixCall")
|
||||||
public void testUnsafeComparisonInWhile() throws Exception {
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhile.kt");
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
}
|
public static class UnsafeInfixCall extends AbstractHighLevelQuickFixTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeGet.kt")
|
public void testAllFilesPresentInUnsafeInfixCall() throws Exception {
|
||||||
public void testUnsafeGet() throws Exception {
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/nullables/unsafeInfixCall"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeGet.kt");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("unsafeInfixCall.kt")
|
@TestMetadata("noComparison.kt")
|
||||||
public void testUnsafeInfixCall() throws Exception {
|
public void testNoComparison() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInfixCall.kt");
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/noComparison.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeInvoke.kt")
|
@TestMetadata("unsafeComparisonInCondition.kt")
|
||||||
public void testUnsafeInvoke() throws Exception {
|
public void testUnsafeComparisonInCondition() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInvoke.kt");
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInCondition.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeInvokeWithImplicitReceiver.kt")
|
@TestMetadata("unsafeComparisonInLogic.kt")
|
||||||
public void testUnsafeInvokeWithImplicitReceiver() throws Exception {
|
public void testUnsafeComparisonInLogic() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInvokeWithImplicitReceiver.kt");
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInLogic.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeInvokeWithReceiver.kt")
|
@TestMetadata("unsafeComparisonInWhen.kt")
|
||||||
public void testUnsafeInvokeWithReceiver() throws Exception {
|
public void testUnsafeComparisonInWhen() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInvokeWithReceiver.kt");
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhen.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafePlus.kt")
|
@TestMetadata("unsafeComparisonInWhile.kt")
|
||||||
public void testUnsafePlus() throws Exception {
|
public void testUnsafeComparisonInWhile() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafePlus.kt");
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhile.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeSet.kt")
|
@TestMetadata("unsafeGet.kt")
|
||||||
public void testUnsafeSet() throws Exception {
|
public void testUnsafeGet() throws Exception {
|
||||||
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeSet.kt");
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeGet.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafeInfixCall.kt")
|
||||||
|
public void testUnsafeInfixCall() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInfixCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafeInvoke.kt")
|
||||||
|
public void testUnsafeInvoke() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInvoke.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafeInvokeWithImplicitReceiver.kt")
|
||||||
|
public void testUnsafeInvokeWithImplicitReceiver() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInvokeWithImplicitReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafeInvokeWithReceiver.kt")
|
||||||
|
public void testUnsafeInvokeWithReceiver() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeInvokeWithReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafePlus.kt")
|
||||||
|
public void testUnsafePlus() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafePlus.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafeSet.kt")
|
||||||
|
public void testUnsafeSet() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/nullables/unsafeInfixCall/unsafeSet.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -8,10 +8,7 @@ package org.jetbrains.kotlin.idea.quickfix
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
|
||||||
import org.jetbrains.kotlin.psi.KtNullableType
|
|
||||||
import org.jetbrains.kotlin.psi.KtProperty
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
|
|
||||||
class RemoveNullableFix(element: KtNullableType, private val typeOfError: NullableKind) :
|
class RemoveNullableFix(element: KtNullableType, private val typeOfError: NullableKind) :
|
||||||
@@ -43,7 +40,10 @@ class RemoveNullableFix(element: KtNullableType, private val typeOfError: Nullab
|
|||||||
return quickFixesPsiBasedFactory { e ->
|
return quickFixesPsiBasedFactory { e ->
|
||||||
when (typeOfError) {
|
when (typeOfError) {
|
||||||
NullableKind.REDUNDANT, NullableKind.SUPERTYPE, NullableKind.USELESS -> {
|
NullableKind.REDUNDANT, NullableKind.SUPERTYPE, NullableKind.USELESS -> {
|
||||||
val nullType = e.getNonStrictParentOfType<KtNullableType>()
|
val nullType: KtNullableType? = when (e) {
|
||||||
|
is KtTypeReference -> e.typeElement as? KtNullableType
|
||||||
|
else -> e.getNonStrictParentOfType()
|
||||||
|
}
|
||||||
if (nullType?.innerType == null) return@quickFixesPsiBasedFactory emptyList()
|
if (nullType?.innerType == null) return@quickFixesPsiBasedFactory emptyList()
|
||||||
listOf(RemoveNullableFix(nullType, typeOfError))
|
listOf(RemoveNullableFix(nullType, typeOfError))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -2,5 +2,4 @@
|
|||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
<caret>lateinit var foo: String?
|
<caret>lateinit var foo: String?
|
||||||
}
|
}
|
||||||
/* IGNORE_FIR */
|
|
||||||
+1
-2
@@ -2,5 +2,4 @@
|
|||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
<caret>lateinit var foo: String
|
<caret>lateinit var foo: String
|
||||||
}
|
}
|
||||||
/* IGNORE_FIR */
|
|
||||||
@@ -2,3 +2,5 @@
|
|||||||
fun main(args : Array<String>) {
|
fun main(args : Array<String>) {
|
||||||
val x : Int??<caret> = 15
|
val x : Int??<caret> = 15
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* IGNORE_FIR */
|
||||||
@@ -2,3 +2,5 @@
|
|||||||
fun main(args : Array<String>) {
|
fun main(args : Array<String>) {
|
||||||
val x : Int? = 15
|
val x : Int? = 15
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* IGNORE_FIR */
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Remove useless '?'" "true"
|
// "Remove useless '?'" "true"
|
||||||
fun f(a: Int) : Boolean {
|
fun f(a: Int) : Boolean {
|
||||||
return a is Int?<caret>
|
return a is Int?<caret>
|
||||||
}
|
}
|
||||||
|
/* IGNORE_FIR */
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Remove useless '?'" "true"
|
// "Remove useless '?'" "true"
|
||||||
fun f(a: Int) : Boolean {
|
fun f(a: Int) : Boolean {
|
||||||
return a is Int<caret>
|
return a is Int<caret>
|
||||||
}
|
}
|
||||||
|
/* IGNORE_FIR */
|
||||||
Reference in New Issue
Block a user