use of org.eclipse.jdt.core.dom.PrefixExpression in project che by eclipse.
the class ConvertForLoopOperation method validateUpdaters.
/*
* Must be one of:
* <ul>
* <li>[indexBinding]++</li>
* <li>++[indexBinding]</li>
* <li>[indexBinding]+= 1</li>
* <li>[indexBinding]= [indexBinding] + 1</li>
* <li>[indexBinding]= 1 + [indexBinding]</li>
* <ul>
*/
private boolean validateUpdaters(ForStatement statement) {
List<Expression> updaters = statement.updaters();
if (updaters.size() != 1)
return false;
Expression updater = updaters.get(0);
if (updater instanceof PostfixExpression) {
PostfixExpression postfix = (PostfixExpression) updater;
if (!PostfixExpression.Operator.INCREMENT.equals(postfix.getOperator()))
return false;
IBinding binding = getBinding(postfix.getOperand());
if (!fIndexBinding.equals(binding))
return false;
return true;
} else if (updater instanceof PrefixExpression) {
PrefixExpression prefix = (PrefixExpression) updater;
if (!PrefixExpression.Operator.INCREMENT.equals(prefix.getOperator()))
return false;
IBinding binding = getBinding(prefix.getOperand());
if (!fIndexBinding.equals(binding))
return false;
return true;
} else if (updater instanceof Assignment) {
Assignment assignment = (Assignment) updater;
Expression left = assignment.getLeftHandSide();
IBinding binding = getBinding(left);
if (!fIndexBinding.equals(binding))
return false;
if (Assignment.Operator.PLUS_ASSIGN.equals(assignment.getOperator())) {
return isOneLiteral(assignment.getRightHandSide());
} else if (Assignment.Operator.ASSIGN.equals(assignment.getOperator())) {
Expression right = assignment.getRightHandSide();
if (!(right instanceof InfixExpression))
return false;
InfixExpression infixExpression = (InfixExpression) right;
Expression leftOperand = infixExpression.getLeftOperand();
IBinding leftBinding = getBinding(leftOperand);
Expression rightOperand = infixExpression.getRightOperand();
IBinding rightBinding = getBinding(rightOperand);
if (fIndexBinding.equals(leftBinding)) {
return isOneLiteral(rightOperand);
} else if (fIndexBinding.equals(rightBinding)) {
return isOneLiteral(leftOperand);
}
}
}
return false;
}
use of org.eclipse.jdt.core.dom.PrefixExpression in project AutoRefactor by JnRouvignac.
the class XORRatherThanDuplicateConditionsRefactoring method getBasisExpression.
private Expression getBasisExpression(final Expression originalExpr, final AtomicBoolean isExprPositive) {
Expression basisExpr = null;
final PrefixExpression negateExpr = as(originalExpr, PrefixExpression.class);
if (hasOperator(negateExpr, NOT)) {
basisExpr = negateExpr.getOperand();
isExprPositive.set(false);
} else {
basisExpr = originalExpr;
isExprPositive.set(true);
}
return basisExpr;
}
use of org.eclipse.jdt.core.dom.PrefixExpression in project AutoRefactor by JnRouvignac.
the class ORConditionRatherThanRedundantClausesRefactoring method getBasisExpression.
private Expression getBasisExpression(final Expression originalExpr, final AtomicBoolean isExprPositive) {
final Expression basisExpr;
final PrefixExpression negateExpr = as(originalExpr, PrefixExpression.class);
if (hasOperator(negateExpr, NOT)) {
basisExpr = negateExpr.getOperand();
isExprPositive.set(false);
} else {
basisExpr = originalExpr;
isExprPositive.set(true);
}
return basisExpr;
}
use of org.eclipse.jdt.core.dom.PrefixExpression in project AutoRefactor by JnRouvignac.
the class UpdateSetRatherThanTestingFirstRefactoring method visit.
@Override
public boolean visit(IfStatement node) {
final Statement elseStmt = node.getElseStatement();
final Statement thenStmt = node.getThenStatement();
final PrefixExpression pe = as(node.getExpression(), PrefixExpression.class);
if (hasOperator(pe, NOT)) {
return maybeReplaceSetContains(node, pe.getOperand(), thenStmt, elseStmt, false);
} else {
return maybeReplaceSetContains(node, node.getExpression(), elseStmt, thenStmt, true);
}
}
use of org.eclipse.jdt.core.dom.PrefixExpression in project AutoRefactor by JnRouvignac.
the class BigNumberRefactoring method visit.
@Override
public boolean visit(MethodInvocation node) {
if (node.getExpression() == null) {
return VISIT_SUBTREE;
}
if (getJavaMinorVersion() >= 5 && (isMethod(node, "java.math.BigInteger", "valueOf", "long") || isMethod(node, "java.math.BigDecimal", "valueOf", "long") || isMethod(node, "java.math.BigDecimal", "valueOf", "double"))) {
final ITypeBinding typeBinding = node.getExpression().resolveTypeBinding();
final Expression arg0 = arg0(node);
if (arg0 instanceof NumberLiteral) {
final String token = ((NumberLiteral) arg0).getToken().replaceFirst("[lLfFdD]$", "");
if (token.contains(".") && hasType(typeBinding, "java.math.BigDecimal")) {
this.ctx.getRefactorings().replace(node, getClassInstanceCreatorNode((Name) node.getExpression(), token));
} else if (ZERO_LONG_LITERAL_RE.matcher(token).matches()) {
replaceWithQualifiedName(node, typeBinding, "ZERO");
} else if (ONE_LONG_LITERAL_RE.matcher(token).matches()) {
replaceWithQualifiedName(node, typeBinding, "ONE");
} else if (TEN_LONG_LITERAL_RE.matcher(token).matches()) {
replaceWithQualifiedName(node, typeBinding, "TEN");
} else {
return VISIT_SUBTREE;
}
return DO_NOT_VISIT_SUBTREE;
}
} else if (!(node.getParent() instanceof PrefixExpression) || !hasOperator((PrefixExpression) node.getParent(), NOT)) {
return maybeReplaceEquals(true, node, node);
}
return VISIT_SUBTREE;
}
Aggregations