Search in sources :

Example 16 with FunctionDefinition

use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.

the class OsgiFunctionFactory method getInstance.

@Override
public FunctionInterface getInstance(final ClassLoader cl, final String functionName) {
    FunctionDefinition fd = (FunctionDefinition) getComponent(functionName, "functionName", FunctionDefinition.class);
    if (fd == null) {
        logger.debug("OSGi function resolution for function: {} failed, going old school.", functionName);
        return super.getInstance(cl, functionName);
    }
    FunctionInterface osgiResolution = fd.getFunctionInstance();
    if (osgiResolution == null) {
        logger.debug("OSGi function resolution for function: {} failed, going old school.", functionName);
        return super.getInstance(cl, functionName);
    }
    return osgiResolution;
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition)

Example 17 with FunctionDefinition

use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.

the class TestCompiledExpression method testMultiArgFunction.

@Test
public void testMultiArgFunction() throws Exception {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "blib", "bleb", "blab");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("SingleValueQuery", fd);
    String expression = "SingleValueQuery( 'aap','noot' )";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    List<String> problems = new ArrayList<>();
    cp.Expression();
    cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Example 18 with FunctionDefinition

use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.

the class TestCompiledExpression method testNestedNamedParams.

@Test
public void testNestedNamedParams() throws Exception {
    FunctionInterface testFunction = new ParameterNamesFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ParameterNamesFunction", fd);
    String expression = "ParameterNamesFunction(aap=1+1,noot=2+2)";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    List<String> problems = new ArrayList<>();
    cp.Expression();
    ContextExpression ss = cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
    Assert.assertEquals("aap,noot", ss.apply().value);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) ParameterNamesFunction(com.dexels.navajo.expression.compiled.ParameterNamesFunction) Test(org.junit.Test)

Example 19 with FunctionDefinition

use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.

the class TestCompiledExpression method testEmptyFunctionCall.

@Test
public void testEmptyFunctionCall() throws ParseException {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "blib", "bleb", "blab");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("addtest", fd);
    String expression = "addtest()";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    cp.Expression();
    List<String> problems = new ArrayList<>();
    ContextExpression ss = cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
    Operand o = ss.apply();
    Assert.assertEquals("monkey", o.value);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Example 20 with FunctionDefinition

use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.

the class TestCompiledExpression method testNestedNamedFunction.

@Test
public void testNestedNamedFunction() throws Exception {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("MysteryFunction", fd);
    String expression = "MysteryFunction(eep=MysteryFunction('blib','blob'), 'aap','noot' )";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    List<String> problems = new ArrayList<>();
    cp.Expression();
    cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Aggregations

FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)20 Test (org.junit.Test)13 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)10 Operand (com.dexels.navajo.document.Operand)8 ArrayList (java.util.ArrayList)7 StringReader (java.io.StringReader)5 AddTestFunction (com.dexels.navajo.expression.compiled.AddTestFunction)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 ServiceReference (org.osgi.framework.ServiceReference)4 XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)3 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)3 Before (org.junit.Before)2 BundleContext (org.osgi.framework.BundleContext)2 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)1 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)1 GiveMoneyTestFunction (com.dexels.navajo.expression.compiled.GiveMoneyTestFunction)1 GivePercentageTestFunction (com.dexels.navajo.expression.compiled.GivePercentageTestFunction)1 ParameterNamesFunction (com.dexels.navajo.expression.compiled.ParameterNamesFunction)1 FunctionFactoryInterface (com.dexels.navajo.functions.util.FunctionFactoryInterface)1