use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class AbstractUnitTestRefactoring method invokeFail.
private MethodInvocation invokeFail(final ASTNode node, final MethodInvocation originalMethod, final Expression failureMessage) {
final ASTBuilder b = this.ctx.getASTBuilder();
final List<Expression> args = arguments(originalMethod);
if ((args.size() == 1) || (args.size() == 2)) {
return invokeMethod(b, originalMethod, "fail", null, null, failureMessage);
} else {
throw new NotImplementedException(node);
}
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class ComparisonRefactoring method replaceWithCorrectCheckOnCompareTo.
private boolean replaceWithCorrectCheckOnCompareTo(final InfixExpression ie, final Operator operator) {
final ASTBuilder b = this.ctx.getASTBuilder();
this.ctx.getRefactorings().replace(ie, b.infixExpr(b.copy(ie.getLeftOperand()), operator, b.number("0")));
return DO_NOT_VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class IsEmptyRatherThanSizeRefactoring method replaceCollectionSize.
private boolean replaceCollectionSize(final InfixExpression node, final MethodInvocation miToReplace, final Operator operator, final long literalSize) {
final Refactorings r = this.ctx.getRefactorings();
final ASTBuilder b = this.ctx.getASTBuilder();
if (literalSize == 0) {
if (GREATER_EQUALS.equals(operator)) {
r.replace(node, b.boolean0(true));
return DO_NOT_VISIT_SUBTREE;
} else if (LESS.equals(operator)) {
r.replace(node, b.boolean0(false));
} else if (GREATER.equals(operator)) {
r.replace(node, b.not(b.invoke(b.copyExpression(miToReplace), "isEmpty")));
return DO_NOT_VISIT_SUBTREE;
} else if (EQUALS.equals(operator)) {
r.replace(node, b.invoke(b.copyExpression(miToReplace), "isEmpty"));
return DO_NOT_VISIT_SUBTREE;
} else if (NOT_EQUALS.equals(operator)) {
r.replace(node, b.not(b.invoke(b.copyExpression(miToReplace), "isEmpty")));
return DO_NOT_VISIT_SUBTREE;
} else if (LESS_EQUALS.equals(operator)) {
r.replace(node, b.invoke(b.copyExpression(miToReplace), "isEmpty"));
return DO_NOT_VISIT_SUBTREE;
}
} else if (literalSize == 1) {
if (GREATER_EQUALS.equals(operator)) {
r.replace(node, b.not(b.invoke(b.copyExpression(miToReplace), "isEmpty")));
return DO_NOT_VISIT_SUBTREE;
} else if (LESS.equals(operator)) {
r.replace(node, b.invoke(b.copyExpression(miToReplace), "isEmpty"));
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class IfElseIfRefactoring method visit.
// TODO JNR
// UseIfElseIfRefactoring
// if (b) {
// return i;
// }
// if (c) {
// return j;
// }
// if (d) {
// return k;
// }
// return l;
@Override
public boolean visit(IfStatement node) {
final Statement elseStmt = node.getElseStatement();
if (elseStmt instanceof Block) {
List<Statement> elseStmts = statements((Block) elseStmt);
if (elseStmts.size() == 1 && elseStmts.get(0) instanceof IfStatement) {
final ASTBuilder b = this.ctx.getASTBuilder();
this.ctx.getRefactorings().set(node, ELSE_STATEMENT_PROPERTY, b.copy(elseStmts.get(0)));
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class PrimitiveWrapperCreationRefactoring method replaceWithTheSingleArgument.
private boolean replaceWithTheSingleArgument(MethodInvocation node) {
final ASTBuilder b = this.ctx.getASTBuilder();
this.ctx.getRefactorings().replace(node, b.copy(arg0(node)));
return DO_NOT_VISIT_SUBTREE;
}
Aggregations