public List<FunctionDef> getFunctions(String functionName) { return registry.stream() .filter(functionDef -> functionDef.getName().equals(functionName)) .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); }
public FunctionDef build() { return new FunctionDef(functionName, params); } }
private void initParams(String function, List<String> paramValues) { removeParams(); Map<Integer, String> paramValue = new HashMap<>(); if (paramValues != null) { for (int i = 0; i < paramValues.size(); i++) { paramValue.put(i, paramValues.get(i)); } } FunctionDef functionDef = functionSearchService.getFunction(function); ParamDef paramDef; for (int i = 1; i < functionDef.getParams().size(); i++) { paramDef = functionDef.getParams().get(i); ConditionParamPresenter param = newParamPresenter(); currentParams.add(param); param.setName(functionNamingService.getParamName(functionDef.getName(), paramDef.getName())); param.setHelp(functionNamingService.getParamHelp(functionDef.getName(), paramDef.getName())); param.setValue(paramValue.get(i)); view.addParam(param.getView().getElement()); param.setOnChangeCommand(this::onParamChange); } }
protected List<FunctionDef> findAvailableFunctions(Class<?> clazz, ClassLoader classLoader) { List<FunctionDef> result = new ArrayList<>(); Class<?> paramClass; for (FunctionDef functionDef : FunctionsRegistry.getInstance().getFunctions()) { try { paramClass = classLoader.loadClass(functionDef.getParams().get(0).getType()); if (paramClass.isAssignableFrom(clazz)) { result.add(functionDef); } } catch (ClassNotFoundException e) { LOGGER.warn("Uncommon error, internal function param type was not resolved: " + functionDef.getParams().get(0).getType()); } } return result; }
private Condition parse(FunctionDef functionDef) throws ParseException { parseReturnSentence(); functionName = parseFunctionName(); functionName = functionName.substring(KIE_FUNCTIONS.length()); parseFunctionOpen(); Condition condition = new Condition(functionName); String param; String[] variableParam; boolean first = true; for (ParamDef ignored : functionDef.getParams()) { if (first) { variableParam = parseVariableParam(); param = variableParam[0] + (variableParam[1] != null ? ("." + variableParam[1]) : ""); first = false; } else { parseParamDelimiter(); param = parseStringParameter(); } condition.addParam(param); } //all parameters were consumed parseFunctionClose(); parseSentenceClose(); return condition; }
private void setFunctions(List<FunctionDef> functions) { currentFunctions = functions.stream().collect(Collectors.toMap(FunctionDef::getName, Function.identity())); options = functions.stream().collect(Collectors.toMap(FunctionDef::getName, functionDef -> functionNamingService.getFunctionName(functionDef.getName()))); } }
@Test public void testFunctionDefEqualsAndHashCode() { TestCaseBuilder.newTestCase() .addTrueCase(new FunctionDef(null), new FunctionDef(null)) .addTrueCase(new FunctionDef(null, null), new FunctionDef(null, null)) .addTrueCase(new FunctionDef("name"), new FunctionDef("name")) .addTrueCase(new FunctionDef("name", null), new FunctionDef("name", null)) .addTrueCase(new FunctionDef("name", Arrays.asList(new ParamDef("param1", "type1"))), new FunctionDef("name", Arrays.asList(new ParamDef("param1", "type1")))) .addFalseCase(new FunctionDef("name"), new FunctionDef(null)) .addFalseCase(new FunctionDef("name", null), new FunctionDef(null, null)) .addFalseCase(new FunctionDef("name", new ArrayList<>()), new FunctionDef("name", null)) .addFalseCase(new FunctionDef("name"), new FunctionDef("name1")) .addFalseCase(new FunctionDef("name", Arrays.asList(new ParamDef("param1", "type1"))), new FunctionDef("name1", new ArrayList<>())) .addFalseCase(new FunctionDef("name", Arrays.asList(new ParamDef("param1", "type1"))), new FunctionDef("name", Arrays.asList(new ParamDef("param2", "type1")))) .addFalseCase(new FunctionDef("name", Arrays.asList(new ParamDef("param1", "type1"))), new FunctionDef("name", Arrays.asList(new ParamDef("param1", "type2")))) .test(); }
private String parseFunctionName() throws ParseException { int index = nextNonBlank(); if (index < 0 || !expression.startsWith(KIE_FUNCTIONS, index)) { throw new ParseException(errorMessage(FUNCTION_CALL_NOT_FOUND_ERROR), parseIndex); } for (FunctionDef functionDef : FunctionsRegistry.getInstance().getFunctions()) { if (expression.startsWith(KIE_FUNCTIONS + functionDef.getName(), index)) { functionName = KIE_FUNCTIONS + functionDef.getName(); break; } } if (functionName == null) { throw new ParseException(errorMessage(VALID_FUNCTION_CALL_NOT_FOUND_ERROR, functionNames()), parseIndex); } setParseIndex(index + functionName.length()); return functionName; }
private void testFindAvailableFunctions(String clazz, String[] expectedFunctions) { List<FunctionDef> functionDefs = service.findAvailableFunctions(path, clazz); assertEquals(functionDefs.size(), expectedFunctions.length); for (String expectedFunction : expectedFunctions) { assertTrue(functionDefs.stream() .anyMatch(functionDef -> expectedFunction.equals(functionDef.getName()))); } }