fix: implement 'copy' and 'isSame' methods in InvokeCustomNode

This commit is contained in:
Skylot
2021-02-02 16:26:16 +00:00
parent 913b00a4d4
commit f6783e8f5e
2 changed files with 72 additions and 0 deletions
@@ -20,6 +20,38 @@ public class InvokeCustomNode extends InvokeNode {
super(lambdaInfo, insn, InvokeType.CUSTOM, instanceCall, isRange);
}
private InvokeCustomNode(MethodInfo mth, InvokeType invokeType, int argsCount) {
super(mth, invokeType, argsCount);
}
@Override
public InsnNode copy() {
InvokeCustomNode copy = new InvokeCustomNode(getCallMth(), getInvokeType(), getArgsCount());
copyCommonParams(copy);
copy.setImplMthInfo(implMthInfo);
copy.setHandleType(handleType);
copy.setCallInsn(callInsn);
copy.setInlineInsn(inlineInsn);
copy.setUseRef(useRef);
return copy;
}
@Override
public boolean isSame(InsnNode obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof InvokeCustomNode) || !super.isSame(obj)) {
return false;
}
InvokeCustomNode other = (InvokeCustomNode) obj;
return handleType == other.handleType
&& implMthInfo.equals(other.implMthInfo)
&& callInsn.isSame(other.callInsn)
&& inlineInsn == other.inlineInsn
&& useRef == other.useRef;
}
public MethodInfo getImplMthInfo() {
return implMthInfo;
}
@@ -0,0 +1,40 @@
package jadx.tests.integration.java8;
import java.util.Arrays;
import java.util.List;
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 TestLambdaInArray extends IntegrationTest {
public static class TestCls {
public List<Function<String, Integer>> test() {
return Arrays.asList(this::call1, this::call2);
}
private Integer call1(String s) {
return null;
}
private Integer call2(String s) {
return null;
}
public void check() throws Exception {
assertThat(test()).hasSize(2);
}
}
@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.containsOne("return Arrays.asList(this::call1, this::call2);");
}
}