KT-15030 Remove redundant calls of conversion methods: false positive for 'toList()'

#KT-15030 Fixed
This commit is contained in:
shiraji
2016-12-05 22:27:10 +09:00
committed by Mikhail Glukhikh
parent 268702e0cc
commit 2815b5e62b
19 changed files with 5 additions and 116 deletions

View File

@@ -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<KtQualifiedExpression>(RemoveRedundantCallsOfConversionMethodsIntention::class) {
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") {
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,

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = listOf(1, 2, 3).toList()<caret>

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = listOf(1, 2, 3)

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = listOf(1, 2, 3).map(Int::toString).toList()<caret>

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = listOf(1, 2, 3).map(Int::toString)

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = mutableListOf(1, 2, 3).toMutableList()<caret>

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = mutableListOf(1, 2, 3)

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = mutableSetOf(1, 2, 3).toMutableSet()<caret>

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = mutableSetOf(1, 2, 3)

View File

@@ -1,5 +0,0 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
import java.util.Collections
val foo = Collections.unmodifiableList(listOf(1)).toMutableList()<caret>

View File

@@ -1,8 +0,0 @@
// WITH_RUNTIME
import java.util.SortedMap
fun test() {
val foo: SortedMap<String, String>? = null
foo?.toSortedMap()<caret>
}

View File

@@ -1,8 +0,0 @@
// WITH_RUNTIME
import java.util.SortedMap
fun test() {
val foo: SortedMap<String, String>? = null
foo
}

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = setOf(1, 2, 3).toSet()<caret>

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = setOf(1, 2, 3)

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = sortedMapOf(1 to 1).toSortedMap()<caret>

View File

@@ -1,2 +0,0 @@
// WITH_RUNTIME
val foo = sortedMapOf(1 to 1)

View File

@@ -1,3 +0,0 @@
// WITH_RUNTIME
// sortedSetOf returns TreeSet not SortedSet
val foo = sortedSetOf(1, 2, 3).toSortedSet().toSortedSet()<caret>

View File

@@ -1,3 +0,0 @@
// WITH_RUNTIME
// sortedSetOf returns TreeSet not SortedSet
val foo = sortedSetOf(1, 2, 3).toSortedSet()

View File

@@ -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");