core: fixed 'this' attribute propagation for move insn (#345)

This commit is contained in:
Skylot
2018-08-22 20:47:39 +03:00
parent ffe739b7eb
commit ecbb53aaea
8 changed files with 129 additions and 49 deletions
@@ -0,0 +1,42 @@
package jadx.tests.integration.usethis;
import java.util.Random;
import org.junit.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestDontInlineThis extends IntegrationTest {
public static class TestCls {
public int field = new Random().nextInt();
private TestCls test() {
TestCls res;
if (field == 7) {
res = this;
} else {
res = new TestCls();
}
res.method();
return res;
}
private void method() {
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("TestDontInlineThis$TestCls res"));
assertThat(code, containsOne("res = this;"));
assertThat(code, containsOne("res = new TestDontInlineThis$TestCls();"));
}
}
@@ -0,0 +1,47 @@
package jadx.tests.integration.usethis;
import java.util.Objects;
import org.junit.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
public class TestInlineThis2 extends IntegrationTest {
public static class TestCls {
public int field;
private void test() {
TestCls thisVar = this;
if (Objects.isNull(thisVar)) {
System.out.println("null");
}
thisVar.method();
thisVar.field = 123;
}
private void method() {
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, not(containsString("thisVar")));
assertThat(code, not(containsString("thisVar.method()")));
assertThat(code, not(containsString("thisVar.field")));
assertThat(code, not(containsString("= this")));
assertThat(code, containsOne("if (Objects.isNull(this)) {"));
assertThat(code, containsOne("this.field = 123;"));
assertThat(code, containsOne("method();"));
}
}