mirror of
https://github.com/skylot/jadx.git
synced 2024-11-26 22:20:50 +00:00
fix: fix default branch position in switch-over-string (PR #2331)
This commit is contained in:
parent
2661b91a6f
commit
cfbe5ab672
@ -103,10 +103,10 @@ public class SwitchOverStringVisitor extends AbstractVisitor implements IRegionI
|
||||
// all checks passed, replace with new switch
|
||||
IRegion parentRegion = switchRegion.getParent();
|
||||
SwitchRegion replaceRegion = new SwitchRegion(parentRegion, switchRegion.getHeader());
|
||||
replaceRegion.addDefaultCase(switchData.getDefaultCode());
|
||||
for (CaseData caseData : switchData.getCases()) {
|
||||
replaceRegion.addCase(Collections.unmodifiableList(caseData.getStrValues()), caseData.getCode());
|
||||
}
|
||||
replaceRegion.addDefaultCase(switchData.getDefaultCode());
|
||||
if (!parentRegion.replaceSubBlock(switchRegion, replaceRegion)) {
|
||||
mth.addWarnComment("Failed to restore switch over string. Please report as a decompilation issue");
|
||||
return false;
|
||||
|
@ -4,13 +4,20 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.assertj.core.api.AbstractStringAssert;
|
||||
import org.assertj.core.internal.Failures;
|
||||
|
||||
import jadx.tests.api.utils.TestUtils;
|
||||
|
||||
import static org.assertj.core.error.ShouldNotContainSubsequence.shouldNotContainSubsequence;
|
||||
|
||||
public class JadxCodeAssertions extends AbstractStringAssert<JadxCodeAssertions> {
|
||||
|
||||
private Failures failures = Failures.instance();
|
||||
|
||||
public JadxCodeAssertions(String code) {
|
||||
super(code, JadxCodeAssertions.class);
|
||||
}
|
||||
@ -65,6 +72,21 @@ public class JadxCodeAssertions extends AbstractStringAssert<JadxCodeAssertions>
|
||||
return containsOnlyOnce(sb.substring(1));
|
||||
}
|
||||
|
||||
public JadxCodeAssertions doesNotContainSubsequence(CharSequence... values) {
|
||||
final var regex = Arrays.stream(values)
|
||||
.map(value -> Pattern.quote(value.toString()))
|
||||
.collect(Collectors.joining(".*"));
|
||||
|
||||
final var pattern = Pattern.compile(regex, Pattern.DOTALL);
|
||||
|
||||
final var matcher = pattern.matcher(actual);
|
||||
if (matcher.find()) {
|
||||
throw failures.failure(info, shouldNotContainSubsequence(actual, values, matcher.start()));
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public JadxCodeAssertions removeBlockComments() {
|
||||
String code = actual.replaceAll("/\\*.*\\*/", "");
|
||||
JadxCodeAssertions newCode = new JadxCodeAssertions(code);
|
||||
|
@ -46,6 +46,7 @@ public class TestSwitchOverStrings extends IntegrationTest {
|
||||
.code()
|
||||
.doesNotContain("case -603257287:")
|
||||
.doesNotContain("c = ")
|
||||
.doesNotContainSubsequence("default:", "case ")
|
||||
.containsOne("case \"frewhyh\":")
|
||||
.countString(5, "return ");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user