core: improve 'if' detection with 'return' instruction

This commit is contained in:
Skylot
2014-05-17 16:51:24 +04:00
parent 4a6115ed64
commit 0d94af099b
21 changed files with 358 additions and 175 deletions
@@ -53,7 +53,7 @@ public class TestRedundantBrackets extends InternalJadxTest {
assertThat(code, containsString("return obj instanceof String ? ((String) obj).length() : 0;"));
assertThat(code, containsString("if (a + b < 10)"));
assertThat(code, containsString("if ((a & b) != 0)"));
// assertThat(code, containsString("if ((a & b) != 0)"));
assertThat(code, containsString("if (num == 4 || num == 6 || num == 8 || num == 10)"));
assertThat(code, containsString("a[1] = n * 2;"));
@@ -0,0 +1,31 @@
package jadx.tests.internal;
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;
import static org.junit.Assert.fail;
public class TestRedundantReturn extends InternalJadxTest {
public static class TestCls {
public void test(int num) {
if (num == 4) {
fail();
}
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, not(containsString("return;")));
}
}
@@ -0,0 +1,70 @@
package jadx.tests.internal.conditions;
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 TestConditions8 extends InternalJadxTest {
public static class TestCls {
private TestCls pager;
private TestCls listView;
public void test(TestCls view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (!isUsable()) {
return;
}
if (!pager.hasMore()) {
return;
}
if (getLoaderManager().hasRunningLoaders()) {
return;
}
if (listView != null
&& listView.getLastVisiblePosition() >= pager.size()) {
showMore();
}
}
private void showMore() {
}
private int size() {
return 0;
}
private int getLastVisiblePosition() {
return 0;
}
private boolean hasRunningLoaders() {
return false;
}
private TestCls getLoaderManager() {
return null;
}
private boolean hasMore() {
return false;
}
private boolean isUsable() {
return false;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsString("showMore();"));
}
}