use of org.finos.legend.pure.m3.serialization.runtime.Message in project legend-pure by finos.
the class ConcreteFunctionDefinitionNameProcessor method process.
public static void process(Function<?> function, ModelRepository repository, ProcessorSupport processorSupport) throws PureCompilationException {
Package parent = function._package();
if (parent != null) {
// Make sure we have a unique name for overloaded functions.
String signature = getSignatureAndResolveImports(function, repository, processorSupport);
parent._childrenRemove(function);
function.setName(signature);
parent._childrenAdd(function);
if (function._name() == null) {
function._name(signature);
}
if (parent._children().count(c -> signature.equals(c.getName())) > 1) {
ListIterable<SourceInformation> sourceInfos = parent._children().collectIf(c -> signature.equals(c.getName()), CoreInstance::getSourceInformation, Lists.mutable.empty()).sortThis();
String pkg = PackageableElement.getUserPathForPackageableElement(parent);
if (M3Paths.Root.equals(pkg)) {
pkg = "::";
}
StringBuilder message = new StringBuilder("The function '").append(signature).append("' is defined more than once in the package '").append(pkg).append("' at: ");
boolean first = true;
for (SourceInformation sourceInfo : sourceInfos) {
if (first) {
first = false;
} else {
message.append(", ");
}
message.append(sourceInfo.getSourceId()).append(" (line:").append(sourceInfo.getLine()).append(" column:").append(sourceInfo.getColumn()).append(')');
}
throw new PureCompilationException(function.getSourceInformation(), message.toString());
}
}
}
use of org.finos.legend.pure.m3.serialization.runtime.Message in project legend-pure by finos.
the class AbstractTestCast method checkInvalidTypeCastErrorMessage.
public void checkInvalidTypeCastErrorMessage(Exception e, String message, int line, int column) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
Assert.assertEquals(message, pe.getInfo());
SourceInformation sourceInfo = pe.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(line, sourceInfo.getLine());
Assert.assertEquals(column, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m3.serialization.runtime.Message in project legend-pure by finos.
the class FunctionExecutionCompiled method executeFunction.
private Object executeFunction(CoreInstance functionDefinition, ListIterable<? extends CoreInstance> coreInstances, CompiledExecutionSupport executionSupport, ClassLoader cl, ProcessorSupport processorSupport) {
// Manage Parameters ----------------------------
ListIterable<? extends CoreInstance> parameters = Instance.getValueForMetaPropertyToManyResolved(processorSupport.function_getFunctionType(functionDefinition), M3Properties.parameters, processorSupport);
Class[] paramClasses = new Class[parameters.size()];
Object[] params = new Object[parameters.size()];
Metadata metamodel = this.metadataCompilerEventHandler.getMetadata();
int i = 0;
if (parameters.size() != coreInstances.size()) {
StringBuilder builder = new StringBuilder();
org.finos.legend.pure.m3.navigation.function.Function.print(builder, functionDefinition, processorSupport);
String message = "Error executing the function:" + builder + ". Mismatch between the number of function parameters (" + parameters.size() + ") and the number of supplied arguments (" + coreInstances.size() + ")";
throw new PureExecutionException(message);
}
for (CoreInstance param : parameters) {
Object val = GraphSerializer.valueSpecToJavaObject(coreInstances.get(i), this.context, this.getProcessorSupport(), metamodel);
CoreInstance paramMult = Instance.getValueForMetaPropertyToOneResolved(param, M3Properties.multiplicity, processorSupport);
if (Multiplicity.isToOne(paramMult, true)) {
String t = TypeProcessor.typeToJavaPrimitiveSingle(Instance.getValueForMetaPropertyToOneResolved(param, M3Properties.genericType, processorSupport), processorSupport);
paramClasses[i] = CompiledSupport.convertFunctionTypeStringToClass(t, cl);
if (val instanceof MutableList) {
MutableList valList = (MutableList) val;
if (valList.size() != 1) {
throw new RuntimeException("Expected exactly one value, found " + valList.size());
}
val = valList.get(0);
}
} else if (Multiplicity.isToOne(paramMult, false)) {
String className = TypeProcessor.typeToJavaObjectSingle(Instance.getValueForMetaPropertyToOneResolved(param, M3Properties.genericType, processorSupport), false, processorSupport);
paramClasses[i] = CompiledSupport.loadClass(className, cl);
if (val instanceof MutableList) {
MutableList valList = (MutableList) val;
switch(valList.size()) {
case 0:
{
val = null;
break;
}
case 1:
{
val = valList.get(0);
break;
}
default:
{
throw new RuntimeException("Expected at most one value, found " + valList.size());
}
}
}
} else {
paramClasses[i] = RichIterable.class;
if (!(val instanceof MutableList)) {
val = FastList.newListWith(val);
}
}
params[i] = val;
i++;
}
return CompiledSupport.executeFunction(functionDefinition, paramClasses, params, executionSupport);
// -----------------------------------------------
}
use of org.finos.legend.pure.m3.serialization.runtime.Message in project legend-pure by finos.
the class TestGraphIsSerialized method testInitializedFromGraphLoaderSerialization.
@Test
public void testInitializedFromGraphLoaderSerialization() {
PureRuntime runtime = new PureRuntimeBuilder(getCodeStorage()).buildAndInitialize();
PureGraphCache cache = new MemoryGraphLoaderPureGraphCache();
cache.setPureRuntime(runtime);
cache.cacheRepoAndSources();
runtime = new PureRuntimeBuilder(getCodeStorage()).withCache(cache).buildAndTryToInitializeFromCache();
new FunctionExecutionCompiledBuilder().build().init(runtime, new Message(""));
Assert.assertTrue(cache.getCacheState().getLastStackTrace(), runtime.isInitialized());
assertAllInstancesMarkedSerialized(runtime);
}
use of org.finos.legend.pure.m3.serialization.runtime.Message in project legend-pure by finos.
the class TestGraphIsSerialized method testInitializedFromM4Serialization.
@Test
public void testInitializedFromM4Serialization() {
PureRuntime runtime = new PureRuntimeBuilder(getCodeStorage()).buildAndInitialize();
PureGraphCache cache = new MemoryPureGraphCache();
cache.setPureRuntime(runtime);
cache.cacheRepoAndSources();
runtime = new PureRuntimeBuilder(getCodeStorage()).withCache(cache).buildAndTryToInitializeFromCache();
new FunctionExecutionCompiledBuilder().build().init(runtime, new Message(""));
Assert.assertTrue(cache.getCacheState().getLastStackTrace(), runtime.isInitialized());
assertAllInstancesMarkedSerialized(runtime);
}
Aggregations