KT-5482 Redundant type arguments are not detected in some cases
#KT-5482 Fixed
This commit is contained in:
+4
-2
@@ -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<JetTypeArgumentList>(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())
|
||||
|
||||
|
||||
+9
@@ -124,4 +124,13 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Type arguments are unnecessary</problem_class>
|
||||
<description>Remove explicit type arguments</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>mapGet.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/mapGet.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Type arguments are unnecessary</problem_class>
|
||||
<description>Remove explicit type arguments</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,11 @@
|
||||
interface I<T>
|
||||
|
||||
interface MyMap {
|
||||
fun <T : Any> get(`type`: I<T>): T?
|
||||
}
|
||||
|
||||
class A(val map: MyMap) {
|
||||
fun <T> foo(`type`: I<T>) {
|
||||
val value = map.get<caret><T>(`type`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
interface I<T>
|
||||
|
||||
interface MyMap {
|
||||
fun <T : Any> get(`type`: I<T>): T?
|
||||
}
|
||||
|
||||
class A(val map: MyMap) {
|
||||
fun <T> foo(`type`: I<T>) {
|
||||
val value = map.get<caret>(`type`)
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -8,6 +8,6 @@ class Map {
|
||||
class U {
|
||||
void test() {
|
||||
Map m = new Map();
|
||||
m.<String, int>put("10", 10);
|
||||
m.<String, int>put(null, 10);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package demo
|
||||
|
||||
class Map {
|
||||
fun <K, V> put(k: K, v: V) {
|
||||
fun <K, V> put(k: K?, v: V) {
|
||||
}
|
||||
}
|
||||
|
||||
class U {
|
||||
fun test() {
|
||||
val m = Map()
|
||||
m.put<String, Int>("10", 10)
|
||||
m.put<String, Int>(null, 10)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user