use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaCleanUp method replaceByCreationReference.
private void replaceByCreationReference(final LambdaExpression node, final ClassInstanceCreation ci) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLambdaCleanUp_description);
TypeNameDecider typeNameDecider = new TypeNameDecider(ci);
CreationReference creationRef = ast.newCreationReference();
creationRef.setType(ast.toType(ci.resolveTypeBinding().getErasure(), typeNameDecider));
ASTNodes.replaceButKeepComment(rewrite, node, creationRef, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLazyLogicalRatherThanEagerCleanUp method replaceWithLazyOperator.
private void replaceWithLazyOperator(final InfixExpression node, final List<Expression> allOperands) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLazyLogicalRatherThanEagerCleanUp_description);
InfixExpression.Operator lazyOperator;
if (ASTNodes.hasOperator(node, InfixExpression.Operator.AND)) {
lazyOperator = InfixExpression.Operator.CONDITIONAL_AND;
} else {
lazyOperator = InfixExpression.Operator.CONDITIONAL_OR;
}
ASTNodes.replaceButKeepComment(rewrite, node, ast.newInfixExpression(lazyOperator, ASTNodes.createMoveTarget(rewrite, allOperands)), group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteSerializeRatherThanBoxingAndSerializeCleanUp 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.ObsoleteSerializeRatherThanBoxingAndSerializeCleanUp_description);
MethodInvocation toStringMethod = ast.newMethodInvocation();
toStringMethod.setExpression(ast.newSimpleName(wrapperClass.getSimpleName()));
// $NON-NLS-1$
toStringMethod.setName(ast.newSimpleName("toString"));
toStringMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(primitiveValue)));
ASTNodes.replaceButKeepComment(rewrite, visited, toStringMethod, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteSwitchCleanUp method addCaseWithStatements.
private void addCaseWithStatements(final SwitchStatement switchStatement, final List<Expression> caseValuesOrNullForDefault, final List<Statement> innerStatements) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
List<Statement> switchStatements = switchStatement.statements();
// Add the case statement(s)
if (caseValuesOrNullForDefault != null) {
for (Expression caseValue : caseValuesOrNullForDefault) {
switchStatements.add(ast.newSwitchCase(ASTNodes.createMoveTarget(rewrite, caseValue)));
}
} else {
switchStatements.add(ast.default0());
}
// Add the statement(s) for this case(s)
boolean isBreakNeeded = true;
if (!innerStatements.isEmpty()) {
for (Statement statement : innerStatements) {
switchStatements.add(ASTNodes.createMoveTarget(rewrite, statement));
}
isBreakNeeded = !ASTNodes.fallsThrough(innerStatements.get(innerStatements.size() - 1));
}
// When required: end with a break
if (isBreakNeeded) {
switchStatements.add(ast.newBreakStatement());
}
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteJava7HashRatherThanEclipseJava6HashCleanUp method refactorHash.
private void refactorHash(final MethodDeclaration node, final Set<String> classesToUseWithImport, final Set<String> importsToAdd, final CollectedData data) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteJava7HashRatherThanEclipseJava6HashCleanUp_description);
List<Statement> statements = node.getBody().statements();
String classname = addImport(Objects.class, classesToUseWithImport, importsToAdd);
Name objectsClassName = ASTNodeFactory.newName(ast, classname);
MethodInvocation hashMethod = ast.newMethodInvocation();
hashMethod.setExpression(objectsClassName);
// $NON-NLS-1$
hashMethod.setName(ast.newSimpleName("hash"));
hashMethod.arguments().addAll(ASTNodes.createMoveTarget(rewrite, data.getFields()));
ReturnStatement newReturnStatement = ast.newReturnStatement(hashMethod);
ASTNodes.replaceButKeepComment(rewrite, statements.get(0), newReturnStatement, group);
for (int i = 1; i < statements.size(); i++) {
rewrite.remove(statements.get(i), group);
}
}
Aggregations