Skip to content

Commit

Permalink
Fix: add commas between multiple lambda parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Feb 3, 2017
1 parent 3010f31 commit 562c833
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class PrintVisitor : AstVisitor<String>("") {
}

override fun visitLambda(lambda: Tr.Lambda): String {
val params = visit(lambda.paramSet.params)
val params = visit(lambda.paramSet.params, ",")
val paramSet = lambda.paramSet.fmt(if(lambda.paramSet.parenthesized) "($params)" else params)
return lambda.fmt("$paramSet${lambda.arrow.fmt("->")}${visit(lambda.body)}")
}
Expand Down Expand Up @@ -413,7 +413,6 @@ class PrintVisitor : AstVisitor<String>("") {
return if (this == null || code == null)
""
else {
// println("${this.javaClass.simpleName} = [" + formatting.prefix() + "," + code + "," + formatting.suffix() + "]")
formatting.prefix() + code + formatting.suffix()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ abstract class LambdaTest(p: Parser): Parser by p {
}

@Test
fun lambdaWithBlock() {
fun rightSideBlock() {
val a = parse("""
public class A {
Action a = ( ) -> { };
Expand All @@ -93,4 +93,16 @@ abstract class LambdaTest(p: Parser): Parser by p {
assertEquals("( ) -> { }", lambda.printTrimmed())
}

@Test
fun multipleParameters() {
val a = parse("""
import java.util.function.BiConsumer;
public class A {
BiConsumer<String, String> a = (s1, s2) -> { };
}
""")

val lambda = a.classes[0].fields()[0].vars[0].initializer!!
assertEquals("(s1, s2) -> { }", lambda.printTrimmed())
}
}

0 comments on commit 562c833

Please sign in to comment.