fix: variable usage with enhanced for loop (#535) (PR #547)

This commit is contained in:
Ahmed Ashour
2019-04-01 20:07:28 +02:00
committed by skylot
parent 3970fce503
commit e6e8f6367e
4 changed files with 65 additions and 52 deletions
@@ -1,38 +0,0 @@
package jadx.tests.integration.variables;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import jadx.NotYetImplemented;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
public class TestVariables7 extends IntegrationTest {
public static class TestCls {
public void test() {
List list;
synchronized (this) {
list = new ArrayList();
}
for (Object o : list) {
System.out.println(o);
}
}
}
@Test
@NotYetImplemented
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsString(" list = new ArrayList"));
}
}
@@ -0,0 +1,57 @@
package jadx.tests.integration.variables;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
public class TestVariablesUsageWithLoops extends IntegrationTest {
public static class TestEnhancedFor {
public void test() {
List list;
synchronized (this) {
list = new ArrayList();
}
for (Object o : list) {
System.out.println(o);
}
}
}
@Test
public void testEnhancedFor() {
ClassNode cls = getClassNode(TestEnhancedFor.class);
String code = cls.getCode().toString();
assertThat(code, containsString(" list = new ArrayList"));
}
public static class TestForLoop {
public void test() {
List list;
synchronized (this) {
list = new ArrayList();
}
for (int i = 0; i < list.size(); i++) {
System.out.println(i);
}
}
}
@Test
public void testForLoop() {
ClassNode cls = getClassNode(TestForLoop.class);
String code = cls.getCode().toString();
assertThat(code, containsString(" list = new ArrayList"));
}
}