Don't create empty parentheses when lambda is the only argument
This commit is contained in:
+7
-2
@@ -34,7 +34,12 @@ public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingIntention<J
|
|||||||
val literal = args.last!!.getArgumentExpression()?.getText() // we know args.last is non null
|
val literal = args.last!!.getArgumentExpression()?.getText() // we know args.last is non null
|
||||||
val callText = element.getText()
|
val callText = element.getText()
|
||||||
if (callText == null || literal == null) return
|
if (callText == null || literal == null) return
|
||||||
val endIndex = Math.max(callText.lastIndexOf(","), callText.indexOf("(") + 1) // in case of single parameter
|
val endIndex = callText.lastIndexOf(",")
|
||||||
element.replace(JetPsiFactory.createExpression(element.getProject(), "${callText.substring(0,endIndex)})$literal"))
|
val newCall = if (endIndex > 0) {
|
||||||
|
"${callText.substring(0, endIndex)}) $literal"
|
||||||
|
} else {
|
||||||
|
"${callText.substring(0, callText.indexOf("("))} $literal"
|
||||||
|
}
|
||||||
|
element.replace(JetPsiFactory.createExpression(element.getProject(), newCall))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// IS_APPLICABLE: true
|
// IS_APPLICABLE: true
|
||||||
fun foo() {
|
fun foo() {
|
||||||
bar() { it }
|
bar { it }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bar(a: Int, b: Int->Int) {
|
fun bar(a: Int, b: Int->Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user