fix: add parentheses around multiple lambda arguments (PR #1840)

* fix: add parentheses around multiple lambda arguments
* add simple test case
---------

Co-authored-by: Skylot <skylot@gmail.com>
This commit is contained in:
George Hopkins
2023-04-24 20:59:59 +02:00
committed by GitHub
parent 06ec12ba17
commit bac2386a1a
2 changed files with 43 additions and 0 deletions
@@ -1003,6 +1003,9 @@ public class InsnGen {
} else {
int callArgsCount = callArgs.size();
int startArg = callArgsCount - implArgs.size();
if (callArgsCount - startArg > 1) {
code.add('(');
}
for (int i = startArg; i < callArgsCount; i++) {
if (i != startArg) {
code.add(", ");
@@ -1010,6 +1013,9 @@ public class InsnGen {
CodeVar argCodeVar = callArgs.get(i).getSVar().getCodeVar();
defVar(code, argCodeVar);
}
if (callArgsCount - startArg > 1) {
code.add(')');
}
}
// force set external arg names into call method args
int extArgsCount = customNode.getArgsCount();
@@ -0,0 +1,37 @@
package jadx.tests.integration.java8;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestLambdaArgs extends IntegrationTest {
public static class TestCls {
public void test1() {
call1(a -> -a);
}
public void test2() {
call2((a, b) -> a - b);
}
private void call1(Function<Integer, Integer> func) {
}
private void call2(BiFunction<Integer, Integer, Integer> func) {
}
}
@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.containsOne("call1(a ->")
.containsOne("call2((a, b) ->");
}
}