Search in sources :

Example 1 with Variable

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable in project legend-engine by finos.

the class HelperValueSpecificationBuilder method buildPropertyGraphFetchTree.

private static GraphFetchTree buildPropertyGraphFetchTree(PropertyGraphFetchTree propertyGraphFetchTree, CompileContext context, Class<?> parentClass, MutableList<String> openVariables, ProcessingContext processingContext) {
    AbstractProperty<?> property;
    MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> pureParameters = Lists.mutable.empty();
    if (!propertyGraphFetchTree.parameters.isEmpty()) {
        Variable thisVariable = new Variable("this", HelperModelBuilder.getElementFullPath(parentClass, context.pureModel.getExecutionSupport()), new Multiplicity(1, 1));
        property = HelperModelBuilder.getAppliedProperty(context, parentClass, Optional.of(Lists.mutable.<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification>with(thisVariable).withAll(propertyGraphFetchTree.parameters)), propertyGraphFetchTree.property);
        processingContext.push("PropertyTree");
        processingContext.addInferredVariables("this", HelperModelBuilder.createThisVariableForClass(context, HelperModelBuilder.getElementFullPath(parentClass, context.pureModel.getExecutionSupport())));
        pureParameters = ListIterate.collect(propertyGraphFetchTree.parameters, x -> x.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)));
        processingContext.flushVariable("this");
        processingContext.pop();
    } else {
        property = HelperModelBuilder.getAppliedProperty(context, parentClass, Optional.empty(), propertyGraphFetchTree.property, propertyGraphFetchTree.sourceInformation);
    }
    Class<?> subType = propertyGraphFetchTree.subType == null ? null : context.resolveClass(propertyGraphFetchTree.subType, propertyGraphFetchTree.sourceInformation);
    Type returnType = subType == null ? property._genericType()._rawType() : subType;
    ListIterable<GraphFetchTree> children = ListIterate.collect(propertyGraphFetchTree.subTrees, subTree -> buildGraphFetchTree(subTree, context, (Class<?>) returnType, openVariables, processingContext));
    return new Root_meta_pure_graphFetch_PropertyGraphFetchTree_Impl("")._property(property)._parameters(pureParameters)._alias(propertyGraphFetchTree.alias)._subType(subType)._subTrees(children);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) PackageableElementPtr(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PackageableElementPtr) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) BaseExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.BaseExecutionContext) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) AnalyticsExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.AnalyticsExecutionContext) AppliedProperty(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Objects(java.util.Objects) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) org.finos.legend.pure.generated(org.finos.legend.pure.generated) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) List(java.util.List) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Lists(org.eclipse.collections.impl.factory.Lists) ExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.ExecutionContext) VariableExpressionAccessor(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpressionAccessor) ListIterable(org.eclipse.collections.api.list.ListIterable) Optional(java.util.Optional) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) 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) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)

Example 2 with Variable

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable in project legend-engine by finos.

the class Handlers method updateTwoParamsLambda.

private static void updateTwoParamsLambda(Object lambda, GenericType newGenericType, org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m) {
    if (lambda instanceof Lambda) {
        Variable variable = ((Lambda) lambda).parameters.get(0);
        variable._class = PackageableElement.getUserPathForPackageableElement(newGenericType._rawType());
        variable.multiplicity = m;
        Variable variable2 = ((Lambda) lambda).parameters.get(1);
        variable2._class = PackageableElement.getUserPathForPackageableElement(newGenericType._rawType());
        variable2.multiplicity = m;
    }
}
Also used : Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)

Example 3 with Variable

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable in project legend-engine by finos.

the class Handlers method updateTwoParamsLambdaDiffTypes.

private static void updateTwoParamsLambdaDiffTypes(Object lambda, GenericType newGenericType, GenericType newGenericType2, org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m, org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m2) {
    if (lambda instanceof Lambda) {
        Variable variable = ((Lambda) lambda).parameters.get(0);
        variable._class = PackageableElement.getUserPathForPackageableElement(newGenericType._rawType());
        variable.multiplicity = m;
        Variable variable2 = ((Lambda) lambda).parameters.get(1);
        variable2._class = PackageableElement.getUserPathForPackageableElement(newGenericType2._rawType());
        variable2.multiplicity = m2;
    }
}
Also used : Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)

Example 4 with Variable

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable in project legend-engine by finos.

the class GraphFetchTreeParseTreeWalker method visitScalarParameterContext.

private ValueSpecification visitScalarParameterContext(GraphFetchTreeParserGrammar.ScalarParameterContext scalarParameterContext) {
    if (scalarParameterContext.enumReference() != null) {
        EnumValue result = new EnumValue();
        result.sourceInformation = walkerSourceInformation.getSourceInformation(scalarParameterContext.enumReference());
        result.fullPath = PureGrammarParserUtility.fromQualifiedName(scalarParameterContext.enumReference().qualifiedName().packagePath() == null ? Collections.emptyList() : scalarParameterContext.enumReference().qualifiedName().packagePath().identifier(), scalarParameterContext.enumReference().qualifiedName().identifier());
        result.value = PureGrammarParserUtility.fromIdentifier(scalarParameterContext.enumReference().identifier());
        return result;
    }
    if (scalarParameterContext.variable() != null) {
        Variable ve = new Variable();
        ve.sourceInformation = walkerSourceInformation.getSourceInformation(scalarParameterContext.variable().identifier());
        ve.name = PureGrammarParserUtility.fromIdentifier(scalarParameterContext.variable().identifier());
        return ve;
    }
    return instanceLiteralToken(scalarParameterContext.instanceLiteral().instanceLiteralToken());
}
Also used : Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) EnumValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue)

Example 5 with Variable

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable in project legend-engine by finos.

the class DomainParseTreeWalker method atomicExpression.

private ValueSpecification atomicExpression(DomainParserGrammar.AtomicExpressionContext ctx, List<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, boolean addLines) {
    ValueSpecification result;
    ListIterable<ValueSpecification> dsl;
    Variable expr;
    List<Variable> expressions = Lists.mutable.of();
    if (ctx.instanceLiteralToken() != null) {
        result = this.instanceLiteralToken(ctx.instanceLiteralToken(), wrapFlag);
    } else if (ctx.dsl() != null) {
        dsl = this.visitDsl(ctx.dsl());
        assert dsl != null;
        if (dsl.size() > 1) {
            throw new EngineException("Only expected one graph fetch tree", walkerSourceInformation.getSourceInformation(ctx.dsl()), EngineErrorType.PARSER);
        }
        result = dsl.getFirst();
    } else if (ctx.expressionInstance() != null) {
        result = this.newFunction(ctx.expressionInstance(), typeParametersNames, lambdaContext, addLines, space);
    } else if (ctx.variable() != null) {
        result = this.variable(ctx.variable());
    } else if (ctx.type() != null) {
        if (ctx.type().unitName() != null) {
            result = this.unitTypeReference(ctx.type());
        } else {
            result = this.typeReference(ctx.type());
        }
    } else if (ctx.lambdaFunction() != null) {
        boolean hasLambdaParams = false;
        if (ctx.lambdaFunction().lambdaParam() != null) {
            for (int i = 0; i < ctx.lambdaFunction().lambdaParam().size(); i++) {
                hasLambdaParams = true;
                DomainParserGrammar.IdentifierContext idCtx = ctx.lambdaFunction().lambdaParam(i).identifier();
                expr = this.lambdaParam(ctx.lambdaFunction().lambdaParam(i).lambdaParamType(), idCtx, typeParametersNames, space);
                expressions.add(expr);
            }
        }
        result = this.lambdaPipe(ctx.lambdaFunction().lambdaPipe(), hasLambdaParams ? ctx.lambdaFunction().lambdaParam(0).getStart() : null, expressions, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
    } else if (ctx.lambdaParam() != null && ctx.lambdaPipe() != null) {
        expr = this.lambdaParam(ctx.lambdaParam().lambdaParamType(), ctx.lambdaParam().identifier(), typeParametersNames, space);
        expressions.add(expr);
        result = this.lambdaPipe(ctx.lambdaPipe(), ctx.lambdaParam().getStart(), expressions, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
    } else if (ctx.instanceReference() != null) {
        result = this.instanceReference(ctx.instanceReference(), typeParametersNames, lambdaContext, space, addLines);
    } else {
        // lambdaPipe
        result = this.lambdaPipe(ctx.lambdaPipe(), null, expressions, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
    }
    return result;
}
Also used : Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)

Aggregations

Variable (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable)20 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)12 Multiplicity (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity)7 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)7 FastList (org.eclipse.collections.impl.list.mutable.FastList)5 AppliedFunction (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction)5 AppliedProperty (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty)5 CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)5 List (java.util.List)4 Lists (org.eclipse.collections.impl.factory.Lists)4 ListIterate (org.eclipse.collections.impl.utility.ListIterate)4 ArrayList (java.util.ArrayList)3 ListIterable (org.eclipse.collections.api.list.ListIterable)3 MutableList (org.eclipse.collections.api.list.MutableList)3 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)3 Unit (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Unit)3 HackedUnit (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.HackedUnit)3 Collections (java.util.Collections)2 Consumer (java.util.function.Consumer)2 CharStreams (org.antlr.v4.runtime.CharStreams)2