Remove redundant spread operator: don't remove inner argument spread operator #KT-27699 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
52c499166e
commit
75755afc00
+7
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(vararg xs: String) {
|
||||
}
|
||||
|
||||
fun bar(ys: Array<String>) {
|
||||
foo(<caret>*arrayOf(*ys, "zzz"))
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(vararg xs: String) {
|
||||
}
|
||||
|
||||
fun bar(ys: Array<String>) {
|
||||
foo(*ys, "zzz")
|
||||
}
|
||||
+5
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user