New J2K: add number types conversions to post-processing
This commit is contained in:
+16
-7
@@ -161,17 +161,26 @@ private val processings: List<GeneralPostProcessing> = listOf(
|
|||||||
Errors.SMARTCAST_IMPOSSIBLE
|
Errors.SMARTCAST_IMPOSSIBLE
|
||||||
),
|
),
|
||||||
diagnosticBasedProcessing(Errors.TYPE_MISMATCH) { element: PsiElement, diagnostic ->
|
diagnosticBasedProcessing(Errors.TYPE_MISMATCH) { element: PsiElement, diagnostic ->
|
||||||
@Suppress("UNCHECKED_CAST") val diagnosticWithParameters =
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val diagnosticWithParameters =
|
||||||
diagnostic as? DiagnosticWithParameters2<KtExpression, KotlinType, KotlinType>
|
diagnostic as? DiagnosticWithParameters2<KtExpression, KotlinType, KotlinType>
|
||||||
?: return@diagnosticBasedProcessing
|
?: return@diagnosticBasedProcessing
|
||||||
val expectedType = diagnosticWithParameters.a
|
val expectedType = diagnosticWithParameters.a
|
||||||
val realType = diagnosticWithParameters.b
|
val realType = diagnosticWithParameters.b
|
||||||
if (realType.makeNotNullable().isSubtypeOf(expectedType.makeNotNullable())
|
when {
|
||||||
&& realType.isNullable()
|
realType.makeNotNullable().isSubtypeOf(expectedType.makeNotNullable())
|
||||||
&& !expectedType.isNullable()
|
&& realType.isNullable()
|
||||||
) {
|
&& !expectedType.isNullable()
|
||||||
val factory = KtPsiFactory(element)
|
-> {
|
||||||
element.replace(factory.createExpressionByPattern("($0)!!", element.text))
|
val factory = KtPsiFactory(element)
|
||||||
|
element.replace(factory.createExpressionByPattern("($0)!!", element.text))
|
||||||
|
}
|
||||||
|
element is KtExpression
|
||||||
|
&& realType.isSignedOrUnsignedNumberType()
|
||||||
|
&& expectedType.isSignedOrUnsignedNumberType() -> {
|
||||||
|
val fix = NumberConversionFix(element, expectedType, disableIfAvailable = null)
|
||||||
|
fix.invoke(element.project, null, element.containingFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user