@Override public Void visitFunctionExpression(FunctionExpression node) { visit(node.getParameters()); writer.print(' '); visit(node.getBody()); return null; }
public void testLambdaCallsBinaryOp() { // A parameter for the lambda expression. ParameterExpression paramExpr = Expressions.parameter(Integer.TYPE, "arg"); // This expression represents a lambda expression // that adds 1 to the parameter value. FunctionExpression lambdaExpr = Expressions.lambda( Expressions.add(paramExpr, Expressions.constant(2)), Arrays.asList(paramExpr)); // Print out the expression. String s = Expressions.toString(lambdaExpr); assertEquals( "new net.hydromatic.linq4j.function.Function1() {\n" + " public int apply(Integer arg) {\n" + " return arg + 2;\n" + " }\n" + " public Object apply(Object arg) {\n" + " return apply(\n" + " (Integer) arg);\n" + " }\n" + "}\n", s); // Compile and run the lambda expression. // The value of the parameter is 1. int n = (Integer) lambdaExpr.compile().dynamicInvoke(1); // This code example produces the following output: // // arg => (arg +2) // 3 assertEquals(3, n); }
@Override protected void postCopyIn(Map alreadyDone) { ((ListExpressionOperator) operator).setNumberOfItems(0); Boolean hasLastChildCopy = hasLastChild; hasLastChild = null; super.postCopyIn(alreadyDone); hasLastChild = hasLastChildCopy; }
/** * INTERNAL: Add a child and ensure it is the rightmost in the tree as long as it is in the tree * If there is already a node that is set as therightmost node, replace it * * @param argument */ public synchronized void addRightMostChild(Expression argument) { if (hasLastChild != null && hasLastChild.booleanValue()) { getChildren().remove(super.getChildren().size() - 1); super.addChild(argument); } else { this.addChild(argument); } this.hasLastChild = Boolean.TRUE; }
/** * INTERNAL: Add a new Expression to the list of arguments. This method will update the list of * arguments and any constant strings that are required to be printed with the arguments * * @param argument */ @Override public synchronized void addChild(Expression argument) { if (hasLastChild != null && hasLastChild.booleanValue()) { getChildren().add(getChildren().size() - 1, argument); } else { super.addChild(argument); } setBaseExpression((Expression) getChildren().firstElement()); ((ListExpressionOperator) operator).incrementNumberOfItems(); }
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); }
public void visit(FunctionExpression entity) { wGetVisitor1().visit(entity.getFunctionName()); wGetVisitor1().visit(entity.getParams()); }
/** * INTERNAL: Set the operator for this expression. The operator must be a ListExpressionOperator * This method asserts that the passed argument is a ListExpressionOperator rather than throwing * an exception since this method is entirely internal and the user should never get this behavior */ @Override public void setOperator(ExpressionOperator theOperator) { assert (theOperator instanceof ListExpressionOperator); super.setOperator(theOperator); ((ListExpressionOperator) theOperator).setNumberOfItems(0); }
/** INTERNAL: */ public void initializePlatformOperator(DatabasePlatform platform) { super.initializePlatformOperator(platform); ((ListExpressionOperator) platformOperator) .setNumberOfItems(((ListExpressionOperator) operator).getNumberOfItems()); }