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);
}
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);
}
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));
}
Aggregations