KT-15030 Remove redundant calls of conversion methods: false positive for 'toList()'
#KT-15030 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
268702e0cc
commit
2815b5e62b
+5
-11
@@ -23,11 +23,13 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.core.replaced
|
import org.jetbrains.kotlin.idea.core.replaced
|
||||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||||
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.KtConstantExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtQualifiedExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||||
import org.jetbrains.kotlin.types.isFlexible
|
import org.jetbrains.kotlin.types.isFlexible
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection<KtQualifiedExpression>(RemoveRedundantCallsOfConversionMethodsIntention::class) {
|
class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection<KtQualifiedExpression>(RemoveRedundantCallsOfConversionMethodsIntention::class) {
|
||||||
override val problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
override val problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||||
@@ -35,15 +37,7 @@ class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspecti
|
|||||||
|
|
||||||
class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeIntention<KtQualifiedExpression>(KtQualifiedExpression::class.java, "Remove redundant calls of the conversion method") {
|
class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeIntention<KtQualifiedExpression>(KtQualifiedExpression::class.java, "Remove redundant calls of the conversion method") {
|
||||||
|
|
||||||
private val targetClassMap = mapOf("toList()" to List::class.qualifiedName,
|
private val targetClassMap = mapOf("toString()" to String::class.qualifiedName,
|
||||||
"toSet()" to Set::class.qualifiedName,
|
|
||||||
"toMap()" to Map::class.qualifiedName,
|
|
||||||
"toMutableList()" to "kotlin.collections.MutableList",
|
|
||||||
"toMutableSet()" to "kotlin.collections.MutableSet",
|
|
||||||
"toMutableMap()" to "kotlin.collections.MutableMap",
|
|
||||||
"toSortedSet()" to SortedSet::class.qualifiedName,
|
|
||||||
"toSortedMap()" to SortedMap::class.qualifiedName,
|
|
||||||
"toString()" to String::class.qualifiedName,
|
|
||||||
"toDouble()" to Double::class.qualifiedName,
|
"toDouble()" to Double::class.qualifiedName,
|
||||||
"toFloat()" to Float::class.qualifiedName,
|
"toFloat()" to Float::class.qualifiedName,
|
||||||
"toLong()" to Long::class.qualifiedName,
|
"toLong()" to Long::class.qualifiedName,
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = listOf(1, 2, 3).toList()<caret>
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = listOf(1, 2, 3)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = listOf(1, 2, 3).map(Int::toString).toList()<caret>
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = listOf(1, 2, 3).map(Int::toString)
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = mutableListOf(1, 2, 3).toMutableList()<caret>
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = mutableListOf(1, 2, 3)
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = mutableSetOf(1, 2, 3).toMutableSet()<caret>
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = mutableSetOf(1, 2, 3)
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
// IS_APPLICABLE: false
|
|
||||||
import java.util.Collections
|
|
||||||
|
|
||||||
val foo = Collections.unmodifiableList(listOf(1)).toMutableList()<caret>
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
|
|
||||||
import java.util.SortedMap
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
val foo: SortedMap<String, String>? = null
|
|
||||||
foo?.toSortedMap()<caret>
|
|
||||||
}
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
|
|
||||||
import java.util.SortedMap
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
val foo: SortedMap<String, String>? = null
|
|
||||||
foo
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = setOf(1, 2, 3).toSet()<caret>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = setOf(1, 2, 3)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = sortedMapOf(1 to 1).toSortedMap()<caret>
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
val foo = sortedMapOf(1 to 1)
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
// sortedSetOf returns TreeSet not SortedSet
|
|
||||||
val foo = sortedSetOf(1, 2, 3).toSortedSet().toSortedSet()<caret>
|
|
||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
// sortedSetOf returns TreeSet not SortedSet
|
|
||||||
val foo = sortedSetOf(1, 2, 3).toSortedSet()
|
|
||||||
@@ -11643,78 +11643,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("list.kt")
|
|
||||||
public void testList() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("list2.kt")
|
|
||||||
public void testList2() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("mutableList.kt")
|
|
||||||
public void testMutableList() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("mutableSet.kt")
|
|
||||||
public void testMutableSet() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("platformTypes.kt")
|
|
||||||
public void testPlatformTypes() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("safeSortedMap.kt")
|
|
||||||
public void testSafeSortedMap() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("safeString.kt")
|
@TestMetadata("safeString.kt")
|
||||||
public void testSafeString() throws Exception {
|
public void testSafeString() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("set.kt")
|
|
||||||
public void testSet() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("short.kt")
|
@TestMetadata("short.kt")
|
||||||
public void testShort() throws Exception {
|
public void testShort() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("sortedMap.kt")
|
|
||||||
public void testSortedMap() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("sortedSet.kt")
|
|
||||||
public void testSortedSet() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("string.kt")
|
@TestMetadata("string.kt")
|
||||||
public void testString() throws Exception {
|
public void testString() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user