use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteAddAllRatherThanLoopCleanUp method replaceWithCollectionsAddAll.
private void replaceWithCollectionsAddAll(final Statement node, final Set<String> classesToUseWithImport, final Set<String> importsToAdd, final Expression iterable, final MethodInvocation addMethod) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteAddAllRatherThanLoopCleanUp_description);
String classname = addImport(Collections.class, classesToUseWithImport, importsToAdd);
MethodInvocation addAllMethod = ast.newMethodInvocation();
addAllMethod.setExpression(ASTNodeFactory.newName(ast, classname));
// $NON-NLS-1$
addAllMethod.setName(ast.newSimpleName("addAll"));
addAllMethod.arguments().add(addMethod.getExpression() != null ? ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(addMethod.getExpression())) : ast.newThisExpression());
addAllMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(iterable)));
ASTNodes.replaceButKeepComment(rewrite, node, ast.newExpressionStatement(addAllMethod), group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteCharacterParameterRatherThanStringCleanUp method refactorWithCharacter.
private void refactorWithCharacter(final StringLiteral stringLiteral, final String value) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteCharacterParameterRatherThanStringCleanUp_description);
CharacterLiteral replacement = ast.newCharacterLiteral();
replacement.setCharValue(value.charAt(0));
rewrite.replace(stringLiteral, replacement, group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteCommonCodeInIfElseStatementCleanUp method insertIdenticalCode.
private void insertIdenticalCode(final IfStatement node, final List<Statement> stmtsToRemove) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteCommonCodeInIfElseStatementCleanUp_description);
for (Statement stmtToRemove : stmtsToRemove) {
rewrite.insertAfter(ASTNodes.createMoveTarget(rewrite, stmtToRemove), node, group);
}
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class EqualsIgnoreCaseRatherThanCaseShiftCleanUp method refactorEqualsIgnoreCase.
private void refactorEqualsIgnoreCase(final MethodInvocation visited, final Expression leftExpressionIfChanged, final Expression rightExpressionIfChanged) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.EqualsIgnoreCaseRatherThanCaseShiftCleanUp_description);
if (leftExpressionIfChanged != null) {
rewrite.replace(visited.getExpression(), ASTNodes.createMoveTarget(rewrite, leftExpressionIfChanged), group);
}
if (rightExpressionIfChanged != null) {
rewrite.replace((Expression) visited.arguments().get(0), ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(rightExpressionIfChanged)), group);
}
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class EqualsIgnoreCaseRatherThanCaseShiftCleanUp method refactorEquals.
private void refactorEquals(final MethodInvocation visited, final MethodInvocation leftInvocation, final MethodInvocation rightInvocation) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.EqualsIgnoreCaseRatherThanCaseShiftCleanUp_description);
rewrite.replace(leftInvocation, ASTNodes.createMoveTarget(rewrite, leftInvocation.getExpression()), group);
// $NON-NLS-1$
rewrite.replace(visited.getName(), ast.newSimpleName("equalsIgnoreCase"), group);
rewrite.replace(rightInvocation, ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(rightInvocation.getExpression())), group);
}
Aggregations