"Remove explicit type specification" intention: Add type argument to initializer if need #KT-13343 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-08-08 19:58:57 +09:00
committed by Mikhail Glukhikh
parent 54922362e3
commit 0099b7b3b1
6 changed files with 23 additions and 0 deletions
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.refactoring.addTypeArgumentsIfNeeded
import org.jetbrains.kotlin.idea.refactoring.getQualifiedTypeArgumentList
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
@@ -35,7 +37,10 @@ class RemoveExplicitTypeIntention : SelfTargetingRangeIntention<KtCallableDeclar
}
override fun applyTo(element: KtCallableDeclaration, editor: Editor?) {
val initializer = (element as? KtProperty)?.initializer
val typeArgumentList = initializer?.let { getQualifiedTypeArgumentList(it) }
element.typeReference = null
if (typeArgumentList != null) addTypeArgumentsIfNeeded(initializer, typeArgumentList)
}
companion object {
@@ -0,0 +1,2 @@
// WITH_RUNTIME
val x: <caret>Set<Int> = setOf()
@@ -0,0 +1,2 @@
// WITH_RUNTIME
val x = setOf<Int>()
@@ -0,0 +1,2 @@
class Foo<T, U>
val foo: <caret>Foo<Int, String> = Foo()
@@ -0,0 +1,2 @@
class Foo<T, U>
val foo = Foo<Int, String>()
@@ -13146,6 +13146,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/removeExplicitType/lambdaInitializer5.kt");
}
@TestMetadata("needTypeArgument.kt")
public void testNeedTypeArgument() throws Exception {
runTest("idea/testData/intentions/removeExplicitType/needTypeArgument.kt");
}
@TestMetadata("needTypeArgument2.kt")
public void testNeedTypeArgument2() throws Exception {
runTest("idea/testData/intentions/removeExplicitType/needTypeArgument2.kt");
}
@TestMetadata("notOnParameterOfFunctionType.kt")
public void testNotOnParameterOfFunctionType() throws Exception {
runTest("idea/testData/intentions/removeExplicitType/notOnParameterOfFunctionType.kt");