コード例 #1
0
  @NotNull
  private JsExpression translateElvis(JetBinaryExpression expression) {
    JsExpression leftExpression = translateLeftExpression(context(), expression);

    JetExpression rightJetExpression = expression.getRight();
    assert rightJetExpression != null : "Binary expression should have a right expression";
    JsNode rightNode = Translation.translateExpression(rightJetExpression, context());

    if (rightNode instanceof JsExpression) {
      return TranslationUtils.notNullConditional(
          leftExpression, (JsExpression) rightNode, context());
    }

    TemporaryVariable result = context().declareTemporary(null);
    AssignToExpressionMutator saveResultToTemporaryMutator =
        new AssignToExpressionMutator(result.reference());
    context()
        .addStatementToCurrentBlock(
            LastExpressionMutator.mutateLastExpression(
                leftExpression, saveResultToTemporaryMutator));

    JsExpression testExpression = TranslationUtils.isNullCheck(result.reference());
    JsStatement thenStatement = convertToStatement(rightNode);
    JsIf ifStatement = new JsIf(testExpression, thenStatement);
    context().addStatementToCurrentBlock(ifStatement);

    return result.reference();
  }
コード例 #2
0
 @NotNull
 @Override
 public JsExpression translateAsSet(@NotNull JsExpression setTo) {
   return translateAsSet(arrayExpression.reference(), toExpressionList(indexExpressions), setTo);
 }
コード例 #3
0
 @NotNull
 @Override
 public JsExpression translateAsGet() {
   return translateAsGet(arrayExpression.reference(), toExpressionList(indexExpressions));
 }