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 typeArgs = types.map {
|
||||
assert(args[it] != null, "there is a null in the type arguments to transform")
|
||||
val typeToCompute = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(args[it]!!);
|
||||
val computedTypeRef = psiFactory.createType(typeToCompute)
|
||||
ShortenReferences.process(computedTypeRef)
|
||||
computedTypeRef.getText()
|
||||
}.makeString(", ", "<", ">")
|
||||
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(args[it]!!)
|
||||
}.joinToString(", ", "<", ">")
|
||||
|
||||
val name = element.getCalleeExpression()?.getText()
|
||||
if (name == null) return
|
||||
val callee = element.getCalleeExpression()
|
||||
if (callee == null) return
|
||||
|
||||
val valueAndFunctionArguments = element.getText()?.substring(name.size) ?: throw AssertionError("InsertExplicitTypeArguments intention shouldn't be applicable for empty call expression")
|
||||
val expr = psiFactory.createExpression("$name$typeArgs${valueAndFunctionArguments}")
|
||||
element.replace(expr)
|
||||
element.addAfter(psiFactory.createTypeArguments(typeArgs), callee)
|
||||
ShortenReferences.process(element.getTypeArgumentList()!!)
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@TestMetadata("insertImportForArg.kt")
|
||||
public void testInsertImportForArg() throws Exception {
|
||||
doTest("idea/testData/intentions/insertExplicitTypeArguments/insertImportForArg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("insertManyTypes.kt")
|
||||
public void testInsertManyTypes() throws Exception {
|
||||
doTest("idea/testData/intentions/insertExplicitTypeArguments/insertManyTypes.kt");
|
||||
|
||||
Reference in New Issue
Block a user