-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: force one branch ternary in constructors (#685)
- Loading branch information
Showing
2 changed files
with
118 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
...re/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor.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,51 @@ | ||
package jadx.tests.integration.conditions; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.JadxMatchers.containsOne; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class TestTernaryOneBranchInConstructor extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
public TestCls(String str, int i) { | ||
this(str == null ? 0 : i); | ||
} | ||
|
||
public TestCls(int i) { | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("this(str == null ? 0 : i);")); | ||
assertThat(code, not(containsString("//"))); | ||
} | ||
|
||
public static class TestCls2 { | ||
public TestCls2(String str, int i) { | ||
this(i == 1 ? str : "", i == 0 ? "" : str); | ||
} | ||
|
||
public TestCls2(String a, String b) { | ||
} | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
noDebugInfo(); | ||
ClassNode cls = getClassNode(TestCls2.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("this(i == 1 ? str : \"\", i == 0 ? \"\" : str);")); | ||
assertThat(code, not(containsString("//"))); | ||
} | ||
} |