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);
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations