use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class EqualsIgnoreCaseRatherThanCaseShiftCleanUp method refactorEquals.
private void refactorEquals(final MethodInvocation visited, final MethodInvocation leftInvocation, final MethodInvocation rightInvocation) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.EqualsIgnoreCaseRatherThanCaseShiftCleanUp_description);
rewrite.replace(leftInvocation, ASTNodes.createMoveTarget(rewrite, leftInvocation.getExpression()), group);
// $NON-NLS-1$
rewrite.replace(visited.getName(), ast.newSimpleName("equalsIgnoreCase"), group);
rewrite.replace(rightInvocation, ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(rightInvocation.getExpression())), group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class FormattedNumberRatherThanPackedNumberCleanUp method refactorNumber.
private void refactorNumber(final NumberLiteral visited, final String token) {
// $NON-NLS-1$ //$NON-NLS-2$
StringBuilder integers = new StringBuilder(token.replaceFirst("^(\\d{4,})[lLdDfF]?$", "$1"));
// $NON-NLS-1$ //$NON-NLS-2$
String suffix = token.replaceFirst("^\\d{4,}([lLdDfF]?)$", "$1");
int position = integers.length() - 3;
while (position > 0) {
integers.insert(position, '_');
position = position - 3;
}
ASTNodeFactory ast = cuRewrite.getASTBuilder();
NumberLiteral replacement = ast.newNumberLiteral(integers + suffix);
TextEditGroup group = new TextEditGroup(MultiFixMessages.FormattedNumberRatherThanPackedNumberCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.replace(visited, replacement, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class HashMapRatherThanHashtableCleanUp method refactorMethod.
@Override
protected void refactorMethod(final MethodInvocation originalMi, final MethodInvocation refactoredMi) {
ASTNodeFactory ast = cuRewrite.getASTBuilder();
// $NON-NLS-1$
refactoredMi.setName(ast.newSimpleName("containsValue"));
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class InlineCodeRatherThanPeremptoryConditionCleanUp method remove.
private void remove(final Statement visited) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = new TextEditGroup(MultiFixMessages.InlineCodeRatherThanPeremptoryConditionCleanUp_description);
if (ASTNodes.canHaveSiblings(visited) || visited.getLocationInParent() == IfStatement.ELSE_STATEMENT_PROPERTY) {
rewrite.remove(visited, group);
} else {
ASTNodeFactory ast = cuRewrite.getASTBuilder();
ASTNodes.replaceButKeepComment(rewrite, visited, ast.newBlock(), group);
}
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class LogParametersRatherThanLogMessageCleanUp method replaceConcatenation.
private void replaceConcatenation(final MethodInvocation visited, final String methodName, final StringBuilder messageBuilder, final List<Expression> params) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.LogParametersRatherThanLogMessageCleanUp_description);
params.add(0, ast.newStringLiteral(messageBuilder.toString()));
MethodInvocation newMethodInvocation = ast.newMethodInvocation();
newMethodInvocation.setExpression(ASTNodes.createMoveTarget(rewrite, visited.getExpression()));
newMethodInvocation.setName(ast.newSimpleName(methodName));
newMethodInvocation.arguments().addAll(params);
rewrite.replace(visited, newMethodInvocation, group);
}
Aggregations