use of org.autorefactor.refactoring.Refactorings in project AutoRefactor by JnRouvignac.
the class SwitchRefactoring method mergeCases.
private void mergeCases(Merge merge, SwitchCaseSection sectionToKeep, SwitchCaseSection sectionToRemove) {
final ASTBuilder b = this.ctx.getASTBuilder();
final Refactorings r = this.ctx.getRefactorings();
final Statement caseKept;
if (merge == Merge.BEFORE_SWITCH_CASES) {
caseKept = sectionToKeep.existingCases.get(0);
} else {
// move == Move.AFTER_SWITCH_CASES
caseKept = sectionToKeep.stmts.get(0);
}
for (final SwitchCase caseToMove : sectionToRemove.existingCases) {
r.insertBefore(b.move(caseToMove), caseKept);
}
r.remove(sectionToRemove.stmts);
}
use of org.autorefactor.refactoring.Refactorings in project AutoRefactor by JnRouvignac.
the class UseMultiCatchRefactoring method visit.
@Override
public boolean visit(TryStatement node) {
List<CatchClause> catchClauses = catchClauses(node);
Binding[] typeBindings = resolveTypeBindings(catchClauses);
for (int i = 0; i < catchClauses.size(); i++) {
CatchClause catchClause1 = catchClauses.get(i);
for (int j = i + 1; j < catchClauses.size(); j++) {
CatchClause catchClause2 = catchClauses.get(j);
MergeDirection direction = mergeDirection(typeBindings, i, j);
if (!MergeDirection.NONE.equals(direction) && matchMultiCatch(catchClause1, catchClause2)) {
Refactorings r = this.ctx.getRefactorings();
UnionType ut = unionTypes(catchClause1.getException().getType(), catchClause2.getException().getType());
if (MergeDirection.UP.equals(direction)) {
r.set(catchClause1.getException(), SingleVariableDeclaration.TYPE_PROPERTY, ut);
r.remove(catchClause2);
} else if (MergeDirection.DOWN.equals(direction)) {
r.remove(catchClause1);
r.set(catchClause2.getException(), SingleVariableDeclaration.TYPE_PROPERTY, ut);
}
return DO_NOT_VISIT_SUBTREE;
}
}
}
return VISIT_SUBTREE;
}
Aggregations