core: fix replace target in if instruction (#317)

This commit is contained in:
Skylot
2018-07-19 15:27:35 +03:00
parent c5994f954a
commit a959af087b
2 changed files with 48 additions and 3 deletions
@@ -68,15 +68,16 @@ public class IfNode extends GotoNode {
@Override
public boolean replaceTargetBlock(BlockNode origin, BlockNode replace) {
boolean replaced = false;
if (thenBlock == origin) {
thenBlock = replace;
return true;
replaced = true;
}
if (elseBlock == origin) {
elseBlock = replace;
return true;
replaced = true;
}
return false;
return replaced;
}
public BlockNode getThenBlock() {
@@ -0,0 +1,44 @@
package jadx.tests.integration.switches;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import org.junit.Test;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class TestSwitchReturnFromCase2 extends IntegrationTest {
public static class TestCls {
public boolean test(int a) {
switch (a % 4) {
case 2:
case 3:
if (a == 2) {
return true;
}
return true;
}
return false;
}
public void check() {
assertTrue(test(2));
assertTrue(test(3));
assertTrue(test(15));
assertFalse(test(1));
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsString("switch (a % 4) {"));
}
}