use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class BigDecimalRefactoring method getCompareToNode.
private InfixExpression getCompareToNode(final boolean isPositive, final MethodInvocation node) {
final ASTBuilder b = this.ctx.getASTBuilder();
final MethodInvocation mi = b.invoke(b.copy(node.getExpression()), "compareTo", b.copy(arg0(node)));
return b.infixExpr(mi, isPositive ? EQUALS : NOT_EQUALS, b.int0(0));
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class MergeConditionalBlocksRefactoring method maybeMergeBlocks.
private boolean maybeMergeBlocks(final Expression firstCondition, final List<Statement> ifCode, final IfStatement subNode, final Expression secondCondition, final Statement doubleStmts, final Statement remainingStmts, final boolean isPositive) {
if (isSameCode(ifCode, asList(doubleStmts))) {
final ASTBuilder b = this.ctx.getASTBuilder();
final Refactorings r = this.ctx.getRefactorings();
final Expression additionalCondition;
if (isPositive) {
additionalCondition = b.copy(secondCondition);
} else {
additionalCondition = b.negate(secondCondition, Copy.COPY);
}
r.replace(firstCondition, b.infixExpr(b.parenthesizeIfNeeded(b.copy(firstCondition)), InfixExpression.Operator.CONDITIONAL_OR, b.parenthesizeIfNeeded(additionalCondition)));
if (remainingStmts != null) {
r.replace(subNode, b.copy(remainingStmts));
} else {
r.remove(subNode);
}
return DO_NOT_VISIT_SUBTREE;
}
return VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class StringValueOfRatherThanConcatRefactoring method maybeReplaceStringConcatenation.
private boolean maybeReplaceStringConcatenation(final InfixExpression node, final Expression expr, final Expression variable) {
if (expr instanceof StringLiteral && ((StringLiteral) expr).getLiteralValue().matches("") && !hasType(variable, "java.lang.String", "char[]")) {
final ASTBuilder b = this.ctx.getASTBuilder();
ctx.getRefactorings().replace(node, b.invoke("String", "valueOf", b.copy(variable)));
return DO_NOT_VISIT_SUBTREE;
}
return VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class UseStringContainsRefactoring method replaceWithStringContains.
private boolean replaceWithStringContains(InfixExpression ie, MethodInvocation node, boolean negate) {
final Refactorings r = this.ctx.getRefactorings();
final ASTBuilder b = this.ctx.getASTBuilder();
r.set(node, MethodInvocation.NAME_PROPERTY, b.simpleName("contains"));
if (negate) {
r.replace(ie, b.not(b.move(node)));
} else {
r.replace(ie, b.move(node));
}
return DO_NOT_VISIT_SUBTREE;
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class AddBracketsToControlStatementRefactoring method setBlock.
private boolean setBlock(Statement statement) {
if (statement == null) {
return VISIT_SUBTREE;
}
final ASTBuilder b = this.ctx.getASTBuilder();
final Block block = b.block(b.copy(statement));
block.accept(this);
this.ctx.getRefactorings().replace(statement, block);
return DO_NOT_VISIT_SUBTREE;
}
Aggregations