core: annotate generated code with reference to used methods
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
package jadx.tests.internal;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.instructions.ArithNode;
|
||||
import jadx.core.dex.instructions.ArithOp;
|
||||
import jadx.core.dex.instructions.InsnType;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.core.dex.nodes.InsnNode;
|
||||
import jadx.core.dex.nodes.MethodNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@@ -39,15 +31,9 @@ public class TestFieldIncrement extends InternalJadxTest {
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
MethodNode mth = getMethod(cls, "method");
|
||||
|
||||
List<InsnNode> insns = mth.getBasicBlocks().get(0).getInstructions();
|
||||
assertEquals(insns.size(), 1);
|
||||
InsnNode insnNode = insns.get(0);
|
||||
assertEquals(InsnType.ARITH, insnNode.getType());
|
||||
assertEquals(ArithOp.ADD, ((ArithNode) insnNode).getOp());
|
||||
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("instanceField++;"));
|
||||
assertThat(code, containsString("staticField--;"));
|
||||
assertThat(code, containsString("result += s + '_';"));
|
||||
|
||||
@@ -37,5 +37,7 @@ public class TestSynchronized extends InternalJadxTest {
|
||||
assertThat(code, containsString("public synchronized boolean test1() {"));
|
||||
assertThat(code, containsString("return this.f"));
|
||||
assertThat(code, containsString("synchronized (this.o) {"));
|
||||
|
||||
assertThat(code, not(containsString(makeIndent(3) + ";")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package jadx.tests.internal.arith;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestArith extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public void method(int a) {
|
||||
a += 2;
|
||||
}
|
||||
|
||||
public void method2(int a) {
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("a += 2;"));
|
||||
assertThat(code, containsString("a++;"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package jadx.tests.internal.arith;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestArith2 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public int test1(int a) {
|
||||
return (a + 2) * 3;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("return (a + 2) * 3;"));
|
||||
assertThat(code, not(containsString("a + 2 * 3")));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package jadx.tests.internal;
|
||||
package jadx.tests.internal.debuginfo;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.codegen.CodeWriter;
|
||||
Reference in New Issue
Block a user