use of org.apache.calcite.linq4j.tree.Node in project calcite by apache.
the class ExpressionTest method testWriteTryCatchFinally.
@Test
public void testWriteTryCatchFinally() {
final ParameterExpression cce_ = Expressions.parameter(Modifier.FINAL, ClassCastException.class, "cce");
final ParameterExpression re_ = Expressions.parameter(0, RuntimeException.class, "re");
Node node = Expressions.tryCatchFinally(Expressions.block(Expressions.return_(null, Expressions.call(Expressions.constant("foo"), "length"))), Expressions.statement(Expressions.call(Expressions.constant("foo"), "toUpperCase")), Expressions.catch_(cce_, Expressions.return_(null, Expressions.constant(null))), Expressions.catch_(re_, Expressions.throw_(Expressions.new_(IndexOutOfBoundsException.class))));
assertEquals("try {\n" + " return \"foo\".length();\n" + "} catch (final ClassCastException cce) {\n" + " return null;\n" + "} catch (RuntimeException re) {\n" + " throw new IndexOutOfBoundsException();\n" + "} finally {\n" + " \"foo\".toUpperCase();\n" + "}\n", Expressions.toString(node));
}
use of org.apache.calcite.linq4j.tree.Node in project calcite by apache.
the class ExpressionTest method testWriteWhile.
@Test
public void testWriteWhile() {
DeclarationStatement xDecl;
DeclarationStatement yDecl;
Node node = Expressions.block(xDecl = Expressions.declare(0, "x", Expressions.constant(10)), yDecl = Expressions.declare(0, "y", Expressions.constant(0)), Expressions.while_(Expressions.lessThan(xDecl.parameter, Expressions.constant(5)), Expressions.statement(Expressions.preIncrementAssign(yDecl.parameter))));
assertEquals("{\n" + " int x = 10;\n" + " int y = 0;\n" + " while (x < 5) {\n" + " ++y;\n" + " }\n" + "}\n", Expressions.toString(node));
}
use of org.apache.calcite.linq4j.tree.Node in project calcite by apache.
the class ExpressionTest method testWriteTryFinally.
@Test
public void testWriteTryFinally() {
final ParameterExpression cce_ = Expressions.parameter(Modifier.FINAL, ClassCastException.class, "cce");
final ParameterExpression re_ = Expressions.parameter(0, RuntimeException.class, "re");
Node node = Expressions.ifThen(Expressions.constant(true), Expressions.tryFinally(Expressions.block(Expressions.return_(null, Expressions.call(Expressions.constant("foo"), "length"))), Expressions.statement(Expressions.call(Expressions.constant("foo"), "toUpperCase"))));
assertEquals("if (true) {\n" + " try {\n" + " return \"foo\".length();\n" + " } finally {\n" + " \"foo\".toUpperCase();\n" + " }\n" + "}\n", Expressions.toString(node));
}
use of org.apache.calcite.linq4j.tree.Node in project calcite by apache.
the class ExpressionTest method testWriteTryCatch.
@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));
}
Aggregations