コード例 #1
0
 private static boolean elvisExpressionsAreEquivalent(
     @NotNull GrElvisExpression condExp1, @NotNull GrElvisExpression condExp2) {
   final GrExpression condition1 = condExp1.getCondition();
   final GrExpression condition2 = condExp2.getCondition();
   final GrExpression elseExpression1 = condExp1.getElseBranch();
   final GrExpression elseExpression2 = condExp2.getElseBranch();
   return expressionsAreEquivalent(condition1, condition2)
       && expressionsAreEquivalent(elseExpression1, elseExpression2);
 }
コード例 #2
0
  @Override
  public void visitElvisExpression(GrElvisExpression expression) {
    GrExpression condition = expression.getCondition();
    GrExpression elseBranch = expression.getElseBranch();

    condition.accept(this);
    List<GotoInstruction> negations = collectAndRemoveAllPendingNegations(expression);

    InstructionImpl head = myHead;
    handlePossibleReturn(condition);
    addPendingEdge(expression, myHead);
    myHead = head;

    if (elseBranch != null) {
      head = reduceAllNegationsIntoInstruction(expression, negations);
      if (head != null) myHead = head;
      elseBranch.accept(this);
      handlePossibleReturn(elseBranch);
    }
  }