use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteFillRatherThanLoopCleanUp method replaceWithArraysFill.
private void replaceWithArraysFill(final ForStatement node, final Set<String> classesToUseWithImport, final Set<String> importsToAdd, final Assignment assignment, final ArrayAccess arrayAccess) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteFillRatherThanLoopCleanUp_description);
String classname = addImport(Arrays.class, classesToUseWithImport, importsToAdd);
MethodInvocation fillMethod = ast.newMethodInvocation();
fillMethod.setExpression(ASTNodeFactory.newName(ast, classname));
// $NON-NLS-1$
fillMethod.setName(ast.newSimpleName("fill"));
fillMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(arrayAccess.getArray())));
fillMethod.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(assignment.getRightHandSide())));
ASTNodes.replaceButKeepComment(rewrite, node, ast.newExpressionStatement(fillMethod), group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteGenericListRatherThanRawListCleanUp 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));
parameterizedType.typeArguments().clear();
parameterizedType.typeArguments().add(ast.toType(elementType, typeNameDecider));
return parameterizedType;
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class AssertJCleanUp method invokeMethod.
@Override
protected MethodInvocation invokeMethod(final Set<String> classesToUseWithImport, final Set<String> importsToAdd, final MethodInvocation originalMethod, final String methodName, final Expression copyOfActual, final Expression copyOfExpected, final Expression delta, final Expression failureMessage) {
ASTNodeFactory ast = cuRewrite.getASTBuilder();
String qualifiedClassName = originalMethod.resolveMethodBinding().getDeclaringClass().getQualifiedName();
Expression qualifiedClass;
if (!FAIL_METHOD.equals(methodName) && FAIL_CLASS.equals(qualifiedClassName)) {
qualifiedClassName = ASSERTIONS_CLASS;
qualifiedClass = null;
} else if (originalMethod.getExpression() != null) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
qualifiedClass = ASTNodes.createMoveTarget(rewrite, originalMethod.getExpression());
} else {
qualifiedClass = null;
}
if (// $NON-NLS-1$
originalMethod.getExpression() == null && !staticImports.contains(qualifiedClassName + "." + methodName) && !staticImports.contains(qualifiedClassName + ".*")) {
// $NON-NLS-1$
qualifiedClass = ASTNodeFactory.newName(ast, qualifiedClassName);
}
if (FAIL_METHOD.equals(methodName)) {
return invokeFail(failureMessage, qualifiedClass);
}
return invokeQualifiedMethod(classesToUseWithImport, importsToAdd, qualifiedClass, methodName, copyOfActual, copyOfExpected, delta, failureMessage);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class AssertJCleanUp method invokeFail.
private MethodInvocation invokeFail(final Expression failureMessage, final Expression qualifiedClass) {
ASTNodeFactory ast = cuRewrite.getASTBuilder();
if (failureMessage != null) {
MethodInvocation failureMethod = (MethodInvocation) failureMessage;
List<Expression> copyOfMessages = new ArrayList<>(failureMethod.arguments().size());
for (Object message : failureMethod.arguments()) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
copyOfMessages.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression((Expression) message)));
}
MethodInvocation newMethodInvocation = ast.newMethodInvocation();
newMethodInvocation.setExpression(qualifiedClass);
newMethodInvocation.setName(ast.newSimpleName(FAIL_METHOD));
newMethodInvocation.arguments().addAll(copyOfMessages);
return newMethodInvocation;
}
MethodInvocation methodInvocation = ast.newMethodInvocation();
methodInvocation.setExpression(qualifiedClass);
methodInvocation.setName(ast.newSimpleName(FAIL_METHOD));
methodInvocation.arguments().add(ast.newNullLiteral());
return methodInvocation;
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class BigNumberCleanUp method replaceWithQualifiedName.
private void replaceWithQualifiedName(final ASTNode visited, final ITypeBinding typeBinding, final String field) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.BigNumberCleanUp_description);
ASTNodes.replaceButKeepComment(rewrite, visited, ASTNodeFactory.newName(ast, typeBinding.getName(), field), group);
}
Aggregations