From 8e5b833cca9a021a31391eeddaba02921f212817 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 22 Aug 2016 18:35:15 +0300 Subject: [PATCH] Has platform type inspection: do not suggest !! for not-null types #KT-12820 Fixed (cherry picked from commit 8830ff7) --- .../kotlin/idea/inspections/HasPlatformTypeInspection.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt index 4da9f91d0b6..347d3cb0c4b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt @@ -22,6 +22,7 @@ import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention +import org.jetbrains.kotlin.idea.intentions.isFlexibleRecursive import org.jetbrains.kotlin.idea.quickfix.AddExclExclCallFix import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtCallableDeclaration @@ -29,7 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments import org.jetbrains.kotlin.psi.psiUtil.getStartOffsetIn import org.jetbrains.kotlin.psi.psiUtil.startOffset -import org.jetbrains.kotlin.types.isNullabilityFlexible +import org.jetbrains.kotlin.types.TypeUtils import javax.swing.JComponent class HasPlatformTypeInspection( @@ -51,9 +52,10 @@ class HasPlatformTypeInspection( override fun additionalFixes(element: KtCallableDeclaration): List? { val type = SpecifyTypeExplicitlyIntention.dangerousFlexibleTypeOrNull(element, publicAPIOnly, reportPlatformArguments) ?: return null - if (type.isNullabilityFlexible()) { + if (TypeUtils.isNullableType(type)) { val expression = element.node.findChildByType(KtTokens.EQ)?.psi?.getNextSiblingIgnoringWhitespaceAndComments() - if (expression != null) { + if (expression != null && + (!reportPlatformArguments || !TypeUtils.makeNotNullable(type).isFlexibleRecursive())) { return listOf(IntentionWrapper(AddExclExclCallFix(expression), element.containingFile)) } }