-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: transform loop to
for
with branching at end
Signed-off-by: Skylot <skylot@gmail.com>
- Loading branch information
Showing
4 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package jadx.tests.integration.loops; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
/** | ||
* Issue #977 | ||
*/ | ||
public class TestArrayForEach3 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
public void test(String[] arr) { | ||
for (String s : arr) { | ||
if (s.length() > 0) { | ||
return; | ||
} | ||
} | ||
throw new IllegalArgumentException("All strings are empty"); | ||
} | ||
|
||
public void check() { | ||
test(new String[] { "", "a" }); // no exception | ||
try { | ||
test(new String[] { "", "" }); | ||
fail("IllegalArgumentException expected"); | ||
} catch (IllegalArgumentException e) { | ||
// expected | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
noDebugInfo(); | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.doesNotContain("while") | ||
.containsOne("for (String str : strArr) {"); | ||
} | ||
} |