diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt index c72e467c993..906ca36beee 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt @@ -44,7 +44,8 @@ class RemoveExplicitTypeArgumentsIntention : SelfTargetingOffsetIndependentInten companion object { fun isApplicableTo(element: KtTypeArgumentList, approximateFlexible: Boolean): Boolean { val callExpression = element.parent as? KtCallExpression ?: return false - if (callExpression.typeArguments.isEmpty()) return false + val typeArguments = callExpression.typeArguments + if (typeArguments.isEmpty() || typeArguments.any { it.typeReference?.annotationEntries?.isNotEmpty() == true }) return false val resolutionFacade = callExpression.getResolutionFacade() val bindingContext = resolutionFacade.analyze(callExpression, BodyResolveMode.PARTIAL_WITH_CFA) diff --git a/idea/testData/intentions/removeExplicitTypeArguments/hasAnnotation.kt b/idea/testData/intentions/removeExplicitTypeArguments/hasAnnotation.kt new file mode 100644 index 00000000000..035d153b97f --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/hasAnnotation.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +annotation class Foo(val value: String) + +fun main() { + val l = listOf<@Foo("bar") String>("") +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index db1b2b4dc6f..ec83710c5e7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -14466,6 +14466,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/removeExplicitTypeArguments/getterBody.kt"); } + @TestMetadata("hasAnnotation.kt") + public void testHasAnnotation() throws Exception { + runTest("idea/testData/intentions/removeExplicitTypeArguments/hasAnnotation.kt"); + } + @TestMetadata("inapplicableTypeThatIsAFunItCannotBeInferred.kt") public void testInapplicableTypeThatIsAFunItCannotBeInferred() throws Exception { runTest("idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt");