use of org.eclipse.jdt.core.dom.MethodInvocation in project AutoRefactor by JnRouvignac.
the class ObsoleteValueOfRatherThanInstantiationCleanUp method replaceFloatWithFloatValue.
private void replaceFloatWithFloatValue(final ClassInstanceCreation visited, final Expression arg0) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteValueOfRatherThanInstantiationCleanUp_description);
MethodInvocation floatValueMethod = ast.newMethodInvocation();
floatValueMethod.setExpression(ASTNodes.createMoveTarget(rewrite, arg0));
// $NON-NLS-1$
floatValueMethod.setName(ast.newSimpleName("floatValue"));
ASTNodes.replaceButKeepComment(rewrite, visited, floatValueMethod, group);
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project AutoRefactor by JnRouvignac.
the class OppositeComparisonRatherThanNegativeExpressionCleanUp method visit.
@Override
public boolean visit(final PrefixExpression visited) {
if (ASTNodes.hasOperator(visited, PrefixExpression.Operator.MINUS)) {
MethodInvocation methodInvocation = ASTNodes.as(visited.getOperand(), MethodInvocation.class);
if (methodInvocation != null && methodInvocation.getExpression() != null && methodInvocation.arguments().size() == 1) {
Expression argument = (Expression) methodInvocation.arguments().get(0);
String[] classes = { Double.class.getCanonicalName(), Float.class.getCanonicalName(), Short.class.getCanonicalName(), Integer.class.getCanonicalName(), Long.class.getCanonicalName(), Character.class.getCanonicalName(), Byte.class.getCanonicalName(), Boolean.class.getCanonicalName() };
for (String klass : classes) {
if (ASTNodes.usesGivenSignature(methodInvocation, klass, "compareTo", klass)) {
// $NON-NLS-1$
if (ASTNodes.hasType(argument, klass)) {
reverseObjects(visited, methodInvocation);
return false;
}
return true;
}
}
}
}
return true;
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project AutoRefactor by JnRouvignac.
the class ObsoleteJava7HashRatherThanEclipseJava6HashCleanUp method isDoubleToLongBitsMethod.
private SimpleName isDoubleToLongBitsMethod(final CollectedData data, final Expression initializer) {
SimpleName fieldToFind = null;
MethodInvocation doubleToLongBits = ASTNodes.as(initializer, MethodInvocation.class);
if (doubleToLongBits != null && ASTNodes.usesGivenSignature(doubleToLongBits, Double.class.getCanonicalName(), "doubleToLongBits", double.class.getSimpleName())) {
// $NON-NLS-1$
SimpleName fieldName = ASTNodes.as((Expression) doubleToLongBits.arguments().get(0), SimpleName.class);
if (fieldName != null && !ASTNodes.isSameVariable(fieldName, data.getPrimeId()) && !ASTNodes.isSameVariable(fieldName, data.getResultId())) {
fieldToFind = fieldName;
}
}
return fieldToFind;
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project AutoRefactor by JnRouvignac.
the class ObsoleteSerializeRatherThanBoxingAndSerializeCleanUp method refactor.
private void refactor(final MethodInvocation visited, final Expression primitiveValue, final Class<?> wrapperClass) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteSerializeRatherThanBoxingAndSerializeCleanUp_description);
MethodInvocation toStringMethod = ast.newMethodInvocation();
toStringMethod.setExpression(ast.newSimpleName(wrapperClass.getSimpleName()));
// $NON-NLS-1$
toStringMethod.setName(ast.newSimpleName("toString"));
toStringMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(primitiveValue)));
ASTNodes.replaceButKeepComment(rewrite, visited, toStringMethod, group);
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project eclipse-pmd by acanda.
the class UseCollectionIsEmptyQuickFix method apply.
/**
* Replaces {@code x.size() == 0} or {@code 0 == x.size()} with {@code x.isEmpty()}. Replaces {@code x.size() != 0}
* or {@code 0 != x.size()} with {@code !x.isEmpty()}.
*/
@Override
protected boolean apply(final InfixExpression node) {
final MethodInvocation size;
if (node.getLeftOperand() instanceof MethodInvocation) {
size = (MethodInvocation) node.getLeftOperand();
} else if (node.getRightOperand() instanceof MethodInvocation) {
size = (MethodInvocation) node.getRightOperand();
} else {
return false;
}
final AST ast = node.getAST();
final MethodInvocation invocation = (MethodInvocation) ast.createInstance(MethodInvocation.class);
invocation.setExpression(ASTUtil.copy(size.getExpression()));
final SimpleName isEmpty = (SimpleName) ast.createInstance(SimpleName.class);
isEmpty.setIdentifier("isEmpty");
invocation.setName(isEmpty);
final Expression replacement;
if (isNotEmpty(node)) {
final PrefixExpression not = (PrefixExpression) ast.createInstance(PrefixExpression.class);
not.setOperator(org.eclipse.jdt.core.dom.PrefixExpression.Operator.NOT);
not.setOperand(invocation);
replacement = not;
} else {
replacement = invocation;
}
ASTUtil.replace(node, replacement);
return true;
}
Aggregations