本文整理汇总了Java中org.apache.calcite.linq4j.tree.ParameterExpression类的典型用法代码示例。如果您正苦于以下问题:Java ParameterExpression类的具体用法?Java ParameterExpression怎么用?Java ParameterExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterExpression类属于org.apache.calcite.linq4j.tree包,在下文中一共展示了ParameterExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testLambdaCallsTwoArgMethod
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testLambdaCallsTwoArgMethod() throws NoSuchMethodException {
// A parameter for the lambda expression.
ParameterExpression paramS =
Expressions.parameter(String.class, "s");
ParameterExpression paramBegin =
Expressions.parameter(Integer.TYPE, "begin");
ParameterExpression paramEnd =
Expressions.parameter(Integer.TYPE, "end");
// This expression represents a lambda expression
// that adds 1 to the parameter value.
FunctionExpression lambdaExpr =
Expressions.lambda(
Expressions.call(
paramS,
String.class.getMethod(
"substring", Integer.TYPE, Integer.TYPE),
paramBegin,
paramEnd), paramS, paramBegin, paramEnd);
// Compile and run the lambda expression.
String s =
(String) lambdaExpr.compile().dynamicInvoke("hello world", 3, 7);
assertEquals("lo w", s);
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:ExpressionTest.java
示例2: testWriteTryCatch
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testWriteTryCatch() {
final ParameterExpression cce_ =
Expressions.parameter(Modifier.FINAL, ClassCastException.class, "cce");
final ParameterExpression re_ =
Expressions.parameter(0, RuntimeException.class, "re");
Node node =
Expressions.tryCatch(
Expressions.block(
Expressions.return_(null,
Expressions.call(Expressions.constant("foo"), "length"))),
Expressions.catch_(cce_,
Expressions.return_(null, Expressions.constant(null))),
Expressions.catch_(re_,
Expressions.return_(null,
Expressions.call(re_, "toString"))));
assertEquals(
"try {\n"
+ " return \"foo\".length();\n"
+ "} catch (final ClassCastException cce) {\n"
+ " return null;\n"
+ "} catch (RuntimeException re) {\n"
+ " return re.toString();\n"
+ "}\n",
Expressions.toString(node));
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:ExpressionTest.java
示例3: testCompile
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testCompile() throws NoSuchMethodException {
// Creating a parameter for the expression tree.
ParameterExpression param = Expressions.parameter(String.class);
// Creating an expression for the method call and specifying its
// parameter.
MethodCallExpression methodCall =
Expressions.call(
Integer.class,
"valueOf",
Collections.<Expression>singletonList(param));
// The following statement first creates an expression tree,
// then compiles it, and then runs it.
int x =
Expressions.<Function1<String, Integer>>lambda(
methodCall,
new ParameterExpression[] { param })
.getFunction()
.apply("1234");
assertEquals(1234, x);
}
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:ExpressionTest.java
示例4: testFor
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testFor() throws NoSuchFieldException {
final BlockBuilder builder = new BlockBuilder();
final ParameterExpression i_ = Expressions.parameter(int.class, "i");
builder.add(
Expressions.for_(
Expressions.declare(
0, i_, Expressions.constant(0)),
Expressions.lessThan(i_, Expressions.constant(10)),
Expressions.postIncrementAssign(i_),
Expressions.block(
Expressions.statement(
Expressions.call(
Expressions.field(
null, System.class.getField("out")),
"println",
i_)))));
assertEquals(
"{\n"
+ " for (int i = 0; i < 10; i++) {\n"
+ " System.out.println(i);\n"
+ " }\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:ExpressionTest.java
示例5: testNoInlineMultipleUsage
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testNoInlineMultipleUsage() {
ParameterExpression p1 = Expressions.parameter(int.class, "p1");
ParameterExpression p2 = Expressions.parameter(int.class, "p2");
DeclarationStatement decl = Expressions.declare(16, "x",
Expressions.subtract(p1, p2));
b.add(decl);
b.add(
Expressions.return_(null,
Expressions.add(decl.parameter, decl.parameter)));
assertEquals(
"{\n"
+ " final int x = p1 - p2;\n"
+ " return x + x;\n"
+ "}\n",
b.toBlock().toString());
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:InlinerTest.java
示例6: testAssignInConditionMultipleUsage
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testAssignInConditionMultipleUsage() {
// int t;
// return (t = 1) != a ? t : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t = Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(0, t, null));
Expression v = builder.append("v",
Expressions.makeTernary(ExpressionType.Conditional,
Expressions.makeBinary(ExpressionType.NotEqual,
Expressions.assign(t, Expressions.constant(1)),
Expressions.parameter(int.class, "a")),
t,
Expressions.parameter(int.class, "c")));
builder.add(Expressions.return_(null, v));
assertEquals(
"{\n"
+ " int t;\n"
+ " return (t = 1) != a ? t : c;\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:InlinerTest.java
示例7: checkAssignInConditionOptimizedOut
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
void checkAssignInConditionOptimizedOut(int modifiers, String s) {
// int t;
// return (t = 1) != a ? b : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t =
Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(modifiers, t, null));
Expression v = builder.append("v",
Expressions.makeTernary(ExpressionType.Conditional,
Expressions.makeBinary(ExpressionType.NotEqual,
Expressions.assign(t, Expressions.constant(1)),
Expressions.parameter(int.class, "a")),
Expressions.parameter(int.class, "b"),
Expressions.parameter(int.class, "c")));
builder.add(Expressions.return_(null, v));
assertThat(Expressions.toString(builder.toBlock()),
CoreMatchers.equalTo(s));
}
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:InlinerTest.java
示例8: testAssignInConditionMultipleUsageNonOptimized
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testAssignInConditionMultipleUsageNonOptimized() {
// int t = 2;
// return (t = 1) != a ? 1 : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t = Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(0, t, TWO));
Expression v = builder.append("v",
Expressions.makeTernary(ExpressionType.Conditional,
Expressions.makeBinary(ExpressionType.NotEqual,
Expressions.assign(t, Expressions.constant(1)),
Expressions.parameter(int.class, "a")),
t,
Expressions.parameter(int.class, "c")));
builder.add(Expressions.return_(null, v));
assertEquals(
"{\n"
+ " int t = 2;\n"
+ " return (t = 1) != a ? t : c;\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:InlinerTest.java
示例9: testMultiPassOptimization
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testMultiPassOptimization() {
// int t = u + v;
// boolean b = t > 1 ? true : true; -- optimized out, thus t can be inlined
// return b ? t : 2
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression u = Expressions.parameter(int.class, "u");
final ParameterExpression v = Expressions.parameter(int.class, "v");
Expression t = builder.append("t", Expressions.add(u, v));
Expression b = builder.append("b",
Expressions.condition(Expressions.greaterThan(t, ONE), TRUE, TRUE));
builder.add(Expressions.return_(null, Expressions.condition(b, t, TWO)));
assertEquals(
"{\n"
+ " return u + v;\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:InlinerTest.java
示例10: testFactorOutBinaryAdd
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testFactorOutBinaryAdd() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(Expressions.add(ONE, TWO))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$1_2;\n"
+ " }\n"
+ "\n"
+ " static final int $L4J$C$1_2 = 1 + 2;\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:DeterministicTest.java
示例11: testFactorOutBinaryAddSurvivesMultipleOptimizations
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testFactorOutBinaryAddSurvivesMultipleOptimizations() {
assertThat(
optimize(
optimizeExpression(
Expressions.new_(Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(Expressions.add(ONE, TWO)))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$1_2;\n"
+ " }\n"
+ "\n"
+ " static final int $L4J$C$1_2 = 1 + 2;\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:DeterministicTest.java
示例12: testFactorOutBinaryAddNameCollision
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testFactorOutBinaryAddNameCollision() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.multiply(Expressions.add(ONE, TWO),
Expressions.subtract(ONE, TWO)))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$1_2_1_20;\n"
+ " }\n"
+ "\n"
+ " static final int $L4J$C$1_2 = 1 + 2;\n"
+ " static final int $L4J$C$1_20 = 1 - 2;\n"
+ " static final int $L4J$C$1_2_1_20 = $L4J$C$1_2 * $L4J$C$1_20;\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:DeterministicTest.java
示例13: testFactorOutBinaryAddMul
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testFactorOutBinaryAddMul() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.multiply(Expressions.add(ONE, TWO),
THREE))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$1_2_3;\n"
+ " }\n"
+ "\n"
+ " static final int $L4J$C$1_2 = 1 + 2;\n"
+ " static final int $L4J$C$1_2_3 = $L4J$C$1_2 * 3;\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:DeterministicTest.java
示例14: testNewBigInteger
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testNewBigInteger() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0, int.class, "test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.new_(BigInteger.class,
Expressions.constant("42")))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$new_java_math_BigInteger_42_;\n"
+ " }\n"
+ "\n"
+ " static final java.math.BigInteger "
+ "$L4J$C$new_java_math_BigInteger_42_ = new java.math.BigInteger(\n"
+ " \"42\");\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:DeterministicTest.java
示例15: testInstanceofTest
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testInstanceofTest() {
// Single instanceof is not optimized
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0, int.class, "test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.typeIs(ONE, Boolean.class))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return 1 instanceof Boolean;\n"
+ " }\n"
+ "\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:DeterministicTest.java
示例16: testInstanceofComplexTest
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testInstanceofComplexTest() {
// instanceof is optimized in complex expressions
assertThat(
optimize(
Expressions.new_(Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(0, int.class, "test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.orElse(
Expressions.typeIs(ONE, Boolean.class),
Expressions.typeIs(TWO, Integer.class)))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$1_instanceof_Boolean_2_instanceof_Integer;\n"
+ " }\n"
+ "\n"
+ " static final boolean "
+ "$L4J$C$1_instanceof_Boolean_2_instanceof_Integer = 1 instanceof "
+ "Boolean || 2 instanceof Integer;\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:DeterministicTest.java
示例17: testIntegerValueOfZeroComplexTest
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testIntegerValueOfZeroComplexTest() {
// Integer.valueOf(0) is optimized in complex expressions
assertThat(
optimize(
Expressions.new_(Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(0, int.class, "test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.call(
getMethod(Integer.class, "valueOf", int.class),
Expressions.constant(0)))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$Integer_valueOf_0_;\n"
+ " }\n"
+ "\n"
+ " static final Integer $L4J$C$Integer_valueOf_0_ = Integer.valueOf(0);\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:DeterministicTest.java
示例18: testDeterministicMethodCall
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testDeterministicMethodCall() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestClass.class,
"deterministic", int.class),
ONE))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$org_apache_calcite_linq4j_test_DeterministicTest_TestClass_dete33e8af1c;\n"
+ " }\n"
+ "\n"
+ " static final int $L4J$C$org_apache_calcite_linq4j_test_DeterministicTest_TestClass_dete33e8af1c = org.apache.calcite.linq4j.test.DeterministicTest.TestClass.deterministic(1);\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:DeterministicTest.java
示例19: testNonDeterministicMethodCall
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testNonDeterministicMethodCall() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestClass.class,
"nonDeterministic", int.class),
ONE))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return org.apache.calcite.linq4j.test.DeterministicTest.TestClass.nonDeterministic(1);\n"
+ " }\n"
+ "\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:DeterministicTest.java
示例20: testDeterministicClassDefaultMethod
import org.apache.calcite.linq4j.tree.ParameterExpression; //导入依赖的package包/类
@Test public void testDeterministicClassDefaultMethod() {
assertThat(
optimize(
Expressions.new_(
Runnable.class,
Collections.<Expression>emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
Collections.<ParameterExpression>emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestDeterministicClass.class,
"deterministic", int.class),
ONE))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
+ " return $L4J$C$org_apache_calcite_linq4j_test_DeterministicTest_TestDeterminis9de610da;\n"
+ " }\n"
+ "\n"
+ " static final int $L4J$C$org_apache_calcite_linq4j_test_DeterministicTest_TestDeterminis9de610da = org.apache.calcite.linq4j.test.DeterministicTest.TestDeterministicClass.deterministic(1);\n"
+ " };\n"
+ "}\n"));
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:DeterministicTest.java
注:本文中的org.apache.calcite.linq4j.tree.ParameterExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论