use of org.kie.dmn.feel.codegen.feel11.FEELCompilationError in project drools by kiegroup.
the class FunctionDefs method asMethodCall.
public static Expression asMethodCall(String className, String methodSignature, List<String> params) {
// creating a simple algorithm to find the method in java
// without using any external libraries in this initial implementation
// might need to explicitly use a classloader here
String[] mp = FunctionDefNode.parseMethod(methodSignature);
try {
String methodName = mp[0];
String[] paramTypeNames = FunctionDefNode.parseParams(mp[1]);
ArrayList<Expression> paramExprs = new ArrayList<>();
if (paramTypeNames.length == params.size()) {
for (int i = 0; i < params.size(); i++) {
String paramName = params.get(i);
String paramTypeName = paramTypeNames[i];
Type paramTypeCanonicalName = parseType(FunctionDefNode.getType(paramTypeName, null).getCanonicalName());
Expression param = new CastExpr(paramTypeCanonicalName, new MethodCallExpr(null, "coerceTo", new NodeList<>(new ClassExpr(paramTypeCanonicalName), new MethodCallExpr(new NameExpr("feelExprCtx"), "getValue", new NodeList<>(new StringLiteralExpr(paramName))))));
paramExprs.add(param);
}
return new MethodCallExpr(new NameExpr(className), methodName, new NodeList<>(paramExprs));
} else {
throw new FEELCompilationError(Msg.createMessage(Msg.ERROR_RESOLVING_EXTERNAL_FUNCTION_AS_DEFINED_BY, methodSignature));
}
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
Aggregations