Search in sources :

Example 1 with ClassDeclaration

use of org.apache.calcite.linq4j.tree.ClassDeclaration in project storm by apache.

the class RexNodeToJavaCodeCompiler method baz.

/** Given a method that implements {@link ExecutableExpression#execute(Context, Object[])},
   * adds a bridge method that implements {@link ExecutableExpression#execute(Context)}, and
   * compiles. */
static String baz(ParameterExpression context_, ParameterExpression outputValues_, BlockStatement block, String className) {
    final List<MemberDeclaration> declarations = Lists.newArrayList();
    // public void execute(Context, Object[] outputValues)
    declarations.add(Expressions.methodDecl(Modifier.PUBLIC, void.class, StormBuiltInMethod.EXPR_EXECUTE2.method.getName(), ImmutableList.of(context_, outputValues_), block));
    // public Object execute(Context)
    final BlockBuilder builder = new BlockBuilder();
    final Expression values_ = builder.append("values", Expressions.newArrayBounds(Object.class, 1, Expressions.constant(1)));
    builder.add(Expressions.statement(Expressions.call(Expressions.parameter(ExecutableExpression.class, "this"), StormBuiltInMethod.EXPR_EXECUTE2.method, context_, values_)));
    builder.add(Expressions.return_(null, Expressions.arrayIndex(values_, Expressions.constant(0))));
    declarations.add(Expressions.methodDecl(Modifier.PUBLIC, Object.class, StormBuiltInMethod.EXPR_EXECUTE1.method.getName(), ImmutableList.of(context_), builder.toBlock()));
    final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, className, null, ImmutableList.<Type>of(ExecutableExpression.class), declarations);
    return Expressions.toString(Lists.newArrayList(classDeclaration), "\n", false);
}
Also used : ClassDeclaration(org.apache.calcite.linq4j.tree.ClassDeclaration) Expression(org.apache.calcite.linq4j.tree.Expression) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) MemberDeclaration(org.apache.calcite.linq4j.tree.MemberDeclaration) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Aggregations

BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 ClassDeclaration (org.apache.calcite.linq4j.tree.ClassDeclaration)1 Expression (org.apache.calcite.linq4j.tree.Expression)1 MemberDeclaration (org.apache.calcite.linq4j.tree.MemberDeclaration)1 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)1 ExecutableExpression (org.apache.storm.sql.runtime.calcite.ExecutableExpression)1