From 2815b5e62b4248a34c07b048b67a7ed4d4c561c4 Mon Sep 17 00:00:00 2001 From: shiraji Date: Mon, 5 Dec 2016 22:27:10 +0900 Subject: [PATCH] KT-15030 Remove redundant calls of conversion methods: false positive for 'toList()' #KT-15030 Fixed --- ...undantCallsOfConversionMethodsIntention.kt | 16 ++---- .../list.kt | 2 - .../list.kt.after | 2 - .../list2.kt | 2 - .../list2.kt.after | 2 - .../mutableList.kt | 2 - .../mutableList.kt.after | 2 - .../mutableSet.kt | 2 - .../mutableSet.kt.after | 2 - .../platformTypes.kt | 5 -- .../safeSortedMap.kt | 8 --- .../safeSortedMap.kt.after | 8 --- .../set.kt | 2 - .../set.kt.after | 2 - .../sortedMap.kt | 2 - .../sortedMap.kt.after | 2 - .../sortedSet.kt | 3 -- .../sortedSet.kt.after | 3 -- .../intentions/IntentionTestGenerated.java | 54 ------------------- 19 files changed, 5 insertions(+), 116 deletions(-) delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt.after delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt delete mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt index 89108df2caa..6d7aae08a57 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt @@ -23,11 +23,13 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection 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.getType import org.jetbrains.kotlin.types.isFlexible -import java.util.* class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection(RemoveRedundantCallsOfConversionMethodsIntention::class) { override val problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL @@ -35,15 +37,7 @@ class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspecti class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeIntention(KtQualifiedExpression::class.java, "Remove redundant calls of the conversion method") { - private val targetClassMap = mapOf("toList()" to List::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, + private val targetClassMap = mapOf("toString()" to String::class.qualifiedName, "toDouble()" to Double::class.qualifiedName, "toFloat()" to Float::class.qualifiedName, "toLong()" to Long::class.qualifiedName, diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt deleted file mode 100644 index 4a1fe2e0ba2..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = listOf(1, 2, 3).toList() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt.after deleted file mode 100644 index ec61a540754..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt.after +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = listOf(1, 2, 3) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt deleted file mode 100644 index 44c79e3c3ab..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = listOf(1, 2, 3).map(Int::toString).toList() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt.after deleted file mode 100644 index ab998b0f90d..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt.after +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = listOf(1, 2, 3).map(Int::toString) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt deleted file mode 100644 index 9b962d974ec..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = mutableListOf(1, 2, 3).toMutableList() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt.after deleted file mode 100644 index d5be492dea1..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt.after +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = mutableListOf(1, 2, 3) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt deleted file mode 100644 index 78af7127f66..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = mutableSetOf(1, 2, 3).toMutableSet() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt.after deleted file mode 100644 index 680130b5bce..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt.after +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = mutableSetOf(1, 2, 3) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt deleted file mode 100644 index 260725d4960..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt +++ /dev/null @@ -1,5 +0,0 @@ -// WITH_RUNTIME -// IS_APPLICABLE: false -import java.util.Collections - -val foo = Collections.unmodifiableList(listOf(1)).toMutableList() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt deleted file mode 100644 index 16b5d41cced..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt +++ /dev/null @@ -1,8 +0,0 @@ -// WITH_RUNTIME - -import java.util.SortedMap - -fun test() { - val foo: SortedMap? = null - foo?.toSortedMap() -} \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt.after deleted file mode 100644 index d3b40421baa..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt.after +++ /dev/null @@ -1,8 +0,0 @@ -// WITH_RUNTIME - -import java.util.SortedMap - -fun test() { - val foo: SortedMap? = null - foo -} \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt deleted file mode 100644 index a94695d2b67..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = setOf(1, 2, 3).toSet() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt.after deleted file mode 100644 index af778622199..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt.after +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = setOf(1, 2, 3) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt deleted file mode 100644 index 1630389b34f..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = sortedMapOf(1 to 1).toSortedMap() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt.after deleted file mode 100644 index 0ea5ffbed05..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt.after +++ /dev/null @@ -1,2 +0,0 @@ -// WITH_RUNTIME -val foo = sortedMapOf(1 to 1) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt deleted file mode 100644 index 02b556c9a4d..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt +++ /dev/null @@ -1,3 +0,0 @@ -// WITH_RUNTIME -// sortedSetOf returns TreeSet not SortedSet -val foo = sortedSetOf(1, 2, 3).toSortedSet().toSortedSet() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt.after deleted file mode 100644 index a3d1b9a7d0e..00000000000 --- a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -// WITH_RUNTIME -// sortedSetOf returns TreeSet not SortedSet -val foo = sortedSetOf(1, 2, 3).toSortedSet() \ 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 40f7ba96f56..9d96f6db734 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -11643,78 +11643,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest { 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") public void testLong() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt"); 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") public void testSafeString() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt"); 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") public void testShort() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt"); 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") public void testString() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt");