use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty in project legend-engine by finos.
the class DomainParseTreeWalker method expression.
private ValueSpecification expression(DomainParserGrammar.ExpressionContext ctx, String exprName, List<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, boolean addLines) {
ValueSpecification result;
List<ValueSpecification> expressions = Lists.mutable.of();
List<ValueSpecification> parameters;
if (ctx.combinedExpression() != null) {
return this.combinedExpression(ctx.combinedExpression(), exprName, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
}
if (ctx.atomicExpression() != null) {
result = this.atomicExpression(ctx.atomicExpression(), typeParametersNames, lambdaContext, space, wrapFlag, addLines);
} else if (ctx.notExpression() != null) {
result = this.notExpression(ctx.notExpression(), exprName, typeParametersNames, lambdaContext, space, addLines);
} else if (ctx.signedExpression() != null) {
result = this.signedExpression(ctx.signedExpression(), exprName, typeParametersNames, lambdaContext, space, addLines);
} else if (ctx.expressionsArray() != null) {
for (DomainParserGrammar.ExpressionContext eCtx : ctx.expressionsArray().expression()) {
expressions.add(this.expression(eCtx, exprName, typeParametersNames, lambdaContext, space, false, addLines));
}
result = this.collect(expressions, walkerSourceInformation.getSourceInformation(ctx));
} else {
throw new EngineException(ctx.getText() + " is not supported", walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
if (ctx.propertyOrFunctionExpression() != null) {
for (DomainParserGrammar.PropertyOrFunctionExpressionContext pfCtx : ctx.propertyOrFunctionExpression()) {
if (pfCtx.propertyExpression() != null) {
result = propertyExpression(pfCtx.propertyExpression(), result, typeParametersNames, lambdaContext, space, addLines);
} else // TODO PropertyBracketExpression is deprecated. Remove else if clause once all use has been addressed
if (pfCtx.propertyBracketExpression() != null) {
if (!allowPropertyBracketExpression) {
throw new EngineException("Bracket operation is not supported", walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression()), EngineErrorType.PARSER);
}
String getPropertyName = "oneString";
parameters = new ArrayList<>();
AppliedProperty appliedProperty = new AppliedProperty();
appliedProperty.property = getPropertyName;
appliedProperty.parameters = Lists.mutable.of(result).withAll(parameters);
if (pfCtx.propertyBracketExpression().STRING() != null) {
CString instance = getInstanceString(pfCtx.propertyBracketExpression().STRING().getText());
instance.sourceInformation = walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression());
appliedProperty.parameters.add(instance);
} else {
CInteger instance = getInstanceInteger(pfCtx.propertyBracketExpression().INTEGER().getText());
instance.sourceInformation = walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression());
appliedProperty.parameters.add(instance);
}
appliedProperty.sourceInformation = walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression());
result = appliedProperty;
} else {
for (int i = 0; i < pfCtx.functionExpression().qualifiedName().size(); i++) {
parameters = this.functionExpressionParameters(pfCtx.functionExpression().functionExpressionParameters(i), typeParametersNames, lambdaContext, addLines, space);
parameters.add(0, result);
result = this.functionExpression(pfCtx.functionExpression().qualifiedName(i), parameters);
}
}
}
}
if (ctx.equalNotEqual() != null) {
result = this.equalNotEqual(ctx.equalNotEqual(), result, exprName, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
}
return result;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty in project legend-engine by finos.
the class DomainParseTreeWalker method propertyExpression.
private ValueSpecification propertyExpression(DomainParserGrammar.PropertyExpressionContext ctx, ValueSpecification result, List<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean addLines) {
List<ValueSpecification> parameters = new ArrayList<>();
DomainParserGrammar.IdentifierContext property = ctx.identifier();
ValueSpecification parameter;
if (ctx.functionExpressionParameters() != null) {
DomainParserGrammar.FunctionExpressionParametersContext fepCtx = ctx.functionExpressionParameters();
if (fepCtx.combinedExpression() != null) {
for (DomainParserGrammar.CombinedExpressionContext ceCtx : fepCtx.combinedExpression()) {
parameter = this.combinedExpression(ceCtx, "param", typeParametersNames, lambdaContext, space, true, addLines);
parameters.add(parameter);
}
}
} else if (ctx.functionExpressionLatestMilestoningDateParameter() != null) {
ctx.functionExpressionLatestMilestoningDateParameter().LATEST_DATE().forEach(lDate -> {
CLatestDate date = new CLatestDate();
date.multiplicity = getMultiplicityOneOne();
parameters.add(date);
});
}
AppliedProperty appliedProperty = new AppliedProperty();
appliedProperty.property = PureGrammarParserUtility.fromIdentifier(property);
appliedProperty.sourceInformation = walkerSourceInformation.getSourceInformation(property);
appliedProperty.parameters = Lists.mutable.of(result).withAll(parameters);
return appliedProperty;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty in project legend-engine by finos.
the class HelperServiceStoreClassMappingBuilder method buildParameterIndexedMappingFromPropertyIndexedMapping.
private static ParameterIndexedParameterMapping buildParameterIndexedMappingFromPropertyIndexedMapping(PropertyIndexedParameterMapping serviceParameterMapping) {
Variable thisVar = new Variable();
thisVar.name = "this";
AppliedProperty prop = new AppliedProperty();
prop.property = serviceParameterMapping.property;
prop.parameters = Lists.mutable.with(thisVar);
Lambda transform = new Lambda();
transform.body = Lists.mutable.with(prop);
transform.parameters = Lists.mutable.empty();
ParameterIndexedParameterMapping parameterIndexedParameterMapping = new ParameterIndexedParameterMapping();
parameterIndexedParameterMapping.transform = transform;
parameterIndexedParameterMapping.serviceParameter = serviceParameterMapping.serviceParameter;
parameterIndexedParameterMapping.sourceInformation = serviceParameterMapping.sourceInformation;
return parameterIndexedParameterMapping;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty in project legend-engine by finos.
the class HelperValueSpecificationBuilder method processProperty.
public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification processProperty(CompileContext context, MutableList<String> openVariables, ProcessingContext processingContext, List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> parameters, String property, SourceInformation sourceInformation) {
// for X.property. X is the first parameter
processingContext.push("Processing property " + property);
org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification firstArgument = parameters.get(0);
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> processedParameters = ListIterate.collect(parameters, p -> p.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)));
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType genericType;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity multiplicity;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification inferredVariable;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification result;
if (// Only for backward compatibility!
firstArgument instanceof org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Enum || (processedParameters.get(0)._genericType()._rawType().equals(context.pureModel.getType("meta::pure::metamodel::type::Enumeration")))) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity();
m.lowerBound = 1;
m.setUpperBound(1);
CString enumValue = new CString();
enumValue.values = Lists.mutable.of(property);
enumValue.multiplicity = m;
// validation to make sure the enum value can be found
context.resolveEnumValue(((PackageableElementPtr) firstArgument).fullPath, enumValue.values.get(0), firstArgument.sourceInformation, sourceInformation);
AppliedFunction extractEnum = new AppliedFunction();
extractEnum.function = "extractEnumValue";
extractEnum.parameters = Lists.mutable.of(firstArgument, enumValue);
result = extractEnum.accept(new ValueSpecificationBuilder(context, openVariables, processingContext));
} else {
if (firstArgument instanceof Variable) {
inferredVariable = processingContext.getInferredVariable(((Variable) firstArgument).name);
} else {
inferredVariable = processedParameters.get(0);
}
Type inferredType = inferredVariable._genericType()._rawType();
if (// is an enum
!(inferredType instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)) {
inferredType = context.pureModel.getType("meta::pure::metamodel::type::Enum");
}
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty<?> foundProperty = findProperty(context, (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) inferredType, parameters, property, sourceInformation);
if (foundProperty instanceof Property) {
genericType = (foundProperty._classifierGenericType()._typeArguments()).getLast();
multiplicity = foundProperty._multiplicity();
} else if (foundProperty instanceof QualifiedProperty) {
FunctionType fType = (FunctionType) foundProperty._classifierGenericType()._typeArguments().getFirst()._rawType();
genericType = fType._returnType();
multiplicity = fType._returnMultiplicity();
} else {
throw new UnsupportedOperationException("Unhandled property: " + foundProperty);
}
if (// autoMap
!inferredVariable._multiplicity().getName().equals("PureOne")) {
processingContext.push("Building Automap for " + property);
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity();
m.lowerBound = 1;
m.setUpperBound(1);
List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> localParameters = Lists.mutable.ofAll(parameters);
final String automapName = "v_automap";
Lambda automapLambda = new Lambda();
AppliedProperty appliedProperty = new AppliedProperty();
appliedProperty.property = property;
Variable automapvar = new Variable();
Variable automaLambdaparam = new Variable();
automapvar.name = automapName;
appliedProperty.parameters = Lists.mutable.of(automapvar);
if (!localParameters.isEmpty()) {
localParameters.remove(0);
}
appliedProperty.parameters.addAll(localParameters);
automaLambdaparam.name = automapName;
automaLambdaparam._class = HelperModelBuilder.getElementFullPath(inferredVariable._genericType()._rawType(), context.pureModel.getExecutionSupport());
automaLambdaparam.multiplicity = m;
automapLambda.body = Lists.mutable.of(appliedProperty);
List<Variable> lambdaParams = new FastList<>();
lambdaParams.add(automaLambdaparam);
automapLambda.parameters = lambdaParams;
List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> newParams = Lists.mutable.of(parameters.get(0), automapLambda);
result = context.buildFunctionExpression("map", null, newParams, openVariables, null, processingContext).getOne();
processingContext.pop();
} else {
result = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(foundProperty)._propertyName(new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("")._values(Lists.fixedSize.of(foundProperty.getName())))._genericType(genericType)._multiplicity(multiplicity)._parametersValues(processedParameters);
}
}
processingContext.pop();
return result;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty in project legend-engine by finos.
the class TestMappingGrammarParser method testLatestMultiplicity.
@Test
public void testLatestMultiplicity() {
PureModelContextData model = PureGrammarParser.newInstance().parseModel("import test::*;\n" + "Class test::A\n" + "{\n" + " stringProperty: String[1];\n" + " latestProduct(){\n" + " $this.stringProperty(%latest)\n" + " }:String[*];\n" + "}\n");
Multiplicity latest = ((CLatestDate) ((AppliedProperty) model.getElementsOfType(Class.class).get(0).qualifiedProperties.get(0).body.get(0)).parameters.get(1)).multiplicity;
Assert.assertTrue(latest.isUpperBoundEqualTo(1), () -> "CLatestDate must have multiplicity set to 1");
}
Aggregations