diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt index fb152e0b698..64c74a1f0b5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/HasPlatformTypeInspection.kt @@ -34,10 +34,11 @@ import javax.swing.JComponent class HasPlatformTypeInspection( val intention: SpecifyTypeExplicitlyIntention = SpecifyTypeExplicitlyIntention(), - @JvmField var publicAPIOnly: Boolean = true + @JvmField var publicAPIOnly: Boolean = true, + @JvmField var reportPlatformArguments: Boolean = false ) : IntentionBasedInspection( intention, - { intention.dangerousFlexibleTypeOrNull(it, publicAPIOnly) != null } + { intention.dangerousFlexibleTypeOrNull(it, publicAPIOnly, reportPlatformArguments) != null } ) { override val problemHighlightType = ProblemHighlightType.WEAK_WARNING @@ -45,7 +46,7 @@ class HasPlatformTypeInspection( override val problemText = "Declaration has platform type. Make the type explicit to prevent subtle bugs." override fun additionalFixes(element: KtCallableDeclaration): List? { - val type = intention.dangerousFlexibleTypeOrNull(element, publicAPIOnly) ?: return null + val type = intention.dangerousFlexibleTypeOrNull(element, publicAPIOnly, reportPlatformArguments) ?: return null if (type.isNullabilityFlexible()) { val expression = element.node.findChildByType(KtTokens.EQ)?.psi?.getNextSiblingIgnoringWhitespaceAndComments() @@ -65,6 +66,7 @@ class HasPlatformTypeInspection( override fun createOptionsPanel(): JComponent? { val panel = MultipleCheckboxOptionsPanel(this) panel.addCheckbox("Apply only to public or protected members", "publicAPIOnly") + panel.addCheckbox("Report for types with platform arguments", "reportPlatformArguments") return panel } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt index 5bff0b7083e..445c56c9474 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt @@ -51,7 +51,9 @@ class SpecifyTypeExplicitlyIntention : SelfTargetingRangeIntention(KtCallableDeclaration::class.java, "Specify type explicitly"), LowPriorityAction { - fun dangerousFlexibleTypeOrNull(declaration: KtCallableDeclaration, publicAPIOnly: Boolean): KotlinType? { + fun dangerousFlexibleTypeOrNull( + declaration: KtCallableDeclaration, publicAPIOnly: Boolean, reportPlatformArguments: Boolean + ): KotlinType? { when (declaration) { is KtFunction -> if (declaration.isLocal || declaration.hasDeclaredReturnType()) return null is KtProperty -> if (declaration.isLocal || declaration.typeReference != null) return null @@ -63,7 +65,12 @@ class SpecifyTypeExplicitlyIntention : val callable = declaration.resolveToDescriptorIfAny() as? CallableDescriptor ?: return null if (publicAPIOnly && !callable.visibility.isPublicAPI) return null val type = callable.returnType ?: return null - if (!type.isFlexibleRecursive()) return null + if (reportPlatformArguments) { + if (!type.isFlexibleRecursive()) return null + } + else { + if (!type.isFlexible()) return null + } return type } diff --git a/idea/testData/inspections/hasPlatformType/inspectionData/expected.xml b/idea/testData/inspections/hasPlatformType/inspectionData/expected.xml index e0ba834692c..c3788ec0ee8 100644 --- a/idea/testData/inspections/hasPlatformType/inspectionData/expected.xml +++ b/idea/testData/inspections/hasPlatformType/inspectionData/expected.xml @@ -23,12 +23,4 @@ Function, property or variable has platform type. Declaration has platform type. Make the type explicit to prevent subtle bugs. - - property2.kt - 3 - light_idea_test_case - - Function, property or variable has platform type. - Declaration has platform type. Make the type explicit to prevent subtle bugs. - \ No newline at end of file diff --git a/idea/testData/inspections/hasPlatformType/property2.kt b/idea/testData/inspections/hasPlatformType/property2.kt index 72602113a6f..f37ee86441b 100644 --- a/idea/testData/inspections/hasPlatformType/property2.kt +++ b/idea/testData/inspections/hasPlatformType/property2.kt @@ -1,3 +1,3 @@ // WITH_RUNTIME - +// By default OK: Array val list = arrayOf(java.lang.String.valueOf(1)) \ No newline at end of file