From a1f1716044a06e6d6aa323d1381453a2eacc5f21 Mon Sep 17 00:00:00 2001 From: shiraji Date: Wed, 5 Oct 2016 13:48:12 +0900 Subject: [PATCH] Add inspection/intention for redundant calls of conversion methods #KT-10871 Fixed Also #KT-12625 Fixed --- ...moveRedundantCallsOfConversionMethods.html | 5 + .../after.kt.template | 1 + .../before.kt.template | 1 + .../description.html | 5 + idea/src/META-INF/plugin.xml | 13 ++ ...undantCallsOfConversionMethodsIntention.kt | 77 +++++++++++ .../.intention | 1 + .../byte.kt | 2 + .../byte.kt.after | 2 + .../char.kt | 2 + .../char.kt.after | 2 + .../double.kt | 2 + .../double.kt.after | 2 + .../float.kt | 2 + .../float.kt.after | 2 + .../int.kt | 2 + .../int.kt.after | 2 + .../list.kt | 2 + .../list.kt.after | 2 + .../list2.kt | 2 + .../list2.kt.after | 2 + .../long.kt | 2 + .../long.kt.after | 2 + .../mutableList.kt | 2 + .../mutableList.kt.after | 2 + .../mutableSet.kt | 2 + .../mutableSet.kt.after | 2 + .../safeSortedMap.kt | 8 ++ .../safeSortedMap.kt.after | 8 ++ .../safeString.kt | 6 + .../safeString.kt.after | 6 + .../set.kt | 2 + .../set.kt.after | 2 + .../short.kt | 2 + .../short.kt.after | 2 + .../sortedMap.kt | 2 + .../sortedMap.kt.after | 2 + .../sortedSet.kt | 3 + .../sortedSet.kt.after | 3 + .../string.kt | 2 + .../string.kt.after | 2 + .../toOtherType.kt | 3 + .../variable.kt | 3 + .../variable.kt.after | 3 + .../intentions/IntentionTestGenerated.java | 123 ++++++++++++++++++ 45 files changed, 325 insertions(+) create mode 100644 idea/resources/inspectionDescriptions/RemoveRedundantCallsOfConversionMethods.html create mode 100644 idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/description.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/.intention create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt.after create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/toOtherType.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt.after diff --git a/idea/resources/inspectionDescriptions/RemoveRedundantCallsOfConversionMethods.html b/idea/resources/inspectionDescriptions/RemoveRedundantCallsOfConversionMethods.html new file mode 100644 index 00000000000..20b9ee298e3 --- /dev/null +++ b/idea/resources/inspectionDescriptions/RemoveRedundantCallsOfConversionMethods.html @@ -0,0 +1,5 @@ + + +This inspection reports redundant calls of the conversion method + + diff --git a/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/after.kt.template b/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/after.kt.template new file mode 100644 index 00000000000..ed7ef7aff72 --- /dev/null +++ b/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/after.kt.template @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/before.kt.template b/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/before.kt.template new file mode 100644 index 00000000000..4986d79c0c5 --- /dev/null +++ b/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/before.kt.template @@ -0,0 +1 @@ +1.toInt() \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/description.html b/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/description.html new file mode 100644 index 00000000000..70f7ab5c3e6 --- /dev/null +++ b/idea/resources/intentionDescriptions/RemoveRedundantCallsOfConversionMethodsIntention/description.html @@ -0,0 +1,5 @@ + + +This intention removes redundant calls of conversion methods. + + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index dae14becd52..1bca654f72d 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -1408,6 +1408,11 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.RemoveRedundantCallsOfConversionMethodsIntention + Kotlin + + + + diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt new file mode 100644 index 00000000000..70637be91bb --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt @@ -0,0 +1,77 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions + +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.util.TextRange +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.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.calls.callUtil.getType +import java.util.* + +class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection(RemoveRedundantCallsOfConversionMethodsIntention::class) { + override val problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL +} + +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, + "toDouble()" to Double::class.qualifiedName, + "toFloat()" to Float::class.qualifiedName, + "toLong()" to Long::class.qualifiedName, + "toInt()" to Int::class.qualifiedName, + "toChar()" to Char::class.qualifiedName, + "toShort()" to Short::class.qualifiedName, + "toByte()" to Byte::class.qualifiedName) + + + override fun applyTo(element: KtQualifiedExpression, editor: Editor?) { + element.replaced(element.receiverExpression) + } + + override fun applicabilityRange(element: KtQualifiedExpression): TextRange? { + val selectorExpression = element.selectorExpression ?: return null + val selectorExpressionText = selectorExpression.text + val qualifiedName = targetClassMap[selectorExpressionText] ?: return null + if(element.receiverExpression.isApplicableReceiverExpression(qualifiedName)) { + return selectorExpression.textRange + } else { + return null + } + } + + private fun KtExpression.isApplicableReceiverExpression(qualifiedName: String): Boolean { + return when (this) { + is KtStringTemplateExpression -> String::class.qualifiedName + is KtConstantExpression -> getType(analyze())?.getJetTypeFqName(false) + else -> getResolvedCall(analyze())?.candidateDescriptor?.returnType?.getJetTypeFqName(false) + } == qualifiedName + } +} diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/.intention b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/.intention new file mode 100644 index 00000000000..9f7cf2169a0 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/.intention @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.intentions.RemoveRedundantCallsOfConversionMethodsIntention \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt new file mode 100644 index 00000000000..b59e03d2e95 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = Byte.MAX_VALUE.toByte() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt.after new file mode 100644 index 00000000000..7cc039fc888 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = Byte.MAX_VALUE \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt new file mode 100644 index 00000000000..afcfad49d59 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 'a'.toChar() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt.after new file mode 100644 index 00000000000..cfe7594df44 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 'a' \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt new file mode 100644 index 00000000000..3ec6609f794 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 1.1.toDouble() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt.after new file mode 100644 index 00000000000..736838a6af7 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 1.1 \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt new file mode 100644 index 00000000000..4e098751809 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 1.1f.toFloat() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt.after new file mode 100644 index 00000000000..94b0cae0cfd --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 1.1f \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt new file mode 100644 index 00000000000..0e4e87891aa --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 1.toInt() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt.after new file mode 100644 index 00000000000..75a6b387fb0 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt new file mode 100644 index 00000000000..4a1fe2e0ba2 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..ec61a540754 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list.kt.after @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..44c79e3c3ab --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..ab998b0f90d --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/list2.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = listOf(1, 2, 3).map(Int::toString) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt new file mode 100644 index 00000000000..7d6e0ff4705 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = Long.MAX_VALUE.toLong() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt.after new file mode 100644 index 00000000000..2d436fe71c1 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/long.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = Long.MAX_VALUE \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt new file mode 100644 index 00000000000..9b962d974ec --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..d5be492dea1 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableList.kt.after @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..78af7127f66 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..680130b5bce --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/mutableSet.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = mutableSetOf(1, 2, 3) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt new file mode 100644 index 00000000000..16b5d41cced --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt @@ -0,0 +1,8 @@ +// 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 new file mode 100644 index 00000000000..d3b40421baa --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt.after @@ -0,0 +1,8 @@ +// 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/safeString.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt new file mode 100644 index 00000000000..fb0f304c66d --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME + +fun test() { + val foo: String? = null + foo?.toString() +} \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt.after new file mode 100644 index 00000000000..b21a073227a --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt.after @@ -0,0 +1,6 @@ +// WITH_RUNTIME + +fun test() { + val foo: String? = null + foo +} diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt new file mode 100644 index 00000000000..a94695d2b67 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..af778622199 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/set.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = setOf(1, 2, 3) \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt new file mode 100644 index 00000000000..a5cdaa58cf0 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = Short.MAX_VALUE.toShort() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt.after new file mode 100644 index 00000000000..a260412dee6 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/short.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = Short.MAX_VALUE \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt new file mode 100644 index 00000000000..1630389b34f --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..0ea5ffbed05 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedMap.kt.after @@ -0,0 +1,2 @@ +// 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 new file mode 100644 index 00000000000..02b556c9a4d --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt @@ -0,0 +1,3 @@ +// 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 new file mode 100644 index 00000000000..a3d1b9a7d0e --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/sortedSet.kt.after @@ -0,0 +1,3 @@ +// WITH_RUNTIME +// sortedSetOf returns TreeSet not SortedSet +val foo = sortedSetOf(1, 2, 3).toSortedSet() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt new file mode 100644 index 00000000000..d6c84e18a41 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = "".toString() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt.after new file mode 100644 index 00000000000..d2e2207b194 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/string.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val foo = "" \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/toOtherType.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/toOtherType.kt new file mode 100644 index 00000000000..c3e45a9dfa0 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/toOtherType.kt @@ -0,0 +1,3 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +val foo = 1.toLong() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt new file mode 100644 index 00000000000..6156f3cf011 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt @@ -0,0 +1,3 @@ +// WITH_RUNTIME +val foo = "" +val bar = foo.toString() \ No newline at end of file diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt.after b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt.after new file mode 100644 index 00000000000..5d517232979 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt.after @@ -0,0 +1,3 @@ +// WITH_RUNTIME +val foo = "" +val bar = foo \ 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 01d4458f55f..310a45a0325 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -10875,6 +10875,129 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveRedundantCallsOfConversionMethods extends AbstractIntentionTest { + public void testAllFilesPresentInRemoveRedundantCallsOfConversionMethods() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeRedundantCallsOfConversionMethods"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true); + } + + @TestMetadata("byte.kt") + public void testByte() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/byte.kt"); + doTest(fileName); + } + + @TestMetadata("char.kt") + public void testChar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/char.kt"); + doTest(fileName); + } + + @TestMetadata("double.kt") + public void testDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/double.kt"); + doTest(fileName); + } + + @TestMetadata("float.kt") + public void testFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/float.kt"); + doTest(fileName); + } + + @TestMetadata("int.kt") + public void testInt() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/int.kt"); + 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("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"); + doTest(fileName); + } + + @TestMetadata("toOtherType.kt") + public void testToOtherType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/toOtherType.kt"); + doTest(fileName); + } + + @TestMetadata("variable.kt") + public void testVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/variable.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/intentions/removeSingleExpressionStringTemplate") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)