use of org.finos.legend.pure.m3.coreinstance.CoreInstanceFactoryRegistry in project legend-pure by finos.
the class FunctionExecutionCompiled method init.
@Override
public void init(PureRuntime runtime, Message message) {
this.runtime = runtime;
this.repository = runtime.getModelRepository();
this.context = runtime.getContext();
this.sourceRegistry = runtime.getSourceRegistry();
this.javaCompilerEventHandler = new JavaCompilerEventHandler(runtime, message, this.includePureStackTrace, this.javaCompilerEventObserver, this.extensions);
this.metadataCompilerEventHandler = new MetadataEagerCompilerEventHandler(runtime.getModelRepository(), (MetadataEventObserver) this.javaCompilerEventObserver, message, runtime.getProcessorSupport());
runtime.addEventHandler(this);
runtime.getIncrementalCompiler().addCompilerEventHandler(this.javaCompilerEventHandler);
runtime.getIncrementalCompiler().addCompilerEventHandler(this.metadataCompilerEventHandler);
initializeFromRuntimeState();
this.extraSupportedTypes = runtime.getIncrementalCompiler().getParserLibrary().getParsers().flatCollect(CoreInstanceFactoriesRegistry::getCoreInstanceFactoriesRegistry).flatCollect(CoreInstanceFactoryRegistry::allManagedTypes).toSet();
}
use of org.finos.legend.pure.m3.coreinstance.CoreInstanceFactoryRegistry in project legend-pure by finos.
the class M3ToJavaGenerator method createFactory.
private void createFactory(MapIterable<String, CoreInstance> packageToCoreInstance, SetIterable<CoreInstance> m3Enumerations) {
String factoryName = this.factoryNamePrefix + "CoreInstanceFactoryRegistry";
RichIterable<CoreInstance> allInstances = m3Enumerations.toList().withAll(packageToCoreInstance.valuesView());
String result = "package org.finos.legend.pure.m3.coreinstance;\n" + "\n" + "import org.eclipse.collections.api.map.MutableMap;\n" + "import org.eclipse.collections.api.map.primitive.MutableIntObjectMap;\n" + "import org.eclipse.collections.impl.map.mutable.UnifiedMap;\n" + "import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap;\n" + "import org.eclipse.collections.api.set.SetIterable;\n" + "import org.eclipse.collections.impl.factory.Sets;\n" + packageToCoreInstance.keysView().collect(_package -> "import " + _package + ";").makeString("\n") + packageToCoreInstance.keysView().collect(_package -> "import " + _package.substring(0, _package.lastIndexOf("Instance")) + ";").makeString("\n") + "\n" + "import org.finos.legend.pure.m4.coreinstance.CoreInstance;\n" + "import org.finos.legend.pure.m4.coreinstance.factory.CoreInstanceFactory;\n" + "\n" + "\n" + "public class " + factoryName + "\n" + "{\n" + " public static final CoreInstanceFactoryRegistry REGISTRY;\n" + " public static final SetIterable<String> ALL_PATHS = Sets.mutable.of" + allInstances.collect(object -> "\"" + getUserObjectPathForPackageableElement(object, false).makeString("::") + "\"").makeString("(", ",", ")") + ";\n\n" + " static\n" + " {\n" + " MutableMap<String, java.lang.Class> interfaceByPath = UnifiedMap.newMap(" + packageToCoreInstance.size() + ");\n" + allInstances.collect(object -> {
String classString = isEnum(object) ? "org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum" : Objects.requireNonNull(object).getName();
return " interfaceByPath.put(\"" + getUserObjectPathForPackageableElement(object, false).makeString("::") + "\", " + classString + ".class);";
}).makeString("\n") + "\n";
if (this.generateTypeFactoriesById) {
result += " MutableIntObjectMap<CoreInstanceFactory> typeFactoriesById = IntObjectHashMap.newMap();\n" + allInstances.collect(object -> {
String classString = isEnum(object) ? "org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum" : Objects.requireNonNull(object).getName();
return " typeFactoriesById.put(" + object.getSyntheticId() + ", " + classString + "Instance.FACTORY);";
}).makeString("", "\n", "\n");
}
result += " MutableMap<String, CoreInstanceFactory> typeFactoriesByPath = UnifiedMap.newMap(" + packageToCoreInstance.size() + ");\n" + allInstances.collect(object -> {
String classString = isEnum(object) ? "org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum" : Objects.requireNonNull(object).getName();
return " typeFactoriesByPath.put(" + getUserObjectPathForPackageableElement(object, false).makeString("\"", "::", "\"") + ", " + classString + "Instance.FACTORY);";
}).makeString("", "\n", "\n") + " REGISTRY = new CoreInstanceFactoryRegistry(" + (this.generateTypeFactoriesById ? "typeFactoriesById.toImmutable()" : "new IntObjectHashMap<CoreInstanceFactory>().toImmutable()") + ", typeFactoriesByPath.toImmutable(), interfaceByPath.toImmutable());\n" + " }\n" + " public static java.lang.Class getClassForPath(String path)\n" + " {\n" + " return REGISTRY.getClassForPath(path);\n" + " }\n" + "}\n";
try {
Path p = Paths.get(this.outputDir + ROOT_PACKAGE.replace(".", "/") + "/" + factoryName + ".java");
Files.write(p, result.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.finos.legend.pure.m3.coreinstance.CoreInstanceFactoryRegistry in project legend-pure by finos.
the class AbstractPureTestWithCoreCompiled method setUpRuntime.
// @Before
public static final void setUpRuntime(FunctionExecution execution, MutableCodeStorage codeStorage, CoreInstanceFactoryRegistry registry, RuntimeOptions options, Pair<String, String> extra, RichIterable<? extends CodeRepository> repositories) {
codeRepositories = repositories;
functionExecution = execution;
runtime = new PureRuntimeBuilder(codeStorage).withRuntimeStatus(getPureRuntimeStatus()).withFactoryRegistryOverride(registry).setTransactionalByDefault(isTransactionalByDefault()).withOptions(options).build();
functionExecution.init(runtime, new Message(""));
runtime.loadAndCompileCore();
if (extra != null) {
runtime.createInMemoryAndCompile(extra);
}
repository = runtime.getModelRepository();
context = runtime.getContext();
processorSupport = functionExecution.getProcessorSupport() == null ? runtime.getProcessorSupport() : functionExecution.getProcessorSupport();
if (functionExecution.getConsole() != null) {
functionExecution.getConsole().enableBufferLines();
}
}
Aggregations