@Override public boolean visit(org.eclipse.edt.compiler.core.ast.IfStatement ifStatement) { IfStatement stmt = factory.createIfStatement(); stack.push(stmt); setElementInformation(ifStatement, stmt); ifStatement.getCondition().accept(this); stmt.setCondition((Expression) stack.pop()); StatementBlock block = factory.createStatementBlock(); setElementInformation(ifStatement, block); stmt.setTrueBranch(block); for (Node node : (List<Node>) ifStatement.getStmts()) { node.accept(this); Statement currStmt = (Statement) stack.pop(); if (currStmt != null) { block.getStatements().add(currStmt); } } if (ifStatement.hasElse()) { block = factory.createStatementBlock(); setElementInformation(ifStatement, block); stmt.setFalseBranch(block); for (Node node : (List<Node>) ifStatement.getElse().getStmts()) { node.accept(this); Statement currStmt = (Statement) stack.pop(); if (currStmt != null) { block.getStatements().add(currStmt); } } } return false; }
@Override public boolean visit(org.eclipse.edt.compiler.core.ast.CaseStatement caseStatement) { IfStatement stmt = null; Expression criterion = null; // need to create a statement block to hold the label statement and if statement StatementBlock block = factory.createStatementBlock(); LabelStatement label = factory.createLabelStatement(); label.setLabel("eze_CaseLabel_" + caseLabelCounter); caseLabelCounter = caseLabelCounter + 1; caseLabelStack.push(label); setElementInformation(caseStatement, label); block.getStatements().add(label); if (caseStatement.hasCriterion()) { caseStatement.getCriterion().accept(this); criterion = (Expression) stack.pop(); } IfStatement current = null; for (Node node : caseStatement.getWhenClauses()) { node.accept(this); IfStatement when = (IfStatement) stack.pop(); if (criterion != null) { when.setCondition(addWhenCriterion(criterion, when.getCondition())); } if (stmt == null) { current = when; stmt = current; } else { current.setFalseBranch(when); current = when; } } if (caseStatement.getDefaultClause() != null) { caseStatement.getDefaultClause().accept(this); current.setFalseBranch((Statement) stack.pop()); } block.getStatements().add(stmt); stack.push(block); setElementInformation(caseStatement, stmt); return false; }