Search in sources :

Example 31 with ASTNodeFactory

use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.

the class IsEmptyRatherThanSizeCleanUp method replaceMethod.

private void replaceMethod(final InfixExpression visited, MethodInvocation miToReplace, boolean isEmpty) {
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    ASTNodeFactory ast = cuRewrite.getASTBuilder();
    TextEditGroup group = new TextEditGroup(MultiFixMessages.IsEmptyRatherThanSizeCleanUp_description);
    MethodInvocation newMethodInvocation = ast.newMethodInvocation();
    newMethodInvocation.setExpression(ast.copyExpression(miToReplace));
    newMethodInvocation.setName(ast.newSimpleName(IS_EMPTY_METHOD));
    rewrite.replace(visited, isEmpty ? newMethodInvocation : ast.not(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)

Example 32 with ASTNodeFactory

use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.

the class MatchingStreamRatherThanCountCleanUp method replaceMethod.

private void replaceMethod(final InfixExpression visited, final MethodInvocation filterMethod, final boolean hasElement) {
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    ASTNodeFactory ast = cuRewrite.getASTBuilder();
    TextEditGroup group = new TextEditGroup(MultiFixMessages.MatchingStreamRatherThanCountCleanUp_description);
    rewrite.replace(visited, filterMethod, group);
    rewrite.replace(filterMethod.getName(), ast.newSimpleName(hasElement ? ANYMATCH_METHOD : NONEMATCH_METHOD), 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 33 with ASTNodeFactory

use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.

the class NamedMethodRatherThanLogLevelParameterCleanUp method replaceLevelByMethodName.

private void replaceLevelByMethodName(final MethodInvocation visited, final String methodName) {
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    ASTNodeFactory ast = cuRewrite.getASTBuilder();
    TextEditGroup group = new TextEditGroup(MultiFixMessages.NamedMethodRatherThanLogLevelParameterCleanUp_description);
    rewrite.replace(visited.getName(), ast.newSimpleName(methodName), group);
    rewrite.remove((Expression) visited.arguments().get(0), 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 34 with ASTNodeFactory

use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.

the class NoLoopIterationRatherThanEmptyCheckCleanUp method removeCondition.

private void removeCondition(final InfixExpression condition, final List<Expression> operands) {
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    ASTNodeFactory ast = cuRewrite.getASTBuilder();
    TextEditGroup group = new TextEditGroup(MultiFixMessages.NoLoopIterationRatherThanEmptyCheckCleanUp_description);
    if (operands.size() == 2) {
        rewrite.replace(condition, ASTNodes.createMoveTarget(rewrite, operands.get(0)), group);
    } else {
        operands.remove(operands.size() - 1);
        InfixExpression newCondition = ast.newInfixExpression(condition.getOperator(), ASTNodes.createMoveTarget(rewrite, operands));
        rewrite.replace(condition, newCondition, group);
    }
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 35 with ASTNodeFactory

use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.

the class ObsoleteGenericMapRatherThanRawMapCleanUp method substituteType.

@Override
protected Type substituteType(final Type origType, final ASTNode originalExpression, final Set<String> classesToUseWithImport, final Set<String> importsToAdd) {
    ASTNodeFactory ast = cuRewrite.getASTBuilder();
    if (origType.isParameterizedType()) {
        return null;
    }
    TypeNameDecider typeNameDecider = new TypeNameDecider(originalExpression);
    ParameterizedType parameterizedType = ast.getAST().newParameterizedType(ast.createCopyTarget(origType));
    List<Type> typeArgs = parameterizedType.typeArguments();
    typeArgs.clear();
    typeArgs.add(ast.toType(keyType, typeNameDecider));
    typeArgs.add(ast.toType(valueType, typeNameDecider));
    return parameterizedType;
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) Type(org.eclipse.jdt.core.dom.Type) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) TypeNameDecider(org.autorefactor.jdt.internal.corext.dom.TypeNameDecider)

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