Ejemplo n.º 1
0
  @Override
  public boolean visit(org.eclipse.edt.compiler.core.ast.WhenClause whenClause) {
    IfStatement clause = factory.createIfStatement();

    Expression prevCond = null;
    for (Node node : whenClause.getExpr_plus()) {
      node.accept(this);

      Expression expr = (Expression) stack.pop();
      if (prevCond != null) {
        BinaryExpression binExp = factory.createBinaryExpression();
        binExp.setLHS(prevCond);
        binExp.setRHS(expr);
        binExp.setOperator(Operation.OR);
        expr = binExp;
      }
      prevCond = expr;
      clause.setCondition(expr);
    }
    StatementBlock block = factory.createStatementBlock();
    for (Node node : (List<Node>) whenClause.getStmts()) {
      node.accept(this);
      Statement stmt = (Statement) stack.pop();
      if (stmt != null) {
        block.getStatements().add(stmt);
      }
    }
    clause.setTrueBranch(block);
    stack.push(clause);
    setElementInformation(whenClause, clause);
    setElementInformation(whenClause, block);
    return false;
  }
Ejemplo n.º 2
0
 private Expression addWhenCriterion(Expression criterion, Expression condition) {
   if (condition instanceof BinaryExpression) {
     BinaryExpression binExp = (BinaryExpression) condition;
     Expression expr = addWhenCriterion(criterion, binExp.getLHS());
     binExp.setLHS(expr);
     expr = addWhenCriterion(criterion, binExp.getRHS());
     binExp.setRHS(expr);
     return condition;
   } else {
     BinaryExpression binExp = factory.createBinaryExpression();
     binExp.setLHS(criterion);
     binExp.setRHS(condition);
     binExp.setOperator(Operation.EQUALS);
     return binExp;
   }
 }