use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class RemoveUnnecessaryCastRefactoring method createPrimitive.
private void createPrimitive(final CastExpression node, final NumberLiteral literal, final char postfix) {
final ASTBuilder b = this.ctx.getASTBuilder();
final NumberLiteral numberLiteral = b.numberLiteral();
numberLiteral.setToken(literal.getToken() + postfix);
ctx.getRefactorings().replace(node, numberLiteral);
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class RemoveUselessBlockRefactoring method replaceBlock.
@SuppressWarnings("unchecked")
private void replaceBlock(final Block node) {
final ASTBuilder b = this.ctx.getASTBuilder();
final Refactorings r = this.ctx.getRefactorings();
r.replace(node, b.copyRange(node.statements()));
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class SimplifyExpressionRefactoring method replaceBy.
private boolean replaceBy(ASTNode node, Expression expr) {
final ASTBuilder b = ctx.getASTBuilder();
ctx.getRefactorings().replace(node, b.move(expr));
return DO_NOT_VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class SimplifyExpressionRefactoring method addParentheses.
private void addParentheses(Expression e) {
final ASTBuilder b = this.ctx.getASTBuilder();
this.ctx.getRefactorings().replace(e, b.parenthesize(b.copy(e)));
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class SimplifyExpressionRefactoring method maybeReduceBooleanExpression.
private boolean maybeReduceBooleanExpression(final InfixExpression node, final Expression leftExpr, final Expression rightExpr) {
final Boolean leftBoolean = getBooleanLiteral(leftExpr);
final Boolean rightBoolean = getBooleanLiteral(rightExpr);
if (leftBoolean != null) {
return replace(node, leftBoolean.booleanValue(), rightExpr);
} else if (rightBoolean != null) {
return replace(node, rightBoolean.booleanValue(), leftExpr);
}
Expression leftOppositeExpr = null;
final PrefixExpression leftPrefix = as(leftExpr, PrefixExpression.class);
if (leftPrefix != null && hasOperator(leftPrefix, NOT)) {
leftOppositeExpr = leftPrefix.getOperand();
}
Expression rightOppositeExpr = null;
final PrefixExpression rightPrefix = as(rightExpr, PrefixExpression.class);
if (rightPrefix != null && hasOperator(rightPrefix, NOT)) {
rightOppositeExpr = rightPrefix.getOperand();
}
final ASTBuilder b = this.ctx.getASTBuilder();
final Refactorings r = this.ctx.getRefactorings();
if (leftOppositeExpr != null && rightOppositeExpr != null) {
r.replace(node, b.infixExpr(b.copy(leftOppositeExpr), getAppropriateOperator(node), b.copy(rightOppositeExpr)));
return DO_NOT_VISIT_SUBTREE;
} else if (leftOppositeExpr != null) {
final Operator reverseOp = getReverseOperator(node);
r.replace(node, b.infixExpr(b.copy(leftOppositeExpr), reverseOp, b.copy(rightExpr)));
return DO_NOT_VISIT_SUBTREE;
} else if (rightOppositeExpr != null) {
final Operator reverseOp = getReverseOperator(node);
r.replace(node, b.infixExpr(b.copy(leftExpr), reverseOp, b.copy(rightOppositeExpr)));
return DO_NOT_VISIT_SUBTREE;
}
return VISIT_SUBTREE;
}
Aggregations