diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt index 0a5fc474926..7b1d98fce75 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall +import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.TypeUtils public class RemoveExplicitTypeArgumentsInspection : IntentionBasedInspection(RemoveExplicitTypeArgumentsIntention()) { @@ -42,8 +43,9 @@ public class RemoveExplicitTypeArgumentsIntention : JetSelfTargetingOffsetIndepe val callExpression = element.getParent() as? JetCallExpression ?: return false if (callExpression.getTypeArguments().isEmpty()) return false - val context = callExpression.analyze() - val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression] ?: return false + val context = callExpression.analyze(BodyResolveMode.PARTIAL) + val calleeExpression = callExpression.getCalleeExpression() ?: return false + val scope = context[BindingContext.RESOLUTION_SCOPE, calleeExpression/*TODO: discuss it*/] ?: return false val originalCall = callExpression.getResolvedCall(context) ?: return false val untypedCall = CallWithoutTypeArgs(originalCall.getCall()) diff --git a/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml b/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml index 72a83dd3487..13bf5d12a17 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml +++ b/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml @@ -124,4 +124,13 @@ Type arguments are unnecessary Remove explicit type arguments + + + mapGet.kt + 9 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt b/idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt new file mode 100644 index 00000000000..3b2e3305129 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt @@ -0,0 +1,11 @@ +interface I + +interface MyMap { + fun get(`type`: I): T? +} + +class A(val map: MyMap) { + fun foo(`type`: I) { + val value = map.get(`type`) + } +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt.after new file mode 100644 index 00000000000..1d42eb79e7e --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt.after @@ -0,0 +1,11 @@ +interface I + +interface MyMap { + fun get(`type`: I): T? +} + +class A(val map: MyMap) { + fun foo(`type`: I) { + val value = map.get(`type`) + } +} \ 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 afea8e85b34..dae733f214e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -5776,6 +5776,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("mapGet.kt") + public void testMapGet() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitTypeArguments/mapGet.kt"); + doTest(fileName); + } + @TestMetadata("nestedCall-KT-5028.kt") public void testNestedCall_KT_5028() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitTypeArguments/nestedCall-KT-5028.kt"); diff --git a/j2k/testData/fileOrElement/methodCallExpression/genericMethod.java b/j2k/testData/fileOrElement/methodCallExpression/genericMethod.java index 8f02a08c22f..0831a76541e 100644 --- a/j2k/testData/fileOrElement/methodCallExpression/genericMethod.java +++ b/j2k/testData/fileOrElement/methodCallExpression/genericMethod.java @@ -8,6 +8,6 @@ class Map { class U { void test() { Map m = new Map(); - m.put("10", 10); + m.put(null, 10); } } \ No newline at end of file diff --git a/j2k/testData/fileOrElement/methodCallExpression/genericMethod.kt b/j2k/testData/fileOrElement/methodCallExpression/genericMethod.kt index 309f1246b0e..4c3af1783d7 100644 --- a/j2k/testData/fileOrElement/methodCallExpression/genericMethod.kt +++ b/j2k/testData/fileOrElement/methodCallExpression/genericMethod.kt @@ -1,13 +1,13 @@ package demo class Map { - fun put(k: K, v: V) { + fun put(k: K?, v: V) { } } class U { fun test() { val m = Map() - m.put("10", 10) + m.put(null, 10) } } \ No newline at end of file