Search in sources :

Example 1 with ConcreteFunctionDefinitionInstance

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;
}
Also used : GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) Constraint(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.Constraint) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ConcreteFunctionDefinitionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinitionInstance) PureParserException(org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Aggregations

PackageInstance (org.finos.legend.pure.m3.coreinstance.PackageInstance)1 Constraint (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.Constraint)1 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)1 ConcreteFunctionDefinitionInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinitionInstance)1 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)1 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)1 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)1 GenericTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance)1 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)1 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)1