use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteUseDiamondOperatorCleanUp method visit.
@Override
public boolean visit(final ClassInstanceCreation node) {
Type type = node.getType();
if (type.isParameterizedType() && node.getAnonymousClassDeclaration() == null && ASTNodes.getTargetType(node) != null && canUseDiamondOperator(node, type)) {
List<Type> typeArguments = ((ParameterizedType) type).typeArguments();
if (!typeArguments.isEmpty()) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteUseDiamondOperatorCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(typeArguments, group);
return false;
}
}
return true;
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteValueOfRatherThanInstantiationCleanUp method replaceWithTheSingleArgument.
private void replaceWithTheSingleArgument(final ClassInstanceCreation visited) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteValueOfRatherThanInstantiationCleanUp_description);
ASTNodes.replaceButKeepComment(rewrite, visited, ASTNodes.createMoveTarget(rewrite, (Expression) visited.arguments().get(0)), group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class ObsoleteValueOfRatherThanInstantiationCleanUp method replaceWithValueOf.
private void replaceWithValueOf(final ClassInstanceCreation visited, final ITypeBinding typeBinding, final Expression arg0) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteValueOfRatherThanInstantiationCleanUp_description);
MethodInvocation valueOfMethod = ast.newMethodInvocation();
valueOfMethod.setExpression(ASTNodeFactory.newName(ast, typeBinding.getName()));
// $NON-NLS-1$
valueOfMethod.setName(ast.newSimpleName("valueOf"));
valueOfMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(arg0)));
ASTNodes.replaceButKeepComment(rewrite, visited, valueOfMethod, group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite 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.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class RemoveEmptyLinesCleanUp method maybeRemoveEmptyLines.
private boolean maybeRemoveEmptyLines(final String source, final int endOfLineIndex, final int newLineIndex) {
if (endOfLineIndex < newLineIndex) {
Matcher matcher = NEWLINE_PATTERN.matcher(source).region(endOfLineIndex, newLineIndex);
boolean isEqualToNewline = matcher.matches();
if (!isEqualToNewline && matcher.find() && matcher.end() < newLineIndex) {
SourceLocation toRemove = SourceLocation.fromPositions(matcher.end(), newLineIndex);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(toRemove);
return true;
}
}
return false;
}
Aggregations