Search in sources :

Example 1 with M3ProcessorSupport

use of org.finos.legend.pure.m3.navigation.M3ProcessorSupport in project legend-pure by finos.

the class FunctionExecutionCompiled method executeFunction.

private Object executeFunction(CoreInstance functionDefinition, ListIterable<? extends CoreInstance> arguments, CompiledExecutionSupport executionSupport) {
    ProcessorSupport processorSupport = new M3ProcessorSupport(this.context, this.repository);
    Object result;
    try {
        result = this.executeFunction(functionDefinition, arguments, executionSupport, this.javaCompilerEventHandler.getJavaCompiler().getClassLoader(), processorSupport);
    } catch (PureException pe) {
        // Rethrow as is to keep the original error
        throw pe;
    } catch (Exception e) {
        StringBuilder builder = new StringBuilder("Error executing ");
        try {
            org.finos.legend.pure.m3.navigation.function.Function.print(builder, functionDefinition, processorSupport);
        } catch (Exception ignore) {
            builder = new StringBuilder("Error executing ");
            builder.append(functionDefinition);
        }
        builder.append(". ");
        if (e.getMessage() != null) {
            builder.append(e.getMessage());
        }
        throw new RuntimeException(builder.toString(), e);
    }
    if (result == null) {
        result = Lists.immutable.empty();
    }
    return result;
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) PureExecutionStreamingException(org.finos.legend.pure.m3.exception.PureExecutionStreamingException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) IOException(java.io.IOException) PureException(org.finos.legend.pure.m4.exception.PureException)

Example 2 with M3ProcessorSupport

use of org.finos.legend.pure.m3.navigation.M3ProcessorSupport in project legend-pure by finos.

the class Loader method parseM3.

public static void parseM3(String code, ModelRepository repository, ParserLibrary library, ValidationType validationType, M3M4StateListener stateListener, Context context) {
    try {
        ListMultimap<Parser, CoreInstance> newInstancesByParser = new TopParser().parse(code, "fromString.pure", repository, library, stateListener, context, null);
        ListIterable<CoreInstance> newInstances = newInstancesByParser.valuesView().toList();
        updateStateFullContextCache(newInstances, context);
        ProcessorSupport processorSupport = new M3ProcessorSupport(context, repository);
        PostProcessor.process(newInstances, repository, library, new InlineDSLLibrary(), null, context, processorSupport, null, null);
        processExcludes(repository, processorSupport, stateListener);
        if (validationType == ValidationType.DEEP) {
            repository.validate(stateListener);
        }
        // Validate M3
        stateListener.startValidation();
        Validator.validateM3(newInstances, validationType, library, new InlineDSLLibrary(), new PureCodeStorage(null), repository, context, processorSupport);
        stateListener.finishedValidation();
    } catch (PureException exception) {
        String space = "      ";
        throw new RuntimeException(exception + " in\n" + space + code.replace("\n", "\n" + space), exception);
    }
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) TopParser(org.finos.legend.pure.m3.serialization.grammar.top.TopParser) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InlineDSLLibrary(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) Parser(org.finos.legend.pure.m3.serialization.grammar.Parser) TopParser(org.finos.legend.pure.m3.serialization.grammar.top.TopParser)

Example 3 with M3ProcessorSupport

use of org.finos.legend.pure.m3.navigation.M3ProcessorSupport in project legend-pure by finos.

the class GenericTypeWithXArguments method toString.

@Override
public String toString() {
    StringBuilder builder = new StringBuilder(64);
    print(builder, new M3ProcessorSupport(this.genericType.getRepository()));
    return builder.toString();
}
Also used : M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport)

Example 4 with M3ProcessorSupport

use of org.finos.legend.pure.m3.navigation.M3ProcessorSupport in project legend-pure by finos.

the class PrintPureRuntimeStatus method print.

private String print(CoreInstance coreInstance) {
    ProcessorSupport processorSupport = new M3ProcessorSupport(coreInstance.getRepository());
    if (Instance.instanceOf(coreInstance, M3Paths.InstanceValue, processorSupport)) {
        return "[InstanceValue: '" + coreInstance.getValueForMetaPropertyToMany(M3Properties.values).collect(new Function<CoreInstance, Object>() {

            @Override
            public String valueOf(CoreInstance coreInstance) {
                CoreInstance importStubId = coreInstance.getValueForMetaPropertyToOne(M3Properties.idOrPath);
                return importStubId == null ? "Lambda" : importStubId.getName();
            }
        }).makeString(", ") + "']";
    }
    if (Instance.instanceOf(coreInstance, M3Paths.FunctionDefinition, processorSupport)) {
        CoreInstance name = coreInstance.getValueForMetaPropertyToOne(M3Properties.functionName);
        return "[FunctionDefinition: '" + (name == null ? "Lambda" : name.getName()) + "']";
    }
    if (Instance.instanceOf(coreInstance, M3Paths.FunctionExpression, processorSupport)) {
        CoreInstance functionName = coreInstance.getValueForMetaPropertyToOne(M3Properties.functionName);
        CoreInstance propertyName = coreInstance.getValueForMetaPropertyToOne(M3Properties.propertyName);
        CoreInstance qualifiedPropertyName = coreInstance.getValueForMetaPropertyToOne(M3Properties.qualifiedPropertyName);
        SourceInformation sourceInformation = coreInstance.getSourceInformation();
        return "[FunctionExpression: " + (functionName == null ? propertyName == null ? qualifiedPropertyName == null ? "Unknown" : qualifiedPropertyName.getName() : propertyName.getName() : functionName.getName()) + ")]";
    }
    if (Instance.instanceOf(coreInstance, M3Paths.GenericType, processorSupport)) {
        CoreInstance id = coreInstance.getValueForMetaPropertyToOne(M3Properties.rawType).getValueForMetaPropertyToOne(M3Properties.idOrPath);
        return "[GenericType " + id + ")]";
    }
    return "[Unknown:'" + coreInstance + "']";
}
Also used : Function(org.eclipse.collections.api.block.function.Function) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 5 with M3ProcessorSupport

use of org.finos.legend.pure.m3.navigation.M3ProcessorSupport in project legend-pure by finos.

the class OperationGraphBuilder method visitMapping.

@Override
public String visitMapping(OperationParser.MappingContext ctx) {
    visitChildren(ctx);
    Token startToken = ctx.functionPath().qualifiedName().packagePath() == null ? ctx.functionPath().qualifiedName().identifier().getStart() : ctx.functionPath().qualifiedName().packagePath().getStart();
    String idOrPath = ctx.functionPath().qualifiedName().packagePath() == null ? ctx.functionPath().qualifiedName().identifier().getText() : LazyIterate.collect(ctx.functionPath().qualifiedName().packagePath().identifier(), RuleContext::getText).makeString("::") + "::" + ctx.functionPath().qualifiedName().identifier().getText();
    MutableList<String> parameters = Lists.mutable.empty();
    if (ctx.mergeParameters() != null) {
        OperationParser.MergeParametersContext mergeContext = ctx.mergeParameters();
        String lambdaText = "";
        if (mergeContext.setParameter() != null && mergeContext.setParameter().VALID_STRING() != null)
            ;
        {
            for (int i = 0; i < mergeContext.setParameter().VALID_STRING().size(); i++) {
                parameters.add(mergeContext.setParameter().VALID_STRING().get(i).getText());
            }
        }
        if (mergeContext.validationLambdaInstance() != null) {
            lambdaText = "{" + mergeContext.validationLambdaInstance().lambdaElement().get(0).getText() + "}";
        }
        final M3ProcessorSupport processorSupport = new M3ProcessorSupport(context, repository);
        final M3AntlrParser parser = new M3AntlrParser();
        final AntlrContextToM3CoreInstance.LambdaContext lambdaContext = new AntlrContextToM3CoreInstance.LambdaContext(setSourceInfo + '_' + (id == null ? "" : '_' + id) + "_MergeOP");
        TemporaryPureMergeOperationFunctionSpecification temporarySpecification = parser.parseMergeSpecification(lambdaText, lambdaContext, sourceInformation.getSourceName(), sourceInformation.getOffsetLine(), importId, repository, processorSupport, context);
        String processedMergeFunction = parser.process(temporarySpecification.validationExpression, context, processorSupport);
        ;
        return "^meta::pure::mapping::MergeOperationSetImplementation" + setSourceInfo + "(" + ((id == null) ? "" : ("    id = '" + id + "',")) + "    root = " + root + "," + "    operation = ^meta::pure::metamodel::import::ImportStub " + sourceInformation.getPureSourceInformation(startToken, startToken, ctx.functionPath().qualifiedName().identifier().getStop()).toM4String() + " (importGroup=system::imports::" + importId + ", idOrPath='" + idOrPath + "')," + "    parameters = [" + toSetImplementationContainers(parameters) + "]," + "    class = ^meta::pure::metamodel::import::ImportStub" + classSourceInfo + " (importGroup=system::imports::" + importId + ", idOrPath='" + classPath + "')," + "    parent = ^meta::pure::metamodel::import::ImportStub (importGroup=system::imports::" + importId + ", idOrPath='" + mappingPath + "'),\n" + "    validationFunction=^meta::pure::metamodel::function::LambdaFunction " + temporarySpecification.validationExpression.getSourceInformation().toM4String() + " (" + "                                                           classifierGenericType=^meta::pure::metamodel::type::generics::GenericType(rawType=meta::pure::metamodel::function::LambdaFunction, typeArguments=^meta::pure::metamodel::type::generics::GenericType(rawType = ^meta::pure::metamodel::type::FunctionType()))," + "                                                           expressionSequence=" + processedMergeFunction + ")" + ")";
    } else {
        if (ctx.parameters() != null && ctx.parameters().VALID_STRING() != null) {
            ListIterate.collect(ctx.parameters().VALID_STRING(), TerminalNode::getText, parameters);
        }
        return "^meta::pure::mapping::OperationSetImplementation" + setSourceInfo + "(" + ((this.id == null) ? "" : ("    id = '" + this.id + "',")) + "    root = " + this.root + "," + "    operation = ^meta::pure::metamodel::import::ImportStub " + this.sourceInformation.getPureSourceInformation(startToken, startToken, ctx.functionPath().qualifiedName().identifier().getStop()).toM4String() + " (importGroup=system::imports::" + this.importId + ", idOrPath='" + idOrPath + "')," + "    parameters = [" + toSetImplementationContainers(parameters) + "]," + "    class = ^meta::pure::metamodel::import::ImportStub" + this.classSourceInfo + " (importGroup=system::imports::" + this.importId + ", idOrPath='" + this.classPath + "')," + "    parent = ^meta::pure::metamodel::import::ImportStub (importGroup=system::imports::" + this.importId + ", idOrPath='" + this.mappingPath + "')" + ")";
    }
}
Also used : M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) RuleContext(org.antlr.v4.runtime.RuleContext) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) Token(org.antlr.v4.runtime.Token) OperationParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.OperationParser) TemporaryPureMergeOperationFunctionSpecification(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.TemporaryPureMergeOperationFunctionSpecification) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) AntlrContextToM3CoreInstance(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.AntlrContextToM3CoreInstance)

Aggregations

M3ProcessorSupport (org.finos.legend.pure.m3.navigation.M3ProcessorSupport)8 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)4 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)4 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)3 AntlrContextToM3CoreInstance (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.AntlrContextToM3CoreInstance)3 Lists (org.eclipse.collections.api.factory.Lists)2 MutableList (org.eclipse.collections.api.list.MutableList)2 Parser (org.finos.legend.pure.m3.serialization.grammar.Parser)2 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)2 PureException (org.finos.legend.pure.m4.exception.PureException)2 IOException (java.io.IOException)1 RuleContext (org.antlr.v4.runtime.RuleContext)1 Token (org.antlr.v4.runtime.Token)1 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1 RichIterable (org.eclipse.collections.api.RichIterable)1 Function (org.eclipse.collections.api.block.function.Function)1 Sets (org.eclipse.collections.api.factory.Sets)1 ListIterable (org.eclipse.collections.api.list.ListIterable)1 SetIterable (org.eclipse.collections.api.set.SetIterable)1 ExceptionTranslation (org.finos.legend.pure.ide.light.helpers.response.ExceptionTranslation)1