use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path in project legend-pure by finos.
the class AbstractTestMatch method testMatchPureObjectTypeFail.
@Test
public void testMatchPureObjectTypeFail() {
Pattern expectedInfo = Pattern.compile("^Match failure: (\\W*\\d*\\w*)\\(?\\d*\\)? instanceOf PathElement$");
assertExpressionRaisesPureException(expectedInfo, "^meta::pure::metamodel::path::PathElement() ->match([i:Integer[1] | $i])");
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path in project legend-pure by finos.
the class CompiledProcessorSupport method package_getByUserPath.
@Override
public CoreInstance package_getByUserPath(String path) {
// Check top level elements
if (M3Paths.Root.equals(path) || "::".equals(path)) {
return this.metadataAccessor.getPackage(M3Paths.Root);
}
if (M3Paths.Package.equals(path)) {
return this.metadataAccessor.getClass(M3Paths.Package);
}
if (PrimitiveUtilities.isPrimitiveTypeName(path)) {
return this.metadataAccessor.getPrimitiveType(path);
}
int lastColon = path.lastIndexOf(':');
if (lastColon == -1) {
// An element in Root - probably a package
try {
CoreInstance element = this.metadataAccessor.getPackage(M3Paths.Root + "::" + path);
if (element != null) {
return element;
}
} catch (Exception ignore) {
// Perhaps it's not a package? Fall back to general method
}
// Get the Root package, then search its children
Package pkg = this.metadataAccessor.getPackage(M3Paths.Root);
return pkg._children().detect(c -> path.equals(c.getName()));
}
// Perhaps the element is a class?
try {
CoreInstance element = this.metadataAccessor.getClass(M3Paths.Root + "::" + path);
if (element != null) {
return element;
}
} catch (Exception ignore) {
// Perhaps it's not a class? Fall back to general method
}
// Get the element's package, then search in the package
Package pkg;
try {
pkg = this.metadataAccessor.getPackage(M3Paths.Root + "::" + path.substring(0, lastColon - 1));
} catch (Exception ignore) {
pkg = null;
}
if (pkg == null) {
// Package doesn't exist, so the element
return null;
}
// Search the children of the package
String name = path.substring(lastColon + 1);
return pkg._children().detect(c -> name.equals(c.getName()));
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path in project legend-pure by finos.
the class JavaClassLoaderSourceCodeGenerator method gen.
public static void gen(long start, Path filePath, String name, MutableList<CompiledExtension> extensions) {
RichIterable<CodeRepository> repositoriesForCompilation = Lists.fixedSize.of(CodeRepository.newPlatformCodeRepository());
PureCodeStorage codeStorage = new PureCodeStorage(null, new ClassLoaderCodeStorage(repositoriesForCompilation));
ClassLoaderPureGraphCache graphCache = new ClassLoaderPureGraphCache();
PureRuntime runtime = new PureRuntimeBuilder(codeStorage).withCache(graphCache).setTransactionalByDefault(false).buildAndTryToInitializeFromCache();
if (!runtime.isInitialized()) {
CacheState cacheState = graphCache.getCacheState();
if (cacheState != null) {
String lastStackTrace = cacheState.getLastStackTrace();
if (lastStackTrace != null) {
System.out.println("Cache initialization failure: " + lastStackTrace);
}
}
System.out.println("Initialization from caches failed - compiling from scratch");
runtime.reset();
runtime.loadAndCompileCore();
runtime.loadAndCompileSystem();
}
System.out.format("Finished Pure initialization (%.6fs)%n", (System.nanoTime() - start) / 1_000_000_000.0);
JavaSourceCodeGenerator javaSourceCodeGenerator = new JavaSourceCodeGenerator(runtime.getProcessorSupport(), runtime.getCodeStorage(), true, filePath, false, extensions, name, JavaPackageAndImportBuilder.externalizablePackage());
javaSourceCodeGenerator.generateCode();
javaSourceCodeGenerator.generatePureCoreHelperClasses(new ProcessorContext(runtime.getProcessorSupport(), false));
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path in project legend-pure by finos.
the class InstanceValueUnbind method run.
@Override
public void run(InstanceValue instanceValue, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (CoreInstance value : instanceValue._valuesCoreInstance()) {
if (!(value instanceof Property)) {
((UnbindState) state).freeProcessedAndValidated(value);
}
Shared.cleanUpReferenceUsage(value, instanceValue, processorSupport);
// TODO replace call to Instance.instanceOf once we resolve issue with Path not being available in this module - circular dependency
if (value instanceof LambdaFunction || value instanceof SimpleFunctionExpression || Instance.instanceOf(value, M3Paths.Path, processorSupport) || value instanceof RootRouteNode) {
matcher.fullMatch(value, state);
} else if (Instance.instanceOf(value, M3Paths.RootGraphFetchTree, processorSupport)) {
matcher.fullMatch(value, state);
} else if (value instanceof KeyExpression) {
((UnbindState) state).freeProcessedAndValidated(modelRepository.newBooleanCoreInstance(((KeyExpression) value)._add()));
((UnbindState) state).freeProcessedAndValidated(((KeyExpression) value)._key());
matcher.fullMatch(((KeyExpression) value)._expression(), state);
} else {
Shared.cleanImportStub(value, processorSupport);
}
if (value instanceof ValueSpecification) {
matcher.fullMatch(value, state);
((ValueSpecification) value)._usageContextRemove();
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path in project legend-pure by finos.
the class NavigationGraphBuilder method visitDefinition.
@Override
public CoreInstance visitDefinition(DefinitionContext ctx) {
GenericType owner;
MutableList<PathElement> props = FastList.newList();
Token firstChar = ctx.SEPARATOR().getSymbol();
owner = visitGenericTypeBlock(ctx.genericType());
String name = ctx.name() != null ? ctx.name().VALID_STRING().getText() : "";
if (ctx.propertyWithParameters() != null) {
for (PropertyWithParametersContext propertyWithParametersContext : ctx.propertyWithParameters()) {
visitPropertyWithParametersBlock(propertyWithParametersContext, props, firstChar);
}
}
Token end = ctx.EOF().getSymbol();
if (props.isEmpty()) {
throw new PureParserException(this.sourceInformation.getPureSourceInformation(firstChar, firstChar, end), "A path must contain at least one navigation");
}
ClassInstance ppeType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Path);
Path propertyPath = (Path) this.repository.newAnonymousCoreInstance(this.sourceInformation.getPureSourceInformation(firstChar, firstChar, end), ppeType, true);
GenericType classifierGT = GenericTypeInstance.createPersistent(this.repository);
classifierGT._rawTypeCoreInstance(ppeType);
propertyPath._classifierGenericType(classifierGT);
propertyPath._start(owner);
propertyPath._name(name);
propertyPath._path(props);
return propertyPath;
}
Aggregations