use of org.eclipse.jdt.core.dom.Statement 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.eclipse.jdt.core.dom.Statement in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the passed in statement.
*
* @param node the statement for which to build a CFG
* @param state the liveness state before the current statement.
* It contains: the live edges before the current statement,
* the live basic block to which the current statement might be added.
* If null, then the new basic block must be created for the current statement.
* @param throwers the thrower blocks information
* @return the new live state after the current statement
*/
public LivenessState buildCFG(IfStatement node, LivenessState state, ThrowerBlocks throwers) {
final CFGBasicBlock exprBlock = getCFGBasicBlock(node, state.nextStmtWillCreateNewBlock(), true);
try {
addVariableAccess(exprBlock, node.getExpression(), READ, throwers);
final LivenessState result = new LivenessState();
CFGEdgeBuilder thenEdge = new CFGEdgeBuilder(node.getExpression(), true, exprBlock);
result.addAll(buildCFG(node.getThenStatement(), LivenessState.of(thenEdge), throwers));
final Statement elseStmt = node.getElseStatement();
CFGEdgeBuilder elseEdge = new CFGEdgeBuilder(node.getExpression(), false, exprBlock);
if (elseStmt != null) {
result.addAll(buildCFG(elseStmt, LivenessState.of(elseEdge), throwers));
} else {
result.add(elseEdge);
}
return result.nextStmtWillCreateNewBlock();
} finally {
moveAllEdgesToBuild(node, state);
}
}
use of org.eclipse.jdt.core.dom.Statement in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param state the blocks liveness state before current node
* @param throwers the thrower blocks information
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(ContinueStatement node, LivenessState state, ThrowerBlocks throwers) {
final CFGBasicBlock basicBlock = getCFGBasicBlock(node, state);
final Statement targetStmt;
if (node.getLabel() != null) {
targetStmt = findLabeledParentStmt(node);
} else {
targetStmt = findContinuableParentStmt(node);
}
addEdgeToBuild(targetStmt, new CFGEdgeBuilder(basicBlock), false);
return state.copyLiveBasicBlock();
}
use of org.eclipse.jdt.core.dom.Statement in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param state the blocks liveness state before current node
* @param throwers the thrower blocks information
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(BreakStatement node, LivenessState state, ThrowerBlocks throwers) {
final CFGBasicBlock basicBlock = getCFGBasicBlock(node, state);
final Statement targetStmt;
if (node.getLabel() != null) {
targetStmt = findLabeledParentStmt(node);
} else {
targetStmt = findBreakableParentStmt(node);
}
addEdgeToBuild(targetStmt, new CFGEdgeBuilder(basicBlock), true);
return state.copyLiveBasicBlock();
}
use of org.eclipse.jdt.core.dom.Statement in project bayou by capergroup.
the class DOMSwitchStatement method handle.
@Override
public DSubTree handle() {
DSubTree Sexpr = new DOMExpression(statement.getExpression(), visitor).handle();
boolean branch = Sexpr.isValid();
for (Object o : statement.statements()) {
int type = ((Statement) o).getNodeType();
nodeType.add(type);
DSubTree body = new DOMStatement((Statement) o, visitor).handle();
bodies.add(body.getNodes());
if (// excludes 'case' statement
type != 49)
branch |= body.isValid();
}
if (branch) {
DSubTree switchNode = BuildTree(Sexpr, 1);
tree.addNode(switchNode.getNodes().get(0));
} else {
// only one will add nodes, the rest will add nothing
tree.addNodes(Sexpr.getNodes());
for (Iterator<Object> iter = statement.statements().iterator(); iter.hasNext(); ) {
Object o = iter.next();
DSubTree body = new DOMStatement((Statement) o, visitor).handle();
tree.addNodes(body.getNodes());
}
}
return tree;
}
Aggregations