}
SourceInfo catchInfo = ((JBlock) x.getCatchBlocks().get(0)).getSourceInfo();
JLocal exObj = popTempLocal();
JLocalRef exRef = new JLocalRef(program, catchInfo, exObj);
JBlock newCatchBlock = new JBlock(program, catchInfo);
// $e = Exceptions.caught($e)
JMethod caughtMethod = program.getSpecialMethod("Exceptions.caught");
JMethodCall call = new JMethodCall(program, catchInfo, null, caughtMethod);
call.getArgs().add(exRef);
JExpressionStatement asg = program.createAssignmentStmt(catchInfo, exRef,
call);
newCatchBlock.statements.add(asg);
/*
* Build up a series of if, else if statements to test the type of the
* exception object against the type of the user's catch block.
*
* Go backwards so we can nest the else statements in the correct order!
*/
// rethrow the current exception if no one caught it
JStatement cur = new JThrowStatement(program, null, exRef);
for (int i = x.getCatchBlocks().size() - 1; i >= 0; --i) {
JBlock block = (JBlock) x.getCatchBlocks().get(i);
JLocalRef arg = (JLocalRef) x.getCatchArgs().get(i);
catchInfo = block.getSourceInfo();
JReferenceType argType = (JReferenceType) arg.getType();
// if ($e instanceof ArgType) { userVar = $e; <user code> }
JExpression ifTest = new JInstanceOf(program, catchInfo, argType, exRef);
asg = program.createAssignmentStmt(catchInfo, arg, exRef);
if (!block.statements.isEmpty()) {
// Only bother adding the assignment if the block is non-empty