use of org.autorefactor.jdt.core.dom.ASTRewrite 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.core.dom.ASTRewrite 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.core.dom.ASTRewrite 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);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class BooleanConstantRatherThanValueOfCleanUp method replaceMethod.
private void replaceMethod(final MethodInvocation visited, final boolean literal) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.BooleanConstantRatherThanValueOfCleanUp_description);
FieldAccess fieldAccess = ast.getAST().newFieldAccess();
Name expression = ASTNodes.as(visited.getExpression(), Name.class);
if (expression != null) {
fieldAccess.setExpression(ASTNodes.createMoveTarget(rewrite, expression));
}
// $NON-NLS-1$ //$NON-NLS-2$
fieldAccess.setName(ast.newSimpleName(literal ? "TRUE" : "FALSE"));
rewrite.replace(visited, fieldAccess, group);
}
use of org.autorefactor.jdt.core.dom.ASTRewrite in project AutoRefactor by JnRouvignac.
the class CollectionsAddAllRatherThanAsListCleanUp method refactorMethod.
private void refactorMethod(final MethodInvocation visited, final MethodInvocation asListMethod, final Set<String> classesToUseWithImport, final Set<String> importsToAdd) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.CollectionsAddAllRatherThanAsListCleanUp_description);
String collectionsName = addImport(Collections.class, classesToUseWithImport, importsToAdd);
List<Expression> copyOfArguments = new ArrayList<>(asListMethod.arguments().size() + 1);
copyOfArguments.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(visited.getExpression())));
for (Object argument : asListMethod.arguments()) {
copyOfArguments.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression((Expression) argument)));
}
MethodInvocation newMethodInvocation = ast.newMethodInvocation();
newMethodInvocation.setExpression(ASTNodeFactory.newName(ast, collectionsName));
newMethodInvocation.setName(ast.newSimpleName(ADD_ALL_METHOD));
newMethodInvocation.arguments().addAll(copyOfArguments);
MethodInvocation newCollectionsAddAllMethod = newMethodInvocation;
rewrite.replace(visited, newCollectionsAddAllMethod, group);
}
Aggregations