use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory 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.internal.corext.dom.ASTNodeFactory 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.internal.corext.dom.ASTNodeFactory 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.internal.corext.dom.ASTNodeFactory 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.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaCleanUp method replaceByTypeReference.
private void replaceByTypeReference(final LambdaExpression node, final MethodInvocation methodInvocation) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLambdaCleanUp_description);
TypeNameDecider typeNameDecider = new TypeNameDecider(methodInvocation);
TypeMethodReference typeMethodRef = ast.newTypeMethodReference();
typeMethodRef.setType(ast.toType(ASTNodes.getCalledType(methodInvocation).getErasure(), typeNameDecider));
typeMethodRef.setName(ASTNodes.createMoveTarget(rewrite, methodInvocation.getName()));
ASTNodes.replaceButKeepComment(rewrite, node, typeMethodRef, group);
}
Aggregations