Search in sources :

Example 76 with ASTBuilder

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);
}
Also used : SwitchCase(org.eclipse.jdt.core.dom.SwitchCase) DoStatement(org.eclipse.jdt.core.dom.DoStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) Statement(org.eclipse.jdt.core.dom.Statement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) BreakStatement(org.eclipse.jdt.core.dom.BreakStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) Refactorings(org.autorefactor.refactoring.Refactorings) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 77 with ASTBuilder

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());
    }
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) DoStatement(org.eclipse.jdt.core.dom.DoStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) Statement(org.eclipse.jdt.core.dom.Statement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) BreakStatement(org.eclipse.jdt.core.dom.BreakStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 78 with ASTBuilder

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()));
}
Also used : ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 79 with ASTBuilder

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;
}
Also used : UnionType(org.eclipse.jdt.core.dom.UnionType) Type(org.eclipse.jdt.core.dom.Type) UnionType(org.eclipse.jdt.core.dom.UnionType) ArrayList(java.util.ArrayList) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Aggregations

ASTBuilder (org.autorefactor.refactoring.ASTBuilder)79 Expression (org.eclipse.jdt.core.dom.Expression)25 Refactorings (org.autorefactor.refactoring.Refactorings)23 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)19 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)12 IfStatement (org.eclipse.jdt.core.dom.IfStatement)10 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)9 Statement (org.eclipse.jdt.core.dom.Statement)9 Type (org.eclipse.jdt.core.dom.Type)9 Block (org.eclipse.jdt.core.dom.Block)6 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)6 ArrayList (java.util.ArrayList)5 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)5 ASTHelper.hasType (org.autorefactor.refactoring.ASTHelper.hasType)4 NotImplementedException (org.autorefactor.util.NotImplementedException)4 ASTMatcher (org.eclipse.jdt.core.dom.ASTMatcher)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 EnhancedForStatement (org.eclipse.jdt.core.dom.EnhancedForStatement)4 ForStatement (org.eclipse.jdt.core.dom.ForStatement)4 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)4