FIR IDE: Enable AddExclExclCallFix for ASSIGNMENT_TYPE_MISMATCH and
INITIALIZER_TYPE_MISMATCH.
This commit is contained in:
committed by
teamcityserver
parent
eddc590aaf
commit
c6427d57f1
@@ -118,6 +118,8 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() {
|
|||||||
registerApplicator(AddExclExclCallFixFactories.iteratorOnNullableFactory)
|
registerApplicator(AddExclExclCallFixFactories.iteratorOnNullableFactory)
|
||||||
registerApplicator(TypeMismatchFactories.argumentTypeMismatchFactory)
|
registerApplicator(TypeMismatchFactories.argumentTypeMismatchFactory)
|
||||||
registerApplicator(TypeMismatchFactories.returnTypeMismatchFactory)
|
registerApplicator(TypeMismatchFactories.returnTypeMismatchFactory)
|
||||||
|
registerApplicator(TypeMismatchFactories.assignmentTypeMismatch)
|
||||||
|
registerApplicator(TypeMismatchFactories.initializerTypeMismatch)
|
||||||
|
|
||||||
// TODO: NON_EXHAUSTIVE_WHEN[_ON_SEALED_CLASS] will be replaced in future. We need to register the fix for those diagnostics as well
|
// TODO: NON_EXHAUSTIVE_WHEN[_ON_SEALED_CLASS] will be replaced in future. We need to register the fix for those diagnostics as well
|
||||||
registerPsiQuickFixes(KtFirDiagnostic.NoElseInWhen::class, AddWhenElseBranchFix)
|
registerPsiQuickFixes(KtFirDiagnostic.NoElseInWhen::class, AddWhenElseBranchFix)
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ object TypeMismatchFactories {
|
|||||||
getFixesForTypeMismatch(diagnostic.psi, diagnostic.expectedType, diagnostic.actualType)
|
getFixesForTypeMismatch(diagnostic.psi, diagnostic.expectedType, diagnostic.actualType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val assignmentTypeMismatch = diagnosticFixFactory<KtFirDiagnostic.AssignmentTypeMismatch> { diagnostic ->
|
||||||
|
getFixesForTypeMismatch(diagnostic.psi, diagnostic.expectedType, diagnostic.actualType)
|
||||||
|
}
|
||||||
|
|
||||||
|
val initializerTypeMismatch = diagnosticFixFactory<KtFirDiagnostic.InitializerTypeMismatch> { diagnostic ->
|
||||||
|
diagnostic.psi.initializer?.let { getFixesForTypeMismatch(it, diagnostic.expectedType, diagnostic.actualType) } ?: emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
private fun KtAnalysisSession.getFixesForTypeMismatch(
|
private fun KtAnalysisSession.getFixesForTypeMismatch(
|
||||||
psi: PsiElement,
|
psi: PsiElement,
|
||||||
expectedType: KtType,
|
expectedType: KtType,
|
||||||
|
|||||||
Generated
+10
@@ -361,6 +361,11 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/assignmentRValue.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/assignmentRValue.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initializer.kt")
|
||||||
|
public void testInitializer() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/initializer.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("memberAccessInExtension.kt")
|
@TestMetadata("memberAccessInExtension.kt")
|
||||||
public void testMemberAccessInExtension() throws Exception {
|
public void testMemberAccessInExtension() throws Exception {
|
||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtension.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtension.kt");
|
||||||
@@ -371,6 +376,11 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtensionAsAssignmentRValue.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtensionAsAssignmentRValue.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("memberAccessInExtensionAsInitializer.kt")
|
||||||
|
public void testMemberAccessInExtensionAsInitializer() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtensionAsInitializer.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullArgument.kt")
|
@TestMetadata("nullArgument.kt")
|
||||||
public void testNullArgument() throws Exception {
|
public void testNullArgument() throws Exception {
|
||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/nullArgument.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/nullArgument.kt");
|
||||||
|
|||||||
@@ -9,3 +9,6 @@ fun foo(arg: String?) {
|
|||||||
val x: String = arg<caret>
|
val x: String = arg<caret>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Need data flow info from null check
|
||||||
|
/* IGNORE_FIR */
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// "Add non-null asserted (!!) call" "true"
|
// "Add non-null asserted (!!) call" "true"
|
||||||
fun test() {
|
fun test(s: String?) {
|
||||||
val s: String? = null
|
var z: String = ""
|
||||||
val z: String = <caret>s
|
z = <caret>s
|
||||||
}
|
}
|
||||||
// TODO: Enable when FIR reports TYPE_MISMATCH for assignments
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
|
|||||||
+3
-5
@@ -1,7 +1,5 @@
|
|||||||
// "Add non-null asserted (!!) call" "true"
|
// "Add non-null asserted (!!) call" "true"
|
||||||
fun test() {
|
fun test(s: String?) {
|
||||||
val s: String? = null
|
var z: String = ""
|
||||||
val z: String = s!!
|
z = s!!
|
||||||
}
|
}
|
||||||
// TODO: Enable when FIR reports TYPE_MISMATCH for assignments
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Add non-null asserted (!!) call" "true"
|
||||||
|
fun test(s: String?) {
|
||||||
|
val z: String = <caret>s
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Add non-null asserted (!!) call" "true"
|
||||||
|
fun test(s: String?) {
|
||||||
|
val z: String = s!!
|
||||||
|
}
|
||||||
Vendored
+2
-3
@@ -5,7 +5,6 @@ class C {
|
|||||||
|
|
||||||
// Test for KTIJ-10052
|
// Test for KTIJ-10052
|
||||||
fun C.test() {
|
fun C.test() {
|
||||||
val z: String = <caret>s
|
var z: String = ""
|
||||||
|
z = <caret>s
|
||||||
}
|
}
|
||||||
// TODO: Enable when FIR reports TYPE_MISMATCH for assignments
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
|
|||||||
+2
-3
@@ -5,7 +5,6 @@ class C {
|
|||||||
|
|
||||||
// Test for KTIJ-10052
|
// Test for KTIJ-10052
|
||||||
fun C.test() {
|
fun C.test() {
|
||||||
val z: String = s!!
|
var z: String = ""
|
||||||
|
z = s!!
|
||||||
}
|
}
|
||||||
// TODO: Enable when FIR reports TYPE_MISMATCH for assignments
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
|
|||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Add non-null asserted (!!) call" "true"
|
||||||
|
class C {
|
||||||
|
val s: String? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test for KTIJ-10052
|
||||||
|
fun C.test() {
|
||||||
|
var z: String = <caret>s
|
||||||
|
}
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Add non-null asserted (!!) call" "true"
|
||||||
|
class C {
|
||||||
|
val s: String? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test for KTIJ-10052
|
||||||
|
fun C.test() {
|
||||||
|
var z: String = s!!
|
||||||
|
}
|
||||||
@@ -774,6 +774,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/assignmentRValue.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/assignmentRValue.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initializer.kt")
|
||||||
|
public void testInitializer() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/initializer.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("memberAccessInExtension.kt")
|
@TestMetadata("memberAccessInExtension.kt")
|
||||||
public void testMemberAccessInExtension() throws Exception {
|
public void testMemberAccessInExtension() throws Exception {
|
||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtension.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtension.kt");
|
||||||
@@ -784,6 +789,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtensionAsAssignmentRValue.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtensionAsAssignmentRValue.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("memberAccessInExtensionAsInitializer.kt")
|
||||||
|
public void testMemberAccessInExtensionAsInitializer() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/memberAccessInExtensionAsInitializer.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullArgument.kt")
|
@TestMetadata("nullArgument.kt")
|
||||||
public void testNullArgument() throws Exception {
|
public void testNullArgument() throws Exception {
|
||||||
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/nullArgument.kt");
|
runTest("idea/testData/quickfix/addExclExclCall/typeMismatch/nullArgument.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user