Ejemplo n.º 1
0
 public void visit(ConditionalExpression node) {
   visit(node.getThenCase());
   visit(node.getCondition());
   if (node.getElseCase() != null) {
     visit(node.getElseCase());
   }
 }
  @Override
  public void negate() {
    switch (operation) {
      case GREATER:
        operation = OperationType.LESS_EQUAL;
        break;
      case LESS:
        operation = OperationType.GREATER_EQUAL;
        break;
      case GREATER_EQUAL:
        operation = OperationType.LESS;
        break;
      case LESS_EQUAL:
        operation = OperationType.GREATER;
        break;
      case EQ:
        operation = OperationType.NE;
        break;
      case NE:
        operation = OperationType.EQ;
        break;
      default:
        break;
    }

    if (left instanceof ConditionalExpression) {
      ((ConditionalExpression) left).negate();
    }

    if (right instanceof ConditionalExpression) {
      ((ConditionalExpression) right).negate();
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ConditionalExpression)
  */
 public boolean visit(ConditionalExpression node) {
   PTConditionalExpression ce = InstantiationFactory.eINSTANCE.createPTConditionalExpression();
   ce.setCondition(perform(node.getExpression()));
   ce.setTrue(perform(node.getThenExpression()));
   ce.setFalse(perform(node.getElseExpression()));
   expression = ce;
   return false;
 }
Ejemplo n.º 4
0
 @Override
 public Void visitConditionalExpression(ConditionalExpression node) {
   visit(node.getCondition());
   writer.print(" ? ");
   visit(node.getThenExpression());
   writer.print(" : ");
   visit(node.getElseExpression());
   return null;
 }
 /*
  * @see ASTVisitor#visit(ConditionalExpression)
  */
 @Override
 public boolean visit(ConditionalExpression node) {
   node.getExpression().accept(this);
   this.fBuffer.append("?"); // $NON-NLS-1$
   node.getThenExpression().accept(this);
   this.fBuffer.append(":"); // $NON-NLS-1$
   node.getElseExpression().accept(this);
   return false;
 }
Ejemplo n.º 6
0
  public void testLinenoConditional() {
    AstRoot root = parse("\na\n" + "    ?\n" + "    b\n" + "    :\n" + "    c\n" + "    ;\n");

    ExpressionStatement ex = (ExpressionStatement) root.getFirstChild();
    ConditionalExpression hook = (ConditionalExpression) ex.getExpression();
    AstNode condExpr = hook.getTestExpression();
    AstNode thenExpr = hook.getTrueExpression();
    AstNode elseExpr = hook.getFalseExpression();

    assertEquals(2, hook.getLineno());
    assertEquals(1, condExpr.getLineno());
    assertEquals(3, thenExpr.getLineno());
    assertEquals(5, elseExpr.getLineno());
  }
Ejemplo n.º 7
0
  public boolean visit(ConditionalExpression s) throws Exception {
    Map<String, String> parameters = createInitialParameters(s);
    xmlWriter.startTag("ConditionalExpression", parameters);

    xmlWriter.startTag("Condition", new HashMap<String, String>());
    s.getCondition().traverse(this);
    xmlWriter.endTag("Condition");

    Expression ifTrue = s.getIfTrue();
    if (ifTrue != null) {
      xmlWriter.startTag("IfTrue", new HashMap<String, String>());
      ifTrue.traverse(this);
      xmlWriter.endTag("IfTrue");
    }

    Expression falseExp = s.getIfFalse();
    if (falseExp != null) {
      xmlWriter.startTag("IfFalse", new HashMap<String, String>());
      falseExp.traverse(this);
      xmlWriter.endTag("IfFalse");
    }

    return false;
  }