Invokes the lambda expression with the given arguments in the specified EL context. The formal parameters are bound to the corresponding arguments, and the body expression is evaluated within a lambda scope. If the result is another lambda, the current arguments are made available to the nested lamb
(ELContext context, Object... args)
| 73 | * @throws ELException if the number of arguments is less than the number of formal parameters |
| 74 | */ |
| 75 | @SuppressWarnings("null") // args[i] can't be null due to earlier checks |
| 76 | public Object invoke(ELContext context, Object... args) throws ELException { |
| 77 | |
| 78 | Objects.requireNonNull(context); |
| 79 | |
| 80 | int formalParamCount = 0; |
| 81 | if (formalParameters != null) { |
| 82 | formalParamCount = formalParameters.size(); |
| 83 | } |
| 84 | |
| 85 | int argCount = 0; |
| 86 | if (args != null) { |
| 87 | argCount = args.length; |
| 88 | } |
| 89 | |
| 90 | if (formalParamCount > argCount) { |
| 91 | throw new ELException(Util.message(context, "lambdaExpression.tooFewArgs", Integer.valueOf(argCount), |
| 92 | Integer.valueOf(formalParamCount))); |
| 93 | } |
| 94 | |
| 95 | // Build the argument map |
| 96 | // Start with the arguments from any outer expressions so if there is |
| 97 | // any overlap the local arguments have priority |
| 98 | Map<String,Object> lambdaArguments = new HashMap<>(nestedArguments); |
| 99 | for (int i = 0; i < formalParamCount; i++) { |
| 100 | lambdaArguments.put(formalParameters.get(i), args[i]); |
| 101 | } |
| 102 | |
| 103 | context.enterLambdaScope(lambdaArguments); |
| 104 | |
| 105 | try { |
| 106 | Object result = expression.getValue(context); |
| 107 | // Make arguments from this expression available to any nested |
| 108 | // expression |
| 109 | if (result instanceof LambdaExpression) { |
| 110 | ((LambdaExpression) result).nestedArguments.putAll(lambdaArguments); |
| 111 | } |
| 112 | return result; |
| 113 | } finally { |
| 114 | context.exitLambdaScope(); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Invokes the lambda expression with the given arguments using the EL context set by |
no test coverage detected