Skip to content

Commit

Permalink
Update Property and Function return types to GenericType
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredebelen committed Nov 5, 2024
1 parent f4fb6a3 commit 1677c24
Show file tree
Hide file tree
Showing 27 changed files with 2,084 additions and 1,649 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity;
import org.finos.legend.engine.protocol.pure.v1.model.type.GenericType;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.type.relationType.RelationType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda;
Expand Down Expand Up @@ -192,7 +194,7 @@ public static Function wrapLambda(Lambda lambda)
Function func = new Function();
func.name = REPL_RUN_FUNCTION_QUALIFIED_PATH.substring(REPL_RUN_FUNCTION_QUALIFIED_PATH.lastIndexOf("::") + 2);
func._package = REPL_RUN_FUNCTION_QUALIFIED_PATH.substring(0, REPL_RUN_FUNCTION_QUALIFIED_PATH.lastIndexOf("::"));
func.returnType = M3Paths.Any;
func.returnGenericType = new GenericType(new PackageableType(M3Paths.Any));
func.returnMultiplicity = new Multiplicity(0, null);
func.body = lambda.body;
return func;
Expand All @@ -208,7 +210,7 @@ public static Pair<PureModelContextData, Function> injectNewFunction(PureModelCo
func.name = originalFunction.name;
func._package = originalFunction._package;
func.parameters = originalFunction.parameters;
func.returnType = originalFunction.returnType;
func.returnGenericType = originalFunction.returnGenericType;
func.returnMultiplicity = originalFunction.returnMultiplicity;
func.body = lambda != null ? lambda.body : func.body; // if no lambda is specified, we'll just use the original function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Association_Impl;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement;
Expand Down Expand Up @@ -74,8 +75,8 @@ private void associationSecondPass(Association srcAssociation, CompileContext co
{
String packageString = context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association = context.pureModel.getAssociation(packageString, srcAssociation.sourceInformation);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class source = context.resolveClass(srcAssociation.properties.get(0).type, srcAssociation.properties.get(0).sourceInformation);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class target = context.resolveClass(srcAssociation.properties.get(1).type, srcAssociation.properties.get(1).sourceInformation);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class source = context.resolveClass(((PackageableType) srcAssociation.properties.get(0).genericType.rawType).fullPath, srcAssociation.properties.get(0).sourceInformation);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class target = context.resolveClass(((PackageableType) srcAssociation.properties.get(1).genericType.rawType).fullPath, srcAssociation.properties.get(1).sourceInformation);

String property0Ref = context.pureModel.addPrefixToTypeReference(HelperModelBuilder.getElementFullPath(source, context.pureModel.getExecutionSupport()));
String property1Ref = context.pureModel.addPrefixToTypeReference(HelperModelBuilder.getElementFullPath(target, context.pureModel.getExecutionSupport()));
Expand Down Expand Up @@ -106,7 +107,7 @@ private void associationSecondPass(Association srcAssociation, CompileContext co

ListIterable<QualifiedProperty<Object>> qualifiedProperties = ListIterate.collect(srcAssociation.qualifiedProperties, p ->
{
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class cl = context.resolveGenericType(p.returnType, p.sourceInformation)._rawType() == source ? target : source;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class cl = context.newGenericType(p.returnGenericType)._rawType() == source ? target : source;
return HelperModelBuilder.processQualifiedPropertyFirstPass(context, association, org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(cl), ctx).valueOf(p);
});
qualifiedProperties.forEach(q ->
Expand All @@ -118,22 +119,22 @@ private void associationSecondPass(Association srcAssociation, CompileContext co
}
});
ctx.flushVariable("this");
association._originalMilestonedProperties(ListIterate.collect(srcAssociation.originalMilestonedProperties, HelperModelBuilder.processProperty(context, context.pureModel.getGenericTypeFromIndex(srcAssociation.properties.get(0).type), association)))
association._originalMilestonedProperties(ListIterate.collect(srcAssociation.originalMilestonedProperties, HelperModelBuilder.processProperty(context, context.newGenericType(srcAssociation.properties.get(0).genericType), association)))
._properties(Lists.mutable.with(property1, property2))
._qualifiedProperties(qualifiedProperties);
}

private void associationThirdPass(Association srcAssociation, CompileContext context)
{
String property0Ref = context.pureModel.addPrefixToTypeReference(srcAssociation.properties.get(0).type);
String property1Ref = context.pureModel.addPrefixToTypeReference(srcAssociation.properties.get(1).type);
String property0Ref = context.pureModel.addPrefixToTypeReference(((PackageableType)srcAssociation.properties.get(0).genericType.rawType).fullPath);
String property1Ref = context.pureModel.addPrefixToTypeReference(((PackageableType)srcAssociation.properties.get(1).genericType.rawType).fullPath);

org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association = context.pureModel.getAssociation(context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name), srcAssociation.sourceInformation);
ProcessingContext ctx = new ProcessingContext("Association " + context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name) + " (third pass)");

ListIterate.collect(srcAssociation.qualifiedProperties, property ->
{
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(context, srcAssociation.properties.get(0).type.equals(property.returnType) ? property1Ref : property0Ref);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(context, ((PackageableType) srcAssociation.properties.get(0).genericType.rawType).fullPath.equals(((PackageableType)property.returnGenericType.rawType).fullPath) ? property1Ref : property0Ref);
ctx.addInferredVariables("this", thisVariable);
ctx.push("Qualified Property " + property.name);
ListIterate.collect(property.parameters, expression -> expression.accept(new ValueSpecificationBuilder(context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ private PackageableElement functionFirstPass(Function function, CompileContext c

context.pureModel.setNameAndPackage(targetFunc, functionSignature, function._package, function.sourceInformation)
._functionName(functionName) // function name to be used in the handler map -> meta::pure::functions::date::isAfterDay
._classifierGenericType(context.newGenericType(context.pureModel.getType("meta::pure::metamodel::function::ConcreteFunctionDefinition"), PureModel.buildFunctionType(ListIterate.collect(function.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), ctx))), context.resolveGenericType(function.returnType, function.sourceInformation), context.pureModel.getMultiplicity(function.returnMultiplicity), context.pureModel)))
._classifierGenericType(context.newGenericType(context.pureModel.getType("meta::pure::metamodel::function::ConcreteFunctionDefinition"), PureModel.buildFunctionType(ListIterate.collect(function.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), ctx))), context.newGenericType(function.returnGenericType), context.pureModel.getMultiplicity(function.returnMultiplicity), context.pureModel)))
._stereotypes(ListIterate.collect(function.stereotypes, context::resolveStereotype))
._taggedValues(ListIterate.collect(function.taggedValues, context::newTaggedValue));
HelperModelBuilder.processFunctionConstraints(function, context, targetFunc, ctx);

context.pureModel.handlers.register(new UserDefinedFunctionHandler(context.pureModel, functionFullName, targetFunc,
ps -> new TypeAndMultiplicity(context.resolveGenericType(function.returnType, function.sourceInformation), context.pureModel.getMultiplicity(function.returnMultiplicity)),
ps -> new TypeAndMultiplicity(context.newGenericType(function.returnGenericType), context.pureModel.getMultiplicity(function.returnMultiplicity)),
ps ->
{
List<ValueSpecification> vs = ListIterate.collect(function.parameters, p -> p.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), ctx)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static org.eclipse.collections.api.block.function.Function<Property, org.
defaultValue = new Root_meta_pure_metamodel_function_property_DefaultValue_Impl(null, SourceInformationHelper.toM3SourceInformation(property.defaultValue.sourceInformation), null);
defaultValue._functionDefinition(lambdaFunction);
}
GenericType returnGenericType = context.resolveGenericType(property.type, property.propertyTypeSourceInformation);
GenericType returnGenericType = context.newGenericType(property.genericType);
return new Root_meta_pure_metamodel_function_property_Property_Impl<>(property.name, SourceInformationHelper.toM3SourceInformation(property.sourceInformation), context.pureModel.getClass("meta::pure::metamodel::function::property::Property"))
._name(property.name)
._defaultValue(defaultValue)
Expand Down Expand Up @@ -169,15 +169,15 @@ public static org.eclipse.collections.api.block.function.Function<org.finos.lege
return new Root_meta_pure_metamodel_function_property_QualifiedProperty_Impl<>(property.name, SourceInformationHelper.toM3SourceInformation(property.sourceInformation), null)
._name(property.name)
._functionName(property.name)
._genericType(context.resolveGenericType(property.returnType, property.sourceInformation))
._genericType(context.newGenericType(property.returnGenericType))
._multiplicity(context.pureModel.getMultiplicity(property.returnMultiplicity))
._stereotypes(ListIterate.collect(property.stereotypes, s -> context.resolveStereotype(s.profile, s.value, s.profileSourceInformation, s.sourceInformation)))
._taggedValues(ListIterate.collect(property.taggedValues, t -> new Root_meta_pure_metamodel_extension_TaggedValue_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::extension::TaggedValue"))._tag(context.resolveTag(t.tag.profile, t.tag.value, t.tag.profileSourceInformation, t.sourceInformation))._value(t.value)))
._classifierGenericType(
context.newGenericType(
context.pureModel.getType("meta::pure::metamodel::function::property::QualifiedProperty"),
Lists.fixedSize.of(
PureModel.buildFunctionType(Lists.mutable.of(thisVariable).withAll(ListIterate.collect(property.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), processingContext)))), context.resolveGenericType(property.returnType, property.sourceInformation), context.pureModel.getMultiplicity(property.returnMultiplicity), context.pureModel)
PureModel.buildFunctionType(Lists.mutable.of(thisVariable).withAll(ListIterate.collect(property.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), processingContext)))), context.newGenericType(property.returnGenericType), context.pureModel.getMultiplicity(property.returnMultiplicity), context.pureModel)
)
)
)
Expand Down Expand Up @@ -315,7 +315,7 @@ private static String terseSignatureSuffix(Function function)
{
String functionSignature = LazyIterate.collect(function.parameters, HelperModelBuilder::getParameterSignature).select(Objects::nonNull).makeString("__")
// TODO: do we have to take care of void return type ~ Nil?
+ "__" + getClassSignature(function.returnType) + "_" + getMultiplicitySignature(function.returnMultiplicity) + "_";
+ "__" + getClassSignature(((PackageableType) function.returnGenericType.rawType).fullPath) + "_" + getMultiplicitySignature(function.returnMultiplicity) + "_";
return function.parameters.isEmpty() ? functionSignature : ("_" + functionSignature);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ public PackageableElement visit(Function function)

this.context.pureModel.setNameAndPackage(targetFunc, functionSignature, function._package, function.sourceInformation)
._functionName(functionName) // function name to be used in the handler map -> meta::pure::functions::date::isAfterDay
._classifierGenericType(newGenericType(this.context.pureModel.getType("meta::pure::metamodel::function::ConcreteFunctionDefinition"), PureModel.buildFunctionType(ListIterate.collect(function.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx))), this.context.resolveGenericType(function.returnType, function.sourceInformation), this.context.pureModel.getMultiplicity(function.returnMultiplicity), this.context.pureModel)))
._classifierGenericType(newGenericType(this.context.pureModel.getType("meta::pure::metamodel::function::ConcreteFunctionDefinition"), PureModel.buildFunctionType(ListIterate.collect(function.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx))), this.context.newGenericType(function.returnGenericType), this.context.pureModel.getMultiplicity(function.returnMultiplicity), this.context.pureModel)))
._stereotypes(ListIterate.collect(function.stereotypes, this::resolveStereotype))
._taggedValues(ListIterate.collect(function.taggedValues, this::newTaggedValue));
HelperModelBuilder.processFunctionConstraints(function, this.context, targetFunc, ctx);

this.context.pureModel.handlers.register(new UserDefinedFunctionHandler(this.context.pureModel, functionFullName, targetFunc,
ps -> new TypeAndMultiplicity(this.context.resolveGenericType(function.returnType, function.sourceInformation), this.context.pureModel.getMultiplicity(function.returnMultiplicity)),
ps -> new TypeAndMultiplicity(this.context.newGenericType(function.returnGenericType), this.context.pureModel.getMultiplicity(function.returnMultiplicity)),
ps ->
{
List<ValueSpecification> vs = ListIterate.collect(function.parameters, p -> p.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property;

Expand Down Expand Up @@ -68,8 +69,8 @@ public PackageableElement visit(Class srcClass)
@Override
public PackageableElement visit(Association srcAssociation)
{
String property0Ref = this.context.pureModel.addPrefixToTypeReference(srcAssociation.properties.get(0).type);
String property1Ref = this.context.pureModel.addPrefixToTypeReference(srcAssociation.properties.get(1).type);
String property0Ref = this.context.pureModel.addPrefixToTypeReference(((PackageableType) srcAssociation.properties.get(0).genericType.rawType).fullPath);
String property1Ref = this.context.pureModel.addPrefixToTypeReference(((PackageableType) srcAssociation.properties.get(1).genericType.rawType).fullPath);

String packageString = this.context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association = this.context.pureModel.getAssociation(packageString, srcAssociation.sourceInformation);
Expand Down
Loading

0 comments on commit 1677c24

Please sign in to comment.