Search in sources :

Example 1 with Path

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])");
}
Also used : Pattern(java.util.regex.Pattern) PureExpressionTest(org.finos.legend.pure.m3.tests.function.base.PureExpressionTest) Test(org.junit.Test)

Example 2 with Path

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()));
}
Also used : ValCoreInstance(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ValCoreInstance) BaseCoreInstance(org.finos.legend.pure.m3.coreinstance.BaseCoreInstance) ReflectiveCoreInstance(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ReflectiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) Package(org.finos.legend.pure.m3.coreinstance.Package) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException)

Example 3 with Path

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));
}
Also used : PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) CodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository) ClassLoaderPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.ClassLoaderPureGraphCache) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) CacheState(org.finos.legend.pure.m3.serialization.runtime.cache.CacheState) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)

Example 4 with Path

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();
        }
    }
}
Also used : ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) KeyExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.lang.KeyExpression) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)

Example 5 with Path

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;
}
Also used : Path(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) PropertyWithParametersContext(org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser.PropertyWithParametersContext) PureParserException(org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException) Token(org.antlr.v4.runtime.Token) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)

Aggregations

CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)18 IOException (java.io.IOException)11 RichIterable (org.eclipse.collections.api.RichIterable)10 RepositoryCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage)10 PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)10 StreamingOutput (javax.ws.rs.core.StreamingOutput)9 MutableCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)9 MutableRepositoryCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage)9 Path (javax.ws.rs.Path)8 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)8 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)6 Map (java.util.Map)5 GET (javax.ws.rs.GET)5 MutableList (org.eclipse.collections.api.list.MutableList)5 PropertyPathElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement)5 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)5 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)5 CodeRepository (org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository)5 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)5 Path (java.nio.file.Path)4