[java-decompiler] Patch 0048 from ForgeFlower.Improve output of loops inside trycatch

GitOrigin-RevId: 44c74aef2d7f6da9c2f7da6f7a53abbc463111cc
This commit is contained in:
SuperCoder79
2024-09-10 12:38:00 +02:00
committed by intellij-monorepo-bot
parent 4b2a63b5f4
commit 74e32bae0d
3 changed files with 29 additions and 1 deletions

View File

@@ -192,6 +192,26 @@ public final class DecHelper {
return setHandlers;
}
public static boolean invalidHeadMerge(Statement head) {
// Don't build a trycatch around a loop-head if statement, as we know that DoStatement should be built first.
// Since CatchStatement's isHead is run after DoStatement's, we can assume that a loop was not able to be built.
Statement ifhead = findIfHead(head);
return ifhead != null && head.getContinueSet().contains(ifhead.getFirst());
}
private static Statement findIfHead(Statement head) {
while (head != null && head.type != Statement.StatementType.IF) {
if (head.type != Statement.StatementType.SEQUENCE) {
return null;
}
head = head.getFirst();
}
return head;
}
public static List<Exprent> copyExprentList(List<? extends Exprent> lst) {
List<Exprent> ret = new ArrayList<>();
for (Exprent expr : lst) {
@@ -199,4 +219,4 @@ public final class DecHelper {
}
return ret;
}
}
}

View File

@@ -85,6 +85,10 @@ public final class CatchAllStatement extends Statement {
return null;
}
if (DecHelper.invalidHeadMerge(head)) {
return null;
}
if (DecHelper.checkStatementExceptions(Arrays.asList(head, exc))) {
return new CatchAllStatement(head, exc);
}

View File

@@ -129,6 +129,10 @@ public final class CatchStatement extends Statement {
}
}
if (DecHelper.invalidHeadMerge(head)) {
return null;
}
if (DecHelper.checkStatementExceptions(lst)) {
return new CatchStatement(head, next, setHandlers);
}