recordInvocation.arguments().add(arrayCreation);
}
// If there are indices, add them ("index0", "index1", ...) after the
// field.
Expression field = ast.newSimpleName(fieldName);
if (indices > 0) {
for (int i = 0; i < indices; i++) {
ArrayAccess arrayAccess = ast.newArrayAccess();
arrayAccess.setArray(field);
arrayAccess.setIndex(ast.newSimpleName("index" + i));
field = arrayAccess;
}
}
// Set the field as the next argument.
recordInvocation.arguments().add(field);
// Get current timestamp from the checkpoint object.
MethodInvocation timestampGetter = ast.newMethodInvocation();
timestampGetter.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
timestampGetter.setName(ast.newSimpleName("getTimestamp"));
// Set the timestamp as the next argument.
recordInvocation.arguments().add(timestampGetter);
// The statement of the method call.
ExpressionStatement recordStatement = ast
.newExpressionStatement(recordInvocation);
thenBranch.statements().add(recordStatement);
ifStatement.setThenStatement(thenBranch);
block.statements().add(ifStatement);
// Finally, assign the new value to the field.
Assignment assignment = ast.newAssignment();
assignment
.setLeftHandSide((Expression) ASTNode.copySubtree(ast, field));
assignment.setRightHandSide(ast.newSimpleName("newValue"));
assignment.setOperator(Assignment.Operator.ASSIGN);
// Set the checkpoint object of the new value, if necessary.
Class c;
try {
c = fieldType.toClass(state.getClassLoader());
} catch (ClassNotFoundException e) {
throw new ASTClassNotFoundException(fieldType.getName());
}
if (hasMethod(c, _getSetCheckpointMethodName(false),
new Class[] { Checkpoint.class })
|| state.getCrossAnalyzedTypes().contains(c.getName())) {
block.statements().add(_createSetCheckpointInvocation(ast));
} else {
addToLists(_fixSetCheckpoint, c.getName(), block);
}
// Return the result of the assignment.
if (special && _assignOperators.containsKey(fieldType.getName())) {
String[] operators = _assignOperators.get(fieldType.getName());
SwitchStatement switchStatement = ast.newSwitchStatement();
switchStatement.setExpression(ast.newSimpleName("operator"));
boolean isPostfix = true;
for (int i = 0; i < operators.length; i++) {
String operator = operators[i];
SwitchCase switchCase = ast.newSwitchCase();
switchCase.setExpression(ast.newNumberLiteral(Integer
.toString(i)));
switchStatement.statements().add(switchCase);
ReturnStatement returnStatement = ast.newReturnStatement();
if (operator.equals("=")) {
Assignment newAssignment = (Assignment) ASTNode
.copySubtree(ast, assignment);
returnStatement.setExpression(newAssignment);
} else if (operator.equals("++") || operator.equals("--")) {
Expression expression;
if (isPostfix) {
PostfixExpression postfix = ast.newPostfixExpression();
postfix.setOperand((Expression) ASTNode.copySubtree(
ast, assignment.getLeftHandSide()));