Don't create empty parentheses when lambda is the only argument

This commit is contained in:
Tal Man
2014-03-18 20:53:48 -04:00
committed by Andrey Breslav
parent 796611702c
commit 1c2082fd19
2 changed files with 8 additions and 3 deletions
@@ -34,7 +34,12 @@ public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingIntention<J
val literal = args.last!!.getArgumentExpression()?.getText() // we know args.last is non null
val callText = element.getText()
if (callText == null || literal == null) return
val endIndex = Math.max(callText.lastIndexOf(","), callText.indexOf("(") + 1) // in case of single parameter
element.replace(JetPsiFactory.createExpression(element.getProject(), "${callText.substring(0,endIndex)})$literal"))
val endIndex = callText.lastIndexOf(",")
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
fun foo() {
bar() { it }
bar { it }
}
fun bar(a: Int, b: Int->Int) {