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;
}
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);
}
}
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();
}
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 + "']";
}
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 + "')" + ")";
}
}
Aggregations