当前位置: 首页>>代码示例>>Java>>正文


Java BlockStatement.accept方法代码示例

本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockStatement.accept方法的典型用法代码示例。如果您正苦于以下问题:Java BlockStatement.accept方法的具体用法?Java BlockStatement.accept怎么用?Java BlockStatement.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.linq4j.tree.BlockStatement的用法示例。


在下文中一共展示了BlockStatement.accept方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkBlockBuilder

import org.apache.calcite.linq4j.tree.BlockStatement; //导入方法依赖的package包/类
public void checkBlockBuilder(boolean optimizing, String expected) {
  BlockBuilder statements = new BlockBuilder(optimizing);
  Expression one =
      statements.append(
          "one", Expressions.constant(1));
  Expression two =
      statements.append(
          "two", Expressions.constant(2));
  Expression three =
      statements.append(
          "three", Expressions.add(one, two));
  Expression six =
      statements.append(
          "six",
          Expressions.multiply(three, two));
  Expression nine =
      statements.append(
          "nine",
          Expressions.multiply(three, three));
  Expression eighteen =
      statements.append(
          "eighteen",
          Expressions.add(
              Expressions.add(three, six),
              nine));
  statements.add(Expressions.return_(null, eighteen));
  BlockStatement expression = statements.toBlock();
  assertEquals(expected, Expressions.toString(expression));
  expression.accept(new Shuttle());
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:ExpressionTest.java

示例2: testBlockBuilder2

import org.apache.calcite.linq4j.tree.BlockStatement; //导入方法依赖的package包/类
@Test public void testBlockBuilder2() {
  BlockBuilder statements = new BlockBuilder();
  Expression element =
      statements.append(
          "element", Expressions.constant(null));
  Expression comparator =
      statements.append(
          "comparator", Expressions.constant(null, Comparator.class));
  Expression treeSet =
      statements.append(
          "treeSet",
          Expressions.new_(
              TreeSet.class,
              Arrays.asList(comparator)));
  statements.add(
      Expressions.return_(
          null,
          Expressions.call(
              treeSet,
              "add",
              element)));
  BlockStatement expression = statements.toBlock();
  final String expected = "{\n"
      + "  final java.util.TreeSet treeSet = new java.util.TreeSet(\n"
      + "    (java.util.Comparator) null);\n"
      + "  return treeSet.add(null);\n"
      + "}\n";
  assertThat(Expressions.toString(expression), is(expected));
  expression.accept(new Shuttle());
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:ExpressionTest.java

示例3: testBlockBuilder3

import org.apache.calcite.linq4j.tree.BlockStatement; //导入方法依赖的package包/类
@Test public void testBlockBuilder3() {
/*
    int a = 1;
    int b = a + 2;
    int c = a + 3;
    int d = a + 4;
    int e = {
      int b = a + 3;
      foo(b);
    }
    bar(a, b, c, d, e);
*/
    BlockBuilder builder0 = new BlockBuilder();
    final Expression a = builder0.append("_a", Expressions.constant(1));
    final Expression b =
        builder0.append("_b", Expressions.add(a, Expressions.constant(2)));
    final Expression c =
        builder0.append("_c", Expressions.add(a, Expressions.constant(3)));
    final Expression d =
        builder0.append("_d", Expressions.add(a, Expressions.constant(4)));

    BlockBuilder builder1 = new BlockBuilder();
    final Expression b1 =
        builder1.append("_b", Expressions.add(a, Expressions.constant(3)));
    builder1.add(
        Expressions.statement(
            Expressions.call(ExpressionTest.class, "foo", b1)));
    final Expression e = builder0.append("e", builder1.toBlock());
    builder0.add(
        Expressions.statement(
            Expressions.call(ExpressionTest.class, "bar", a, b, c, d, e)));
    // With the bug in BlockBuilder.append(String, BlockExpression),
    //    bar(1, _b, _c, _d, foo(_d));
    // Correct result is
    //    bar(1, _b, _c, _d, foo(_c));
    // because _c has the same expression (a + 3) as inner b.
    BlockStatement expression = builder0.toBlock();
    assertEquals(
        "{\n"
            + "  final int _b = 1 + 2;\n"
            + "  final int _c = 1 + 3;\n"
            + "  final int _d = 1 + 4;\n"
            + "  org.apache.calcite.linq4j.test.ExpressionTest.bar(1, _b, _c, _d, org.apache.calcite.linq4j.test.ExpressionTest.foo(_c));\n"
            + "}\n",
        Expressions.toString(expression));
    expression.accept(new Shuttle());
  }
 
开发者ID:apache,项目名称:calcite,代码行数:48,代码来源:ExpressionTest.java


注:本文中的org.apache.calcite.linq4j.tree.BlockStatement.accept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。