baldimir commented on code in PR #6023:
URL:
https://github.com/apache/incubator-kie-drools/pull/6023#discussion_r1679138703
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunction.java:
##########
@@ -82,71 +76,121 @@ public Object invokeReflectively(EvaluationContext ctx,
Object[] params) {
// use reflection to call the appropriate invoke method
try {
boolean isNamedParams = params.length > 0 && params[0] instanceof
NamedParameter;
- if ( !isCustomFunction() ) {
- List<String> available = null;
- if ( isNamedParams ) {
- available = Stream.of( params ).map( p ->
((NamedParameter) p).getName() ).collect( Collectors.toList() );
- }
+ if (!isCustomFunction()) {
+ CandidateMethod cm = getCandidateMethod(ctx, params,
isNamedParams);
- CandidateMethod cm = getCandidateMethod( ctx, params,
isNamedParams, available );
+ if (cm != null) {
+ Object result = cm.actualMethod.invoke(this,
cm.actualParams);
- if ( cm != null ) {
- Object result = cm.apply.invoke( this, cm.actualParams );
-
- if ( result instanceof Either ) {
+ if (result instanceof Either) {
@SuppressWarnings("unchecked")
Either<FEELEvent, Object> either = (Either<FEELEvent,
Object>) result;
return getEitherResult(ctx,
either,
- () ->
Stream.of(cm.apply.getParameters()).map(p ->
p.getAnnotation(ParameterName.class).value()).collect(Collectors.toList()),
- () ->
Arrays.asList(cm.actualParams));
+ () ->
Stream.of(cm.actualMethod.getParameters()).map(p ->
p.getAnnotation(ParameterName.class).value()).collect(Collectors.toList()),
+ () ->
Arrays.asList(cm.actualParams));
}
return result;
} else {
- // CandidateMethod cm could be null also if reflection
failed on Platforms not supporting getClass().getDeclaredMethods()
+ // CandidateMethod cm could be null also if reflection
failed on Platforms not supporting
+ // getClass().getDeclaredMethods()
String ps = getClass().toString();
- logger.error( "Unable to find function '" + getName() + "(
" + ps.substring( 1, ps.length() - 1 ) + " )'" );
- ctx.notifyEvt(() -> new FEELEventBase(Severity.ERROR,
"Unable to find function '" + getName() + "( " + ps.substring(1, ps.length() -
1) + " )'", null));
+ logger.error("Unable to find function '" + getName() + "(
" + ps.substring(1, ps.length() - 1) +
+ " )'");
+ ctx.notifyEvt(() -> new FEELEventBase(Severity.ERROR,
"Unable to find function '" + getName() +
+ "( " + ps.substring(1, ps.length() - 1) + " )'",
null));
}
} else {
- if ( isNamedParams ) {
- params = rearrangeParameters(params,
this.getParameters().get(0).stream().map(Param::getName).collect(Collectors.toList()));
+ if (isNamedParams) {
+ // This is inherently frail because it expects that, if,
the first parameter is NamedParameter
Review Comment:
I think as far as I understand it, this is by the specification. Please see
section 10.3.1.2 Grammar rules, Rule 39 in the specification. The "parameters"
are either "named parameters" or "positional parameters".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]