Search in sources :

Example 1 with InvalidFunctionDescriptorException

use of org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException in project legend-pure by finos.

the class FunctionDescriptorToId method execute.

@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException {
    String functionDescriptor = Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport).getName();
    String id = null;
    try {
        id = FunctionDescriptor.functionDescriptorToId(functionDescriptor);
    } catch (InvalidFunctionDescriptorException e) {
        throw new PureExecutionException(functionExpressionToUseInStack.getSourceInformation(), "Invalid function descriptor: " + functionDescriptor, e);
    }
    return ValueSpecificationBootstrap.newStringLiteral(this.repository, id, processorSupport);
}
Also used : InvalidFunctionDescriptorException(org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException)

Example 2 with InvalidFunctionDescriptorException

use of org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException in project legend-pure by finos.

the class TestFunctionDescriptor method testGetFunctionByDescriptor.

@Test
public void testGetFunctionByDescriptor() throws InvalidFunctionDescriptorException {
    PureRuntime runtime = new PureRuntimeBuilder(new PureCodeStorage(Paths.get("..", "pure-code", "local"), new ClassLoaderCodeStorage(CodeRepository.newPlatformCodeRepository()))).build();
    runtime.loadAndCompileCore();
    runtime.createInMemorySource("fromString.pure", "function test1():Integer[1]\n" + "{\n" + "    5\n" + "}\n" + "function pkg1::pkg2::test2(s:String[0..5], i:Integer[*], j:Integer[0..*]):Date[2]\n" + "{\n" + "    [%2014, %2013]\n" + "}\n");
    runtime.compile();
    ProcessorSupport processorSupport = runtime.getProcessorSupport();
    CoreInstance expected;
    CoreInstance actual;
    // Test functions
    expected = processorSupport.package_getByUserPath("test1__Integer_1_");
    Assert.assertNotNull(expected);
    actual = FunctionDescriptor.getFunctionByDescriptor("test1():Integer[1]", processorSupport);
    Assert.assertSame(expected, actual);
    actual = FunctionDescriptor.getFunctionByDescriptor("test1():Integer[1..1]", processorSupport);
    Assert.assertSame(expected, actual);
    expected = processorSupport.package_getByUserPath("pkg1::pkg2::test2_String_$0_5$__Integer_MANY__Integer_MANY__Date_2_");
    Assert.assertNotNull(expected);
    actual = FunctionDescriptor.getFunctionByDescriptor("pkg1::pkg2::test2(String[0..5], Integer[*], Integer[*]):Date[2]", processorSupport);
    Assert.assertSame(expected, actual);
    actual = FunctionDescriptor.getFunctionByDescriptor("pkg1::pkg2::test2(String[0..5], Integer[0..*], Integer[0..*]):Date[2..2]", processorSupport);
    Assert.assertSame(expected, actual);
    // Real functions
    // expected = processorSupport.package_getByUserPath("meta::pure::functions::collection::get_T_MANY__String_1__T_$0_1$_");
    // Assert.assertNotNull(expected);
    // actual = FunctionDescriptor.getFunctionByDescriptor("meta::pure::functions::collection::get(T[*], String[1]):T[0..1]", processorSupport);
    // Assert.assertSame(expected, actual);
    expected = processorSupport.package_getByUserPath("meta::pure::functions::string::toString_Any_1__String_1_");
    Assert.assertNotNull(expected);
    actual = FunctionDescriptor.getFunctionByDescriptor("meta::pure::functions::string::toString(Any[1]):String[1]", processorSupport);
    Assert.assertSame(expected, actual);
    expected = processorSupport.package_getByUserPath("meta::pure::functions::string::plus_String_MANY__String_1_");
    Assert.assertNotNull(expected);
    actual = FunctionDescriptor.getFunctionByDescriptor("meta::pure::functions::string::plus(String[*]):String[1]", processorSupport);
    Assert.assertSame(expected, actual);
}
Also used : PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) Test(org.junit.Test)

Example 3 with InvalidFunctionDescriptorException

use of org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException in project legend-pure by finos.

the class TestFunctionDescriptor method testGetFunctionDescriptor.

@Test
public void testGetFunctionDescriptor() throws InvalidFunctionDescriptorException {
    PureRuntime runtime = new PureRuntimeBuilder(new PureCodeStorage(Paths.get("..", "pure-code", "local"), new ClassLoaderCodeStorage(CodeRepository.newPlatformCodeRepository()))).build();
    runtime.loadAndCompileCore();
    runtime.createInMemorySource("fromString.pure", "native function meta::pure::functions::string::length(str:String[1]):Integer[1];\n" + "function pkg1::pkg2::pkg3::func1(string1:String[1], string2:String[1]):String[1]\n" + "{\n" + "    $string1 + $string2 + ' (from private)'\n" + "}\n" + "\n" + "function pkg1::func2(s:String[1]):Integer[1]\n" + "{\n" + "    pkg1::pkg2::pkg3::func1($s, ' from public')->length()\n" + "}\n" + "\n" + "function func3():Boolean[1]\n" + "{\n" + "    false\n" + "}\n" + "\n" + "function func4<T|m>(t:T[m]):T[m]\n" + "{\n" + "    $t\n" + "}");
    runtime.compile();
    ProcessorSupport processorSupport = runtime.getProcessorSupport();
    CoreInstance func1 = FunctionDescriptor.getFunctionByDescriptor("pkg1::pkg2::pkg3::func1(String[1], String[1]):String[1]", processorSupport);
    Assert.assertNotNull(func1);
    Assert.assertEquals("pkg1::pkg2::pkg3::func1(String[1], String[1]):String[1]", FunctionDescriptor.getFunctionDescriptor(func1, processorSupport));
    CoreInstance func2 = FunctionDescriptor.getFunctionByDescriptor("pkg1::func2(String[1]):Integer[1]", processorSupport);
    Assert.assertNotNull(func2);
    Assert.assertEquals("pkg1::func2(String[1]):Integer[1]", FunctionDescriptor.getFunctionDescriptor(func2, processorSupport));
    CoreInstance func3 = FunctionDescriptor.getFunctionByDescriptor("func3():Boolean[1]", processorSupport);
    Assert.assertNotNull(func3);
    Assert.assertEquals("func3():Boolean[1]", FunctionDescriptor.getFunctionDescriptor(func3, processorSupport));
    CoreInstance func4 = FunctionDescriptor.getFunctionByDescriptor("func4(T[m]):T[m]", processorSupport);
    Assert.assertNotNull(func4);
    Assert.assertEquals("func4(T[m]):T[m]", FunctionDescriptor.getFunctionDescriptor(func4, processorSupport));
}
Also used : PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) Test(org.junit.Test)

Aggregations

ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)2 ClassLoaderCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage)2 PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)2 PureRuntimeBuilder (org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder)2 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)2 Test (org.junit.Test)2 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)1 InvalidFunctionDescriptorException (org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException)1