use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class BooleanEqualsRatherThanNullCheckCleanUp method replaceNullCheck.
private void replaceNullCheck(final InfixExpression visited, final Expression firstExpression, final boolean isNullCheck, final boolean isAndExpression, final boolean isPositiveExpression) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.BooleanEqualsRatherThanNullCheckCleanUp_description);
// $NON-NLS-1$ //$NON-NLS-2$
Name booleanConstant = ASTNodeFactory.newName(ast, Boolean.class.getSimpleName(), isAndExpression == isPositiveExpression ? "TRUE" : "FALSE");
MethodInvocation equalsMethod = ast.newMethodInvocation();
equalsMethod.setExpression(booleanConstant);
// $NON-NLS-1$
equalsMethod.setName(ast.newSimpleName("equals"));
equalsMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(firstExpression)));
Expression newExpression;
if (!isNullCheck || isAndExpression) {
newExpression = equalsMethod;
} else {
newExpression = ast.not(equalsMethod);
}
rewrite.replace(visited, newExpression, group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class CommentsCleanUp method visit.
@Override
public boolean visit(final LineComment visited) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.CommentsCleanUp_description);
String comment = getComment(visited);
if (EMPTY_LINE_COMMENT.matcher(comment).matches() || ECLIPSE_GENERATED_TODOS.matcher(comment).matches()) {
rewrite.remove(visited, group);
return false;
}
if (!TOOLS_CONTROL_INSTRUCTIONS.matcher(comment).matches() && !ECLIPSE_IGNORE_NON_EXTERNALIZED_STRINGS.matcher(comment).matches()) {
ASTNode nextNode = getNextNode(visited);
ASTNode previousNode = getPreviousSibling(nextNode);
if (previousNode != null && isSameLineNumber(visited, previousNode)) {
rewrite.toJavadoc(visited, previousNode);
return false;
}
if (acceptJavadoc(nextNode) && !betterCommentExist(visited, nextNode)) {
rewrite.toJavadoc(visited, nextNode);
return false;
}
}
return true;
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class CommentsCleanUp method visit.
@Override
public boolean visit(final BlockComment visited) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.CommentsCleanUp_description);
String comment = getComment(visited);
if (EMPTY_BLOCK_COMMENT.matcher(comment).matches()) {
rewrite.remove(visited, group);
return false;
}
ASTNode nextNode = getNextNode(visited);
if (acceptJavadoc(nextNode) && !betterCommentExist(visited, nextNode)) {
if (ECLIPSE_GENERATED_NON_JAVADOC.matcher(comment).find()) {
rewrite.remove(visited, group);
} else {
rewrite.toJavadoc(visited);
}
return false;
}
Matcher emptyLineAtStartMatcher = EMPTY_LINE_AT_START_OF_BLOCK_COMMENT.matcher(comment);
if (emptyLineAtStartMatcher.find()) {
replaceEmptyLineAtStartOfComment(visited, emptyLineAtStartMatcher);
return false;
}
Matcher emptyLineAtEndMatcher = EMPTY_LINE_AT_END_OF_BLOCK_COMMENT.matcher(comment);
if (emptyLineAtEndMatcher.find()) {
replaceEmptyLineAtEndOfComment(visited, emptyLineAtEndMatcher);
return false;
}
String replacement = getReplacement(comment, false);
if (replacement != null && !replacement.equals(comment)) {
rewrite.replace(visited, replacement);
return false;
}
return true;
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ContainsAllRatherThanLoopCleanUp method newMethod.
@Override
protected Expression newMethod(final Expression iterable, final Expression toFind, final boolean isPositive, final Set<String> classesToUseWithImport, final Set<String> importsToAdd) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
MethodInvocation invoke = ast.newMethodInvocation();
invoke.setExpression(ASTNodes.createMoveTarget(rewrite, toFind));
// $NON-NLS-1$
invoke.setName(ast.newSimpleName("containsAll"));
invoke.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(iterable)));
if (isPositive) {
return ast.not(invoke);
}
return invoke;
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class DoWhileRatherThanDuplicateCodeCleanUp method replaceWithDoWhile.
private void replaceWithDoWhile(final WhileStatement visited, final List<Statement> previousStatements) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.DoWhileRatherThanDuplicateCodeCleanUp_description);
rewrite.remove(previousStatements, group);
ASTNodeFactory ast = cuRewrite.getASTBuilder();
ASTNodes.replaceButKeepComment(rewrite, visited, ast.newDoStatement(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(visited.getExpression())), ASTNodes.createMoveTarget(rewrite, visited.getBody())), group);
}
Aggregations