use of org.autorefactor.refactoring.ASTBuilder 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.ASTBuilder in project AutoRefactor by JnRouvignac.
the class SwitchRefactoring method addCaseWithStmts.
private void addCaseWithStmts(final SwitchStatement switchStmt, final List<Expression> caseValues, final List<Statement> innerStmts) {
final ASTBuilder b = ctx.getASTBuilder();
final List<Statement> switchStmts = statements(switchStmt);
// Add the case statement(s)
if (caseValues != null) {
for (final Expression caseValue : caseValues) {
switchStmts.add(b.case0(b.move(caseValue)));
}
} else {
switchStmts.add(b.default0());
}
// Add the statement(s) for this case(s)
boolean isBreakNeeded = true;
if (!innerStmts.isEmpty()) {
for (final Statement stmt : innerStmts) {
switchStmts.add(b.move(stmt));
}
isBreakNeeded = !isEndingWithJump(getLast(innerStmts));
}
// When required: end with a break;
if (isBreakNeeded) {
switchStmts.add(b.break0());
}
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class UnboxingRatherThanExplicitMethodRefactoring method useUnboxing.
private void useUnboxing(final MethodInvocation node) {
final ASTBuilder b = this.ctx.getASTBuilder();
this.ctx.getRefactorings().replace(node, b.copy(node.getExpression()));
}
use of org.autorefactor.refactoring.ASTBuilder in project AutoRefactor by JnRouvignac.
the class UseMultiCatchRefactoring method unionTypes.
private UnionType unionTypes(Type... types) {
final List<Type> allTypes = new ArrayList<Type>();
collectAllUnionedTypes(allTypes, Arrays.asList(types));
removeSupersededAlternatives(allTypes);
final ASTBuilder b = this.ctx.getASTBuilder();
final UnionType result = this.ctx.getAST().newUnionType();
final List<Type> unionedTypes = types(result);
for (Type unionedType : allTypes) {
unionedTypes.add(b.copy(unionedType));
}
return result;
}
Aggregations