TryStatement tryStmt= new TryStatement();
tryStmt.header= (TryHeaderNode) graph.createNode(TryHeaderNode.class);
tryStmt.header.tryStmt= tryStmt;
Block tryBlock= new Block(start, end);
tryStmt.setTryBlock(tryBlock);
// tryStmt.setBeginIndex(start);
tryStatements.add(tryStmt);
CatchClause cStmt= null;
// Collect all non-default handlers. The range of each handler is
// from the 'store'-instruction to the beginning of the next
// handler.
while (handle != null && !handle.isDefault() && handle.getStartPC() == start && handle.getEndPC() == end)
{
if (cStmt != null)
{
cStmt.setEndIndex(handle.getHandlerPC() - 1);
}
cStmt= createCatchClause(tryStmt, handle);
handle= handleIterator.hasNext() ? handleIterator.next() : null;
}
int foo= -1;
if (handle != null && handle.isDefault() && handle.getStartPC() == start)
{
// Collect first default handler.
hasFinally= true;
if (cStmt != null)
{
cStmt.setEndIndex(handle.getHandlerPC() - 1);
tryStmt.setEndIndex(handle.getHandlerPC() - 1);
// Warning: We only set a lower bound for the end index. The
// correct index is set later
// when the finally statement is analysed.
}
cStmt= createCatchClause(tryStmt, handle);
foo= handle.getHandlerPC();
handle= handleIterator.hasNext() ? handleIterator.next() : null;
}
// Last catch stmt has no endIndex, yet!
while (handle != null && handle.isDefault() && (handle.getHandlerPC() == foo))
{
// Skip all remaining default handlers.
throw new RuntimeException("remaining default handlers");
// handle = handleIterator.hasNext()?handleIterator.next():null;
}
Block catches= tryStmt.getCatchStatements();
if (catches.getChildCount() == 0)
{
throw new ParseException("A try clause must have at least one (possibly default) catch clause", tryStmt);
}
cStmt= (CatchClause) catches.getChildAt(0);
tryBlock.setEndIndex(cStmt.getBeginIndex() - 1);
cStmt= (CatchClause) catches.getLastChild();
if (cStmt.getEndIndex() == Integer.MIN_VALUE)
{
cStmt.setEndIndex(cStmt.getBeginIndex() + 1);
}
tryStmt.setEndIndex(cStmt.getEndIndex());