Search in sources :

Example 91 with Expression

use of org.eclipse.jdt.core.dom.Expression in project AutoRefactor by JnRouvignac.

the class VectorOldToNewAPIRefactoring method replaceWithAndSwapArguments.

private void replaceWithAndSwapArguments(final MethodInvocation node, final String newMethodName) {
    final List<Expression> args = arguments(node);
    assertSize(args, 2);
    final Expression arg1 = args.get(1);
    final ASTBuilder b = ctx.getASTBuilder();
    final Refactorings r = ctx.getRefactorings();
    r.set(node, NAME_PROPERTY, b.simpleName(newMethodName));
    r.moveToIndex(arg1, 0, b.move(arg1));
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) Refactorings(org.autorefactor.refactoring.Refactorings) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 92 with Expression

use of org.eclipse.jdt.core.dom.Expression in project AutoRefactor by JnRouvignac.

the class VectorOldToNewAPIRefactoring method replaceWithSpecial.

private void replaceWithSpecial(final MethodInvocation node, final String newMethodName) {
    final List<Expression> args = arguments(node);
    assertSize(args, 1);
    final Expression arg0 = args.get(0);
    final ASTBuilder b = this.ctx.getASTBuilder();
    final Refactorings r = this.ctx.getRefactorings();
    r.set(node, NAME_PROPERTY, b.simpleName(newMethodName));
    if (hasType(arg0, "int", "short", "byte")) {
        r.replace(arg0, b.cast(b.type("Object"), b.move(arg0)));
    }
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) Refactorings(org.autorefactor.refactoring.Refactorings) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 93 with Expression

use of org.eclipse.jdt.core.dom.Expression in project AutoRefactor by JnRouvignac.

the class ForLoopHelper method getIndexOnIterable.

private static ForLoopContent getIndexOnIterable(final Expression condition, Name loopVariable) {
    final InfixExpression ie = as(condition, InfixExpression.class);
    if (ie != null && !ie.hasExtendedOperands()) {
        final Expression leftOp = ie.getLeftOperand();
        final Expression rightOp = ie.getRightOperand();
        if (hasOperator(ie, LESS)) {
            return buildForLoopContent(loopVariable, rightOp);
        } else if (hasOperator(ie, GREATER)) {
            return buildForLoopContent(loopVariable, leftOp);
        }
    }
    return null;
}
Also used : PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) Expression(org.eclipse.jdt.core.dom.Expression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression)

Example 94 with Expression

use of org.eclipse.jdt.core.dom.Expression in project AutoRefactor by JnRouvignac.

the class AbstractUnitTestRefactoring method invokeAssertNull.

private MethodInvocation invokeAssertNull(final MethodInvocation originalMethod, final boolean isPositive, final Expression actual, final Expression failureMessage) {
    final ASTBuilder b = this.ctx.getASTBuilder();
    final String methodName = getAssertName(isPositive, "Null");
    final Expression copyOfActual = b.copy(actual);
    return invokeMethod(b, originalMethod, methodName, copyOfActual, null, failureMessage);
}
Also used : InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) Expression(org.eclipse.jdt.core.dom.Expression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 95 with Expression

use of org.eclipse.jdt.core.dom.Expression in project AutoRefactor by JnRouvignac.

the class AbstractUnitTestRefactoring method maybeRefactorComparison.

private boolean maybeRefactorComparison(final ASTNode nodeToReplace, final MethodInvocation originalMethod, final InfixExpression ie, final boolean isAssertEquals, final Expression failureMessage, final boolean isRewriteNeeded) {
    final Pair<Expression, Expression> actualAndExpected = getActualAndExpected(ie.getLeftOperand(), ie.getRightOperand());
    if (isComparingObjects(ie) && !isNullLiteral(ie.getLeftOperand()) && !isNullLiteral(ie.getRightOperand())) {
        final ASTBuilder b = this.ctx.getASTBuilder();
        final Refactorings r = this.ctx.getRefactorings();
        final MethodInvocation newAssert = invokeMethod(b, originalMethod, getAssertName(isAssertEquals, "Same"), b.copy(actualAndExpected.getFirst()), b.copy(actualAndExpected.getSecond()), failureMessage);
        r.replace(nodeToReplace, invokeMethodOrStatement(nodeToReplace, b, newAssert));
        return DO_NOT_VISIT_SUBTREE;
    } else {
        return maybeRefactorToAssertEquals(nodeToReplace, originalMethod, isAssertEquals, actualAndExpected.getFirst(), actualAndExpected.getSecond(), failureMessage, true);
    }
}
Also used : InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) Expression(org.eclipse.jdt.core.dom.Expression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) Refactorings(org.autorefactor.refactoring.Refactorings) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Aggregations

Expression (org.eclipse.jdt.core.dom.Expression)552 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)263 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)213 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)187 CastExpression (org.eclipse.jdt.core.dom.CastExpression)185 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)135 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)126 ASTNode (org.eclipse.jdt.core.dom.ASTNode)125 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)122 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)121 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)112 AST (org.eclipse.jdt.core.dom.AST)101 PostfixExpression (org.eclipse.jdt.core.dom.PostfixExpression)95 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)88 SimpleName (org.eclipse.jdt.core.dom.SimpleName)83 InstanceofExpression (org.eclipse.jdt.core.dom.InstanceofExpression)76 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)73 Type (org.eclipse.jdt.core.dom.Type)70 ArrayList (java.util.ArrayList)69 Block (org.eclipse.jdt.core.dom.Block)63