use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PackageableElementPtr in project legend-engine by finos.
the class PureCollectionDataParseTreeWalker method visitInstance.
private AppliedFunction visitInstance(PureCollectionDataParserGrammar.InstanceContext ctx) {
ctx.instancePropertyAssignment().stream().map(this::visitPropertyAssignment).collect(Collectors.toList());
PackageableElementPtr newClass = new PackageableElementPtr();
newClass.fullPath = PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath() == null ? Collections.emptyList() : ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier());
List<ValueSpecification> keyExpressions = ctx.instancePropertyAssignment().stream().map(this::visitPropertyAssignment).collect(Collectors.toList());
Collection valueAssignments = new Collection();
valueAssignments.values = keyExpressions;
valueAssignments.multiplicity = PURE_ONE;
AppliedFunction appliedFunction = new AppliedFunction();
appliedFunction.parameters = Lists.mutable.with(newClass, cString("dummy"), valueAssignments);
appliedFunction.function = "new";
return appliedFunction;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PackageableElementPtr 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;
}
Aggregations