Search in sources :

Example 51 with ASTNodeFactory

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);
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 52 with ASTNodeFactory

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);
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup) NumberLiteral(org.eclipse.jdt.core.dom.NumberLiteral)

Example 53 with ASTNodeFactory

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"));
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory)

Example 54 with ASTNodeFactory

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);
    }
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 55 with ASTNodeFactory

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);
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Aggregations

ASTNodeFactory (org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory)152 ASTRewrite (org.autorefactor.jdt.core.dom.ASTRewrite)133 TextEditGroup (org.eclipse.text.edits.TextEditGroup)115 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)47 Expression (org.eclipse.jdt.core.dom.Expression)44 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)37 ArrayList (java.util.ArrayList)19 Block (org.eclipse.jdt.core.dom.Block)17 Statement (org.eclipse.jdt.core.dom.Statement)17 IfStatement (org.eclipse.jdt.core.dom.IfStatement)16 Type (org.eclipse.jdt.core.dom.Type)14 TypeNameDecider (org.autorefactor.jdt.internal.corext.dom.TypeNameDecider)11 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)10 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)10 List (java.util.List)8 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)8 Name (org.eclipse.jdt.core.dom.Name)7 ASTNode (org.eclipse.jdt.core.dom.ASTNode)6 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)6 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)6