use of org.eclipse.vorto.mapping.engine.functions.IScriptEvaluator in project vorto by eclipse.
the class MappingSpecification method getScriptFunctions.
@Override
public FunctionLibrary getScriptFunctions(IScriptEvalProvider factory) {
FunctionLibrary library = new FunctionLibrary();
this.infoModel.getFunctionblocks().stream().forEach(property -> {
IMappedElement mappedElement = (IMappedElement) property.getType();
if (mappedElement.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
Stereotype functionsStereoType = mappedElement.getStereotype(STEREOTYPE_FUNCTIONS).get();
IScriptEvaluator evaluator = factory.createEvaluator(property.getName().toLowerCase());
functionsStereoType.getAttributes().keySet().stream().filter(functionName -> !functionName.equalsIgnoreCase(STEREOTYPE_NAMESPACE)).forEach(functionName -> evaluator.addScriptFunction(new ScriptClassFunction(functionName, functionsStereoType.getAttributes().get(functionName))));
library.addFunctions(evaluator.getFunctions());
}
});
return library;
}
use of org.eclipse.vorto.mapping.engine.functions.IScriptEvaluator in project vorto by eclipse.
the class SpecWithMultipleParams method getScriptFunctions.
@Override
public FunctionLibrary getScriptFunctions(IScriptEvalProvider evalProvider) {
FunctionLibrary library = new FunctionLibrary();
IScriptEvaluator evaluator = evalProvider.createEvaluator("button");
evaluator.addScriptFunction(new ScriptClassFunction("convertArray", "function convertArray(arrayValue,header) { return header+String.fromCharCode(arrayValue[0])}"));
library.addFunctions(evaluator.getFunctions());
return library;
}
Aggregations