in src/org/jetbrains/java/decompiler/modules/decompiler/PatternHelper.java [349:415]
private static boolean processCatchStatement(@NotNull VarTracker tracker,
@NotNull CatchStatement statement) {
Statement tryBody = statement.getFirst();
if (tryBody == null || tryBody.getStats() == null || !tryBody.getStats().isEmpty() ||
tryBody.getExprents() == null || tryBody.getExprents().size() != 1) {
return false;
}
Exprent body = tryBody.getExprents().get(0);
InvocationExprent invocationExprent = null;
boolean hasAssignment = false;
if (body instanceof AssignmentExprent assignmentExprent && assignmentExprent.getRight() instanceof InvocationExprent newInvocation) {
invocationExprent = newInvocation;
hasAssignment = true;
}
else if (body instanceof InvocationExprent newInvocation) {
invocationExprent = newInvocation;
}
if (invocationExprent == null) {
return false;
}
Exprent qualifier = invocationExprent.getInstance();
if (qualifier == null ||
invocationExprent.isStatic() ||
!(invocationExprent.getParameters() != null && invocationExprent.getParameters().isEmpty())) {
return false;
}
RecordVarExprent recordVarExprent = tracker.getRecord(qualifier);
if (recordVarExprent == null) {
return false;
}
if (statement.getStats().size() != 2) {
return false;
}
Statement catchSection = statement.getStats().get(1);
if (!(catchSection.getStats().isEmpty() && catchSection.getExprents() != null)) {
return false;
}
if (!((catchSection.getExprents().size() == 1) ||
(catchSection.getExprents().size() == 2 && catchSection.getExprents().get(1) instanceof ExitExprent))) {
return false;
}
Exprent throwExpected = catchSection.getExprents().get(0);
if (!((throwExpected instanceof ExitExprent exitExprent && exitExprent.getExitType() == EXIT_THROW &&
exitExprent.getValue() instanceof NewExprent newExprent && newExprent.getNewType() != null &&
MATCH_EXCEPTION.equals(newExprent.getNewType().getValue())) ||
(catchSection.getExprents().get(1) instanceof ExitExprent))) {
return false;
}
if (!hasAssignment) {
VarType exprType = invocationExprent.getExprType();
VarProcessor processor = DecompilerContext.getVarProcessor();
RecordVarExprent nextComponent = new RecordVarExprent(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER), exprType,processor ));
recordVarExprent.addComponent(nextComponent);
return true;
}
if (!(((AssignmentExprent)body).getLeft() instanceof VarExprent assignTo)) {
return false;
}
VarExprent assignToDefinition = (VarExprent)assignTo.copy();
assignToDefinition.setDefinition(true);
RecordVarExprent nextComponent = new RecordVarExprent(assignToDefinition);
recordVarExprent.addComponent(nextComponent);
tracker.put(assignTo, nextComponent, tryBody);
return true;
}