Fix InsertExplicitTypeArguments intention to insert imports for shortened types
#KT-5489 Fixed
This commit is contained in:
@@ -58,17 +58,13 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
|
|||||||
val psiFactory = JetPsiFactory(element)
|
val psiFactory = JetPsiFactory(element)
|
||||||
val typeArgs = types.map {
|
val typeArgs = types.map {
|
||||||
assert(args[it] != null, "there is a null in the type arguments to transform")
|
assert(args[it] != null, "there is a null in the type arguments to transform")
|
||||||
val typeToCompute = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(args[it]!!);
|
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(args[it]!!)
|
||||||
val computedTypeRef = psiFactory.createType(typeToCompute)
|
}.joinToString(", ", "<", ">")
|
||||||
ShortenReferences.process(computedTypeRef)
|
|
||||||
computedTypeRef.getText()
|
|
||||||
}.makeString(", ", "<", ">")
|
|
||||||
|
|
||||||
val name = element.getCalleeExpression()?.getText()
|
val callee = element.getCalleeExpression()
|
||||||
if (name == null) return
|
if (callee == null) return
|
||||||
|
|
||||||
val valueAndFunctionArguments = element.getText()?.substring(name.size) ?: throw AssertionError("InsertExplicitTypeArguments intention shouldn't be applicable for empty call expression")
|
element.addAfter(psiFactory.createTypeArguments(typeArgs), callee)
|
||||||
val expr = psiFactory.createExpression("$name$typeArgs${valueAndFunctionArguments}")
|
ShortenReferences.process(element.getTypeArgumentList()!!)
|
||||||
element.replace(expr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(c: kotlin.support.AbstractIterator<kotlin.concurrent.FunctionalList<Int>>) {
|
||||||
|
ba<caret>r(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> bar(t: T): T = t
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import kotlin.concurrent.FunctionalList
|
||||||
|
import kotlin.support.AbstractIterator
|
||||||
|
|
||||||
|
fun foo(c: kotlin.support.AbstractIterator<kotlin.concurrent.FunctionalList<Int>>) {
|
||||||
|
bar<AbstractIterator<FunctionalList<Int>>>(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> bar(t: T): T = t
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
@@ -3304,6 +3304,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest("idea/testData/intentions/insertExplicitTypeArguments/inapplicableTypeNotInferred.kt");
|
doTest("idea/testData/intentions/insertExplicitTypeArguments/inapplicableTypeNotInferred.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("insertImportForArg.kt")
|
||||||
|
public void testInsertImportForArg() throws Exception {
|
||||||
|
doTest("idea/testData/intentions/insertExplicitTypeArguments/insertImportForArg.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("insertManyTypes.kt")
|
@TestMetadata("insertManyTypes.kt")
|
||||||
public void testInsertManyTypes() throws Exception {
|
public void testInsertManyTypes() throws Exception {
|
||||||
doTest("idea/testData/intentions/insertExplicitTypeArguments/insertManyTypes.kt");
|
doTest("idea/testData/intentions/insertExplicitTypeArguments/insertManyTypes.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user