use of org.eclipse.jdt.core.dom.MethodInvocation in project eclipse-pmd by acanda.
the class MethodReturnsInternalArrayQuickFix method apply.
@Override
protected boolean apply(final ReturnStatement node) {
final Expression expression = node.getExpression();
final AST ast = expression.getAST();
final MethodInvocation replacement = create(ast, MethodInvocation.class);
replacement.setExpression(copy(expression));
final SimpleName name = create(ast, SimpleName.class);
name.setIdentifier("clone");
replacement.setName(name);
return replace(expression, replacement);
}
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;
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project eclipse-pmd by acanda.
the class ByteInstantiationValueOfQuickFix method apply.
/**
* Replaces the Byte instantiation with its argument, e.g. {@code new Byte(123 + x)} with
* {@code Byte.valueOf(123 + x)}.
*/
@Override
@SuppressWarnings("unchecked")
protected boolean apply(final ClassInstanceCreation node) {
final AST ast = node.getAST();
final MethodInvocation invocation = ast.newMethodInvocation();
invocation.setExpression(ast.newSimpleName("Byte"));
invocation.setName(ast.newSimpleName("valueOf"));
invocation.arguments().add(copy((Expression) node.arguments().get(0)));
replace(node, invocation);
return true;
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project eclipse-pmd by acanda.
the class LongInstantiationValueOfQuickFix method apply.
/**
* Replaces the Long instantiation with its argument, e.g. {@code new Long(123 + x)} with
* {@code Long.valueOf(123 + x)}.
*/
@Override
@SuppressWarnings("unchecked")
protected boolean apply(final ClassInstanceCreation node) {
final AST ast = node.getAST();
final MethodInvocation invocation = ast.newMethodInvocation();
invocation.setExpression(ast.newSimpleName("Long"));
invocation.setName(ast.newSimpleName("valueOf"));
invocation.arguments().add(copy((Expression) node.arguments().get(0)));
replace(node, invocation);
return true;
}
use of org.eclipse.jdt.core.dom.MethodInvocation in project eclipse-pmd by acanda.
the class ShortInstantiationValueOfQuickFix method apply.
/**
* Replaces the Short instantiation with its argument, e.g. {@code new Short(123 + x)} with
* {@code Short.valueOf(123 + x)}.
*/
@Override
@SuppressWarnings("unchecked")
protected boolean apply(final ClassInstanceCreation node) {
final AST ast = node.getAST();
final MethodInvocation invocation = ast.newMethodInvocation();
invocation.setExpression(ast.newSimpleName("Short"));
invocation.setName(ast.newSimpleName("valueOf"));
invocation.arguments().add(copy((Expression) node.arguments().get(0)));
replace(node, invocation);
return true;
}
Aggregations