use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project AutoRefactor by JnRouvignac.
the class AbstractClassSubstituteRefactoring method replaceClass.
private void replaceClass(final ClassInstanceCreation originalInstanceCreation, final List<VariableDeclaration> variableDecls, final List<MethodInvocation> methodCallsToRefactorAlone, final List<MethodInvocation> methodCallsToRefactorWithVariable) {
final ASTBuilder b = ctx.getASTBuilder();
if (variableDecls.isEmpty() && methodCallsToRefactorAlone.isEmpty()) {
final ClassInstanceCreation newInstanceCreation = b.copySubtree(originalInstanceCreation);
refactorInstantiation(b, originalInstanceCreation, newInstanceCreation);
ctx.getRefactorings().replace(originalInstanceCreation, newInstanceCreation);
} else {
refactorInstantiation(b, originalInstanceCreation, originalInstanceCreation);
for (final MethodInvocation methodCall : methodCallsToRefactorAlone) {
final MethodInvocation copyOfMethodCall = b.copySubtree(methodCall);
refactorMethod(b, methodCall, copyOfMethodCall);
ctx.getRefactorings().replace(methodCall, copyOfMethodCall);
}
for (final MethodInvocation methodCall : methodCallsToRefactorWithVariable) {
refactorMethod(b, methodCall, methodCall);
}
for (final VariableDeclaration variableDecl : variableDecls) {
final VariableDeclarationStatement parent = (VariableDeclarationStatement) variableDecl.getParent();
final VariableDeclarationStatement newDeclareStmt = b.copySubtree(parent);
replaceVariableType(b, parent, newDeclareStmt);
ctx.getRefactorings().replace(parent, newDeclareStmt);
}
}
}
use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project AutoRefactor by JnRouvignac.
the class AbstractClassSubstituteRefactoring method visit.
@Override
public boolean visit(Block node) {
final ObjectInstantiationVisitor classCreationVisitor = new ObjectInstantiationVisitor();
node.accept(classCreationVisitor);
for (final ClassInstanceCreation instanceCreation : classCreationVisitor.getObjectInstantiations()) {
final List<VariableDeclaration> varDecls = new ArrayList<VariableDeclaration>();
final List<MethodInvocation> methodCallsToRefactorAlone = new ArrayList<MethodInvocation>();
final List<MethodInvocation> methodCallsToRefactorWithVariable = new ArrayList<MethodInvocation>();
if (canInstantiationBeRefactored(instanceCreation) && canBeRefactored(node, instanceCreation, varDecls, methodCallsToRefactorAlone, methodCallsToRefactorWithVariable) && canCodeBeRefactored()) {
replaceClass(instanceCreation, varDecls, methodCallsToRefactorAlone, methodCallsToRefactorWithVariable);
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
Aggregations