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);
}
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;
}
}
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;
}
}
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());
}
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;
}
Aggregations