use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class BigNumberCleanUp method getClassInstanceCreatorNode.
private ASTNode getClassInstanceCreatorNode(final Expression expression, final String numberLiteral) {
ASTNodeFactory ast = cuRewrite.getASTBuilder();
String fullyQualifiedName;
if (expression instanceof Name) {
fullyQualifiedName = ((Name) expression).getFullyQualifiedName();
} else if (expression instanceof FieldAccess) {
fullyQualifiedName = ((FieldAccess) expression).getName().getFullyQualifiedName();
} else {
throw new IllegalArgumentException();
}
return ast.newClassInstanceCreation(fullyQualifiedName, ast.newStringLiteral(numberLiteral));
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class BooleanConstantRatherThanValueOfCleanUp method replaceMethod.
private void replaceMethod(final MethodInvocation visited, final boolean literal) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.BooleanConstantRatherThanValueOfCleanUp_description);
FieldAccess fieldAccess = ast.getAST().newFieldAccess();
Name expression = ASTNodes.as(visited.getExpression(), Name.class);
if (expression != null) {
fieldAccess.setExpression(ASTNodes.createMoveTarget(rewrite, expression));
}
// $NON-NLS-1$ //$NON-NLS-2$
fieldAccess.setName(ast.newSimpleName(literal ? "TRUE" : "FALSE"));
rewrite.replace(visited, fieldAccess, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class CollectionsAddAllRatherThanAsListCleanUp method refactorMethod.
private void refactorMethod(final MethodInvocation visited, final MethodInvocation asListMethod, final Set<String> classesToUseWithImport, final Set<String> importsToAdd) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.CollectionsAddAllRatherThanAsListCleanUp_description);
String collectionsName = addImport(Collections.class, classesToUseWithImport, importsToAdd);
List<Expression> copyOfArguments = new ArrayList<>(asListMethod.arguments().size() + 1);
copyOfArguments.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(visited.getExpression())));
for (Object argument : asListMethod.arguments()) {
copyOfArguments.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression((Expression) argument)));
}
MethodInvocation newMethodInvocation = ast.newMethodInvocation();
newMethodInvocation.setExpression(ASTNodeFactory.newName(ast, collectionsName));
newMethodInvocation.setName(ast.newSimpleName(ADD_ALL_METHOD));
newMethodInvocation.arguments().addAll(copyOfArguments);
MethodInvocation newCollectionsAddAllMethod = newMethodInvocation;
rewrite.replace(visited, newCollectionsAddAllMethod, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory 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.internal.corext.dom.ASTNodeFactory 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);
}
Aggregations