use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoletePrimitiveComparisonRatherThanWrapperComparisonCleanUp 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.ObsoletePrimitiveComparisonRatherThanWrapperComparisonCleanUp_description);
MethodInvocation compareMethod = ast.newMethodInvocation();
compareMethod.setExpression(ast.newSimpleName(wrapperClass.getSimpleName()));
// $NON-NLS-1$
compareMethod.setName(ast.newSimpleName("compare"));
compareMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(primitiveValue)));
compareMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression((Expression) visited.arguments().get(0))));
ASTNodes.replaceButKeepComment(rewrite, visited, compareMethod, group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteReduceIndentationCleanUp method moveElseStatement.
private void moveElseStatement(final IfStatement visited) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteReduceIndentationCleanUp_description);
List<Statement> statementsToMove = ASTNodes.asList(visited.getElseStatement());
if (ASTNodes.canHaveSiblings(visited)) {
for (int i = statementsToMove.size() - 1; i >= 0; i--) {
rewrite.insertAfter(ASTNodes.createMoveTarget(rewrite, statementsToMove.get(i)), visited, group);
}
rewrite.remove(visited.getElseStatement(), group);
} else {
List<Statement> copyOfStatements = new ArrayList<>(statementsToMove.size() + 1);
for (Statement statement : statementsToMove) {
copyOfStatements.add(ASTNodes.createMoveTarget(rewrite, statement));
}
rewrite.remove(visited.getElseStatement(), group);
copyOfStatements.add(0, ASTNodes.createMoveTarget(rewrite, visited));
Block newBlock = ast.newBlock();
newBlock.statements().addAll(copyOfStatements);
ASTNodes.replaceButKeepComment(rewrite, visited, newBlock, group);
}
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteRedundantModifiersCleanUp method removeFinalModifier.
private boolean removeFinalModifier(final List<IExtendedModifier> modifiers) {
boolean result = true;
for (Modifier modifier : getModifiersOnly(modifiers)) {
if (modifier.isFinal()) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(modifier, group);
result = false;
}
}
return result;
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteRedundantModifiersCleanUp method removeProtectedModifier.
private boolean removeProtectedModifier(final BodyDeclaration visited) {
List<IExtendedModifier> modifiers = visited.modifiers();
for (Modifier modifier : getModifiersOnly(modifiers)) {
if (modifier.isProtected()) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(modifier, group);
return false;
}
}
return true;
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteRemoveEmptySuperConstrInvocationCleanUp method visit.
@Override
public boolean visit(final SuperConstructorInvocation node) {
if (node.arguments().isEmpty()) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRemoveEmptySuperConstrInvocationCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodes.removeButKeepComment(rewrite, node, group);
return false;
}
return true;
}
Aggregations