Search in sources :

Example 51 with ASTBuilder

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);
    }
}
Also used : InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) Expression(org.eclipse.jdt.core.dom.Expression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 52 with ASTBuilder

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;
}
Also used : ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 53 with ASTBuilder

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;
}
Also used : Refactorings(org.autorefactor.refactoring.Refactorings) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 54 with ASTBuilder

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;
}
Also used : IfStatement(org.eclipse.jdt.core.dom.IfStatement) Statement(org.eclipse.jdt.core.dom.Statement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) Block(org.eclipse.jdt.core.dom.Block) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 55 with ASTBuilder

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;
}
Also used : ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Aggregations

ASTBuilder (org.autorefactor.refactoring.ASTBuilder)79 Expression (org.eclipse.jdt.core.dom.Expression)25 Refactorings (org.autorefactor.refactoring.Refactorings)23 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)19 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)12 IfStatement (org.eclipse.jdt.core.dom.IfStatement)10 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)9 Statement (org.eclipse.jdt.core.dom.Statement)9 Type (org.eclipse.jdt.core.dom.Type)9 Block (org.eclipse.jdt.core.dom.Block)6 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)6 ArrayList (java.util.ArrayList)5 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)5 ASTHelper.hasType (org.autorefactor.refactoring.ASTHelper.hasType)4 NotImplementedException (org.autorefactor.util.NotImplementedException)4 ASTMatcher (org.eclipse.jdt.core.dom.ASTMatcher)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 EnhancedForStatement (org.eclipse.jdt.core.dom.EnhancedForStatement)4 ForStatement (org.eclipse.jdt.core.dom.ForStatement)4 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)4