use of org.autorefactor.jdt.internal.corext.dom.OrderedInfixExpression in project AutoRefactor by JnRouvignac.
the class ObsoleteJava7HashRatherThanEclipseJava6HashCleanUp method isObjectValid.
private boolean isObjectValid(final CollectedData data, final ConditionalExpression condition) {
OrderedInfixExpression<Expression, NullLiteral> orderedIsFieldNull = ASTNodes.orderedInfix(condition.getExpression(), Expression.class, NullLiteral.class);
if (orderedIsFieldNull != null && Arrays.asList(InfixExpression.Operator.EQUALS, InfixExpression.Operator.NOT_EQUALS).contains(orderedIsFieldNull.getOperator())) {
SimpleName field = getField(orderedIsFieldNull.getFirstOperand());
if (field != null) {
Long zero;
MethodInvocation hashOnField;
if (InfixExpression.Operator.EQUALS.equals(orderedIsFieldNull.getOperator())) {
zero = ASTNodes.getIntegerLiteral(condition.getThenExpression());
hashOnField = ASTNodes.as(condition.getElseExpression(), MethodInvocation.class);
} else {
hashOnField = ASTNodes.as(condition.getThenExpression(), MethodInvocation.class);
zero = ASTNodes.getIntegerLiteral(condition.getElseExpression());
}
if (Long.valueOf(0L).equals(zero) && hashOnField != null && hashOnField.getExpression() != null && HASH_CODE_METHOD.equals(hashOnField.getName().getIdentifier()) && Utils.isEmpty(hashOnField.arguments())) {
SimpleName fieldToHash = getField(hashOnField.getExpression());
if (fieldToHash != null && ASTNodes.isSameVariable(field, fieldToHash)) {
data.getFields().add(ASTNodes.getUnparenthesedExpression(fieldToHash));
return true;
}
}
}
}
return false;
}
use of org.autorefactor.jdt.internal.corext.dom.OrderedInfixExpression in project AutoRefactor by JnRouvignac.
the class IsEmptyRatherThanSizeCleanUp method visit.
@Override
public boolean visit(final InfixExpression visited) {
OrderedInfixExpression<MethodInvocation, Expression> orderedCondition = ASTNodes.orderedInfix(visited, MethodInvocation.class, Expression.class);
if (orderedCondition != null) {
MethodInvocation miToReplace = orderedCondition.getFirstOperand();
Long literalSize = ASTNodes.getIntegerLiteral(orderedCondition.getSecondOperand());
if (literalSize != null && miToReplace.getExpression() != null && !ASTNodes.is(miToReplace.getExpression(), ThisExpression.class) && (ASTNodes.usesGivenSignature(miToReplace, Collection.class.getCanonicalName(), SIZE_METHOD) || ASTNodes.usesGivenSignature(miToReplace, Map.class.getCanonicalName(), SIZE_METHOD) || ASTNodes.usesGivenSignature(miToReplace, String.class.getCanonicalName(), LENGTH_METHOD) && getJavaMinorVersion() >= 6)) {
if (Long.valueOf(0L).equals(literalSize)) {
if (Arrays.asList(InfixExpression.Operator.GREATER, InfixExpression.Operator.NOT_EQUALS).contains(orderedCondition.getOperator())) {
replaceMethod(visited, miToReplace, false);
return false;
}
if (Arrays.asList(InfixExpression.Operator.EQUALS, InfixExpression.Operator.LESS_EQUALS).contains(orderedCondition.getOperator())) {
replaceMethod(visited, miToReplace, true);
return false;
}
} else if (Long.valueOf(1L).equals(literalSize)) {
if (InfixExpression.Operator.GREATER_EQUALS.equals(orderedCondition.getOperator())) {
replaceMethod(visited, miToReplace, false);
return false;
}
if (InfixExpression.Operator.LESS.equals(orderedCondition.getOperator())) {
replaceMethod(visited, miToReplace, true);
return false;
}
}
}
}
return true;
}
use of org.autorefactor.jdt.internal.corext.dom.OrderedInfixExpression in project AutoRefactor by JnRouvignac.
the class UseStringContainsCleanUp method visit.
@Override
public boolean visit(final InfixExpression visited) {
OrderedInfixExpression<MethodInvocation, Expression> orderedExpression = ASTNodes.orderedInfix(visited, MethodInvocation.class, Expression.class);
if (orderedExpression != null) {
MethodInvocation indexOf = orderedExpression.getFirstOperand();
Long value = ASTNodes.getIntegerLiteral(orderedExpression.getSecondOperand());
if (value != null && (// $NON-NLS-1$
ASTNodes.usesGivenSignature(indexOf, String.class.getCanonicalName(), "indexOf", String.class.getCanonicalName()) || ASTNodes.usesGivenSignature(indexOf, String.class.getCanonicalName(), "lastIndexOf", String.class.getCanonicalName()))) {
if (is(orderedExpression.getOperator(), InfixExpression.Operator.GREATER_EQUALS, value, 0) || is(orderedExpression.getOperator(), InfixExpression.Operator.NOT_EQUALS, value, -1)) {
replaceWithStringContains(visited, indexOf, true);
return false;
}
if (is(orderedExpression.getOperator(), InfixExpression.Operator.LESS, value, 0) || is(orderedExpression.getOperator(), InfixExpression.Operator.EQUALS, value, -1)) {
replaceWithStringContains(visited, indexOf, false);
return false;
}
}
}
return true;
}
Aggregations