Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ConditionalExpression


  public void testFactorial() throws Exception {
    CompilationUnit simple = EclipseTACSimpleTestDriver.parseCode("Factorial", FACTORIAL);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(simple);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
   
    ConditionalExpression cond = (ConditionalExpression) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    Variable r = tac.variable(cond);
    TACInstruction instr;

    instr = tac.instruction(cond.getExpression());
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof BinaryOperation);
   
    instr = tac.instruction(cond.getThenExpression());
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof LoadLiteralInstruction);
    Assert.assertEquals(r, ((LoadLiteralInstruction) instr).getTarget());
    Assert.assertEquals("1", ((LoadLiteralInstruction) instr).getLiteral());
   
    instr = tac.instruction(cond.getElseExpression());
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof MethodCallInstruction);
    Assert.assertEquals(r, ((MethodCallInstruction) instr).getTarget());

    Assert.assertEquals(r, tac.variable(cond.getThenExpression()));
    Assert.assertEquals(r, tac.variable(cond.getElseExpression()));
  }
View Full Code Here


      }
      break;
    }

    case ASTNode.CONDITIONAL_EXPRESSION: {
      final ConditionalExpression ce = (ConditionalExpression) node;
      this.processExpression(ce);
      break;
    }

    case ASTNode.METHOD_DECLARATION: {
View Full Code Here

                .getOperator(), node);
      break;
    }

    case ASTNode.CONDITIONAL_EXPRESSION: {
      final ConditionalExpression ce = (ConditionalExpression) node;
      this.processExpression(ce.getThenExpression());
      this.processExpression(ce.getElseExpression());
      break;
    }

    case ASTNode.FIELD_ACCESS: {
      final FieldAccess fieldAccess = (FieldAccess) node;
View Full Code Here

        castRet.setExpression(cloneInvoke);
        Type retType = (Type) ASTNode.copySubtree(castRet.getAST(), method.getReturnType2());
        castRet.setType(retType);


        ConditionalExpression conditionalExpression = workingUnit.getAST().newConditionalExpression();
        conditionalExpression.setElseExpression(castRet);
        conditionalExpression.setThenExpression(workingUnit.getAST().newNullLiteral() );

        InfixExpression nullTest = workingUnit.getAST().newInfixExpression();
        nullTest.setOperator(InfixExpression.Operator.EQUALS);
        nullTest.setRightOperand(workingUnit.getAST().newNullLiteral());
        Expression initialLoad = (SimpleName) ASTNode.copySubtree(cloneInvoke.getAST(), original);
        nullTest.setLeftOperand(initialLoad);

        conditionalExpression.setExpression(nullTest);

        rewrite.replace(original, conditionalExpression, null);

    }
View Full Code Here

      }
      //we do not go into qualified names
      if (node.getNodeType() == ASTNode.QUALIFIED_NAME)
        return false;
      if (node.getNodeType() == ASTNode.CONDITIONAL_EXPRESSION) {
        ConditionalExpression cond = (ConditionalExpression) node;
        BooleanEvaluationState<DI> bes = bCondEval.evaluateCondition(state, cond.getExpression());
        state = bes.conditionMet;
        cond.getThenExpression().accept(this);
        DI thenResult = state;
        state = bes.conditionNotMet;
        cond.getElseExpression().accept(this);
        DI elseResult = state;
        state = thenResult.join(elseResult);
        return false;
      }
      return true;
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ConditionalExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.