/*
  * @see ASTVisitor#visit(LambdaExpression)
  */
 @Override
 public boolean visit(LambdaExpression node) {
   boolean hasParentheses = node.hasParentheses();
   if (hasParentheses) this.fBuffer.append('(');
   for (Iterator<? extends VariableDeclaration> it = node.parameters().iterator();
       it.hasNext(); ) {
     VariableDeclaration v = it.next();
     v.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   if (hasParentheses) this.fBuffer.append(')');
   this.fBuffer.append(" -> "); // $NON-NLS-1$
   node.getBody().accept(this);
   return false;
 }
Example #2
0
  @Override
  public Function<Object[], ?> visit(LambdaExpression<?> e) {

    final Function<Object[], ?> f = e.getBody().accept(this);

    int size = e.getParameters().size();
    List<Function<Object[], ?>> ppe = new ArrayList<>(size);
    for (ParameterExpression p : e.getParameters()) ppe.add(p.accept(this));

    Function<Object[], Object[]> params =
        pp -> {
          Object[] r = new Object[ppe.size()];
          int index = 0;
          for (Function<Object[], ?> pe : ppe) {
            r[index++] = pe.apply(pp);
          }
          return r;
        };

    return f.compose(params);
  }
Example #3
0
 public void toString(StringBuffer bld, Variable rootVariable) {
   int top = assignments.length;
   if (top > 0) {
     for (int idx = 0; idx < top; ++idx) {
       appendOperand(bld, rootVariable, assignments[idx].rhs, IExpressionConstants.PRIORITY_COMMA);
       bld.append(", "); // $NON-NLS-1$
     }
     bld.append(OPERATOR_EACH);
     bld.append(", {"); // $NON-NLS-1$
     for (int idx = 0; idx < top; ++idx) {
       appendOperand(bld, rootVariable, assignments[idx].lhs, IExpressionConstants.PRIORITY_COMMA);
       bld.append(", "); // $NON-NLS-1$
     }
   }
   super.toString(bld, rootVariable);
   if (top > 0) bld.append('}');
 }