castExpression.setType(createType(ast, typeName));
castExpression.setExpression(restoreMethodCall);
rightHandSide = castExpression;
}
Assignment assignment = ast.newAssignment();
assignment.setLeftHandSide(ast.newSimpleName(fieldName));
assignment.setRightHandSide(rightHandSide);
body.statements().add(
ast.newExpressionStatement(assignment));
}
}
// Add a call to the restore method in the superclass, if necessary.
SuperMethodInvocation superRestore = ast.newSuperMethodInvocation();
superRestore.setName(ast
.newSimpleName(_getRestoreMethodName(false)));
superRestore.arguments().add(ast.newSimpleName("timestamp"));
superRestore.arguments().add(ast.newSimpleName("trim"));
Statement superRestoreStatement = ast
.newExpressionStatement(superRestore);
if ((parent != null)
&& (state.getCrossAnalyzedTypes()
.contains(parent.getName()) || hasMethod(parent,
methodName,
new Class[] { int.class, boolean.class }))) {
body.statements().add(superRestoreStatement);
} else {
// Restore the previous checkpoint, if necessary.
IfStatement restoreCheckpoint = ast.newIfStatement();
InfixExpression timestampTester = ast.newInfixExpression();
timestampTester.setLeftOperand(ast.newSimpleName("timestamp"));
timestampTester
.setOperator(InfixExpression.Operator.LESS_EQUALS);
MethodInvocation topTimestamp = ast.newMethodInvocation();
topTimestamp.setExpression(ast
.newSimpleName(CHECKPOINT_RECORD_NAME));
topTimestamp.setName(ast.newSimpleName("getTopTimestamp"));
timestampTester.setRightOperand(topTimestamp);
restoreCheckpoint.setExpression(timestampTester);
Block restoreBlock = ast.newBlock();
restoreCheckpoint.setThenStatement(restoreBlock);
// Assign the old checkpoint.
Assignment assignCheckpoint = ast.newAssignment();
assignCheckpoint.setLeftHandSide(ast
.newSimpleName(CHECKPOINT_NAME));
MethodInvocation restoreCheckpointInvocation = ast
.newMethodInvocation();
restoreCheckpointInvocation.setExpression(ast
.newSimpleName(CHECKPOINT_RECORD_NAME));
restoreCheckpointInvocation.setName(ast
.newSimpleName("restore"));
restoreCheckpointInvocation.arguments().add(
ast.newSimpleName(CHECKPOINT_NAME));
restoreCheckpointInvocation.arguments().add(
_createRollbackableObject(ast, isAnonymous));
restoreCheckpointInvocation.arguments().add(
ast.newSimpleName("timestamp"));
restoreCheckpointInvocation.arguments().add(
ast.newSimpleName("trim"));
assignCheckpoint.setRightHandSide(restoreCheckpointInvocation);
restoreBlock.statements().add(
ast.newExpressionStatement(assignCheckpoint));
// Pop the old states.
MethodInvocation popStates = ast.newMethodInvocation();