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));
}
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)));
}
}
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;
}
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);
}
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);
}
}
Aggregations