// 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()));
postfix.setOperator(PostfixExpression.Operator
.toOperator(operator));
expression = postfix;
// Produce prefix operators next time.
if (operator.equals("--")) {
isPostfix = false;
}
} else {
PrefixExpression prefix = ast.newPrefixExpression();
prefix.setOperand((Expression) ASTNode.copySubtree(ast,
assignment.getLeftHandSide()));
prefix.setOperator(PrefixExpression.Operator
.toOperator(operator));
expression = prefix;
}
returnStatement.setExpression(expression);
} else {
Assignment newAssignment = (Assignment) ASTNode
.copySubtree(ast, assignment);
newAssignment.setOperator(Assignment.Operator
.toOperator(operator));
returnStatement.setExpression(newAssignment);
}
switchStatement.statements().add(returnStatement);
}
// The default statement: just return the old value.
// This case should not be reached.
SwitchCase defaultCase = ast.newSwitchCase();
defaultCase.setExpression(null);
switchStatement.statements().add(defaultCase);
ReturnStatement defaultReturn = ast.newReturnStatement();
defaultReturn.setExpression((Expression) ASTNode.copySubtree(ast,
assignment.getLeftHandSide()));
switchStatement.statements().add(defaultReturn);
block.statements().add(switchStatement);
} else {
ReturnStatement returnStatement = ast.newReturnStatement();
returnStatement.setExpression(assignment);