Remove redundant spread operator: don't remove inner argument spread operator #KT-27699 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-11-16 12:37:28 +09:00
committed by Mikhail Glukhikh
parent 52c499166e
commit 75755afc00
4 changed files with 24 additions and 3 deletions
@@ -62,13 +62,17 @@ class RemoveRedundantSpreadOperatorQuickfix : LocalQuickFix {
// Arguments under arrayOf or []
val innerArgumentExpressions =
when (spreadArgumentExpression) {
is KtCallExpression -> spreadArgumentExpression.valueArgumentList?.arguments?.map { it.getArgumentExpression() }
is KtCollectionLiteralExpression -> spreadArgumentExpression.getInnerExpressions()
is KtCallExpression -> spreadArgumentExpression.valueArgumentList?.arguments?.map {
it.getArgumentExpression() to it.isSpread
}
is KtCollectionLiteralExpression -> spreadArgumentExpression.getInnerExpressions().map { it to false }
else -> null
} ?: return
val factory = KtPsiFactory(project)
innerArgumentExpressions.reversed().forEach { outerArgumentList.addArgumentAfter(factory.createArgument(it), spreadValueArgument) }
innerArgumentExpressions.reversed().forEach { (expression, isSpread) ->
outerArgumentList.addArgumentAfter(factory.createArgument(expression, isSpread = isSpread), spreadValueArgument)
}
outerArgumentList.removeArgument(spreadValueArgument)
}
}
@@ -0,0 +1,6 @@
fun foo(vararg xs: String) {
}
fun bar(ys: Array<String>) {
foo(<caret>*arrayOf(*ys, "zzz"))
}
@@ -0,0 +1,6 @@
fun foo(vararg xs: String) {
}
fun bar(ys: Array<String>) {
foo(*ys, "zzz")
}
@@ -5141,6 +5141,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
public void testShortArrayOf() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantSpreadOperator/shortArrayOf.kt");
}
@TestMetadata("spredOperatorArgument.kt")
public void testSpredOperatorArgument() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt");
}
}
@TestMetadata("idea/testData/inspectionsLocal/removeSetterParameterType")