use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinitionInstance in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method concreteFunctionDefinition.
public CoreInstance concreteFunctionDefinition(FunctionDefinitionContext ctx, ImportGroup importId, boolean addLines, String space, MutableList<CoreInstance> coreInstancesResult) {
this.functionCounter++;
ConcreteFunctionDefinitionInstance functionDefinition = ConcreteFunctionDefinitionInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText() + importId.getName() + this.functionCounter, this.sourceInformation.getPureSourceInformation(ctx.FUNCTION().getSymbol(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
ListIterable<CoreInstance> stereotypes = (ctx.stereotypes() == null) ? null : stereotypes(ctx.stereotypes(), importId);
ListIterable<TaggedValue> tags = (ctx.taggedValues() == null) ? null : taggedValues(ctx.taggedValues(), importId);
MutableList<String> typeParametersNames = Lists.mutable.empty();
MutableList<String> multiplicityParameterNames = Lists.mutable.empty();
if (ctx.typeAndMultiplicityParameters() != null) {
this.typeParametersAndMultiplicityParameters(ctx.typeAndMultiplicityParameters(), typeParametersNames, multiplicityParameterNames);
}
FunctionType signature = this.functionTypeSignature(ctx.functionTypeSignature(), functionDefinition, typeParametersNames, multiplicityParameterNames, importId, spacePlusTabs(space, 1));
// Reset the lambda function counter - we count within the Concrete definition
LambdaContext lambdaContext = new LambdaContext(getFunctionUniqueId(ctx.qualifiedName(), this.functionCounter, importId));
ListIterable<ValueSpecification> block = this.codeBlock(ctx.codeBlock(), typeParametersNames, importId, lambdaContext, addLines, spacePlusTabs(space, 2));
functionDefinition._stereotypesCoreInstance(stereotypes);
functionDefinition._taggedValues(tags);
functionDefinition._functionName(ctx.qualifiedName().identifier().getText());
PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
functionDefinition._package(packageInstance);
packageInstance._childrenAdd(functionDefinition);
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
Type type = (Type) this.processorSupport.package_getByUserPath(M3Paths.ConcreteFunctionDefinition);
genericTypeInstance._rawTypeCoreInstance(type);
GenericTypeInstance genericTypeInstanceTa = GenericTypeInstance.createPersistent(this.repository);
genericTypeInstanceTa._rawTypeCoreInstance(signature);
genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(genericTypeInstanceTa));
functionDefinition._classifierGenericType(genericTypeInstance);
MutableList<Constraint> preConstraints = Lists.mutable.empty();
MutableList<Constraint> postConstraints = Lists.mutable.empty();
if (ctx.constraints() != null) {
ListIterate.forEachWithIndex(ctx.constraints().constraint(), (cCtx, i) -> {
if (cCtx.simpleConstraint() == null) {
throw new PureParserException(this.sourceInformation.getPureSourceInformation(cCtx.getStart()), "Complex constraint specifications are supported only for class definitions");
}
if (cCtx.simpleConstraint().combinedExpression().getText().contains("$return")) {
postConstraints.add(this.constraint(functionDefinition, cCtx, i, importId, lambdaContext, addLines, true));
} else {
preConstraints.add(this.constraint(functionDefinition, cCtx, i, importId, lambdaContext, addLines, false));
}
});
}
if (preConstraints.notEmpty()) {
functionDefinition._preConstraints(preConstraints);
}
if (postConstraints.notEmpty()) {
functionDefinition._postConstraints(postConstraints);
}
functionDefinition._expressionSequence(block);
coreInstancesResult.add(functionDefinition);
return functionDefinition;
}
Aggregations