本文整理汇总了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());
}
示例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());
}
示例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());
}