// Add a commit method.
MethodDeclaration commit = ast.newMethodDeclaration();
commit.setName(ast.newSimpleName(_getCommitMethodName(false)));
// Add two parameters.
SingleVariableDeclaration timestamp = ast
.newSingleVariableDeclaration();
timestamp.setType(ast.newPrimitiveType(PrimitiveType.LONG));
timestamp.setName(ast.newSimpleName("timestamp"));
commit.parameters().add(timestamp);
// Add a call to the restore method in the enclosing anonymous class.
MethodInvocation invocation = ast.newMethodInvocation();
invocation.setName(ast.newSimpleName(_getCommitMethodName(true)));
invocation.arguments().add(ast.newSimpleName("timestamp"));
Block body = ast.newBlock();
body.statements().add(ast.newExpressionStatement(invocation));
commit.setBody(body);
commit.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
commit.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
classDeclaration.bodyDeclarations().add(commit);
// Add a restore method.
MethodDeclaration restore = ast.newMethodDeclaration();
restore.setName(ast.newSimpleName(_getRestoreMethodName(false)));
// Add two parameters.
timestamp = ast.newSingleVariableDeclaration();
timestamp.setType(ast.newPrimitiveType(PrimitiveType.LONG));
timestamp.setName(ast.newSimpleName("timestamp"));
restore.parameters().add(timestamp);
SingleVariableDeclaration trim = ast.newSingleVariableDeclaration();
trim.setType(ast.newPrimitiveType(PrimitiveType.BOOLEAN));
trim.setName(ast.newSimpleName("trim"));
restore.parameters().add(trim);
// Add a call to the restore method in the enclosing anonymous class.
invocation = ast.newMethodInvocation();
invocation.setName(ast.newSimpleName(_getRestoreMethodName(true)));
invocation.arguments().add(ast.newSimpleName("timestamp"));
invocation.arguments().add(ast.newSimpleName("trim"));
body = ast.newBlock();
body.statements().add(ast.newExpressionStatement(invocation));
restore.setBody(body);
restore.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
restore.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
classDeclaration.bodyDeclarations().add(restore);
// Add a get checkpoint method.
MethodDeclaration getCheckpoint = ast.newMethodDeclaration();
String checkpointType = getClassName(Checkpoint.class, state, root);
getCheckpoint.setName(ast
.newSimpleName(_getGetCheckpointMethodName(false)));
getCheckpoint.setReturnType2(createType(ast, checkpointType));
invocation = ast.newMethodInvocation();
invocation
.setName(ast.newSimpleName(_getGetCheckpointMethodName(true)));
body = ast.newBlock();
ReturnStatement returnStatement = ast.newReturnStatement();
returnStatement.setExpression(invocation);
body.statements().add(returnStatement);
getCheckpoint.setBody(body);
getCheckpoint.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
getCheckpoint.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
classDeclaration.bodyDeclarations().add(getCheckpoint);
// Add a set checkpoint method.
MethodDeclaration setCheckpoint = ast.newMethodDeclaration();
setCheckpoint.setName(ast
.newSimpleName(_getSetCheckpointMethodName(false)));
setCheckpoint.setReturnType2(createType(ast, getClassName(Object.class,
state, root)));
// Add a single checkpoint parameter.
SingleVariableDeclaration checkpoint = ast
.newSingleVariableDeclaration();
checkpoint.setType(createType(ast, checkpointType));
checkpoint.setName(ast.newSimpleName("checkpoint"));
setCheckpoint.parameters().add(checkpoint);
// Add a call to the setcheckpoint method in the enclosing anonymous
// class.
invocation = ast.newMethodInvocation();