use of org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype in project legend-pure by finos.
the class MilestoningDatesPropagationFunctions method getMilestonedDates.
public static MilestoningDates getMilestonedDates(FunctionExpression milestonedQualifiedProperty, ProcessorSupport processorSupport) {
CoreInstance func = milestonedQualifiedProperty._funcCoreInstance();
CoreInstance propertyReturnType = (func instanceof AbstractProperty) ? ImportStub.withImportStubByPass(((AbstractProperty<?>) func)._genericType()._rawTypeCoreInstance(), processorSupport) : null;
MilestoningStereotype milestoningStereotype = MilestoningFunctions.getTemporalStereoTypesFromTopMostNonTopTypeGeneralizations(propertyReturnType, processorSupport).getFirst();
return new MilestoningDates(milestoningStereotype, ListHelper.tail(milestonedQualifiedProperty._parametersValues()).toList());
}
use of org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype in project legend-pure by finos.
the class MilestoningFunctions method isGeneratedMilestoningProperty.
public static boolean isGeneratedMilestoningProperty(CoreInstance property, ProcessorSupport processorSupport, String stereotype, String milestoningPathSuffix) {
if (property instanceof ElementWithStereotypes) {
RichIterable<? extends CoreInstance> stereotypes = ((ElementWithStereotypes) property)._stereotypesCoreInstance();
if (stereotypes.notEmpty()) {
CoreInstance profile = processorSupport.package_getByUserPath(M3Paths.Milestoning);
CoreInstance milestoningStereotype = Profile.findStereotype(profile, stereotype);
return stereotypes.anySatisfy(st -> (st instanceof ImportStub) ? ((ImportStub) st)._idOrPath().endsWith(milestoningPathSuffix) : milestoningStereotype.equals(st));
}
}
return false;
}
use of org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype in project legend-pure by finos.
the class MilestoningClassValidator method validateTemporalStereotypesAppliedForAllSubTypesInTemporalHierarchy.
static void validateTemporalStereotypesAppliedForAllSubTypesInTemporalHierarchy(Class<?> cls, ProcessorSupport processorSupport) {
if (!Type.directSubTypeOf(cls, processorSupport.type_TopType(), processorSupport)) {
ListIterable<MilestoningStereotypeEnum> topMostTypeMilestoningStereotypes = MilestoningFunctions.getTemporalStereoTypesFromTopMostNonTopTypeGeneralizations(cls, processorSupport);
MilestoningStereotype subTypeMilestoningStereotype = MilestoningFunctions.getTemporalStereoTypesExcludingParents(cls).getFirst();
boolean subTypeIsTemporal = subTypeMilestoningStereotype != null;
if (topMostTypeMilestoningStereotypes.notEmpty()) {
MilestoningStereotypeEnum topMostTypeMilestoningStereotype = topMostTypeMilestoningStereotypes.getFirst();
boolean topMostTypeIsTemporal = topMostTypeMilestoningStereotype != null;
if (topMostTypeIsTemporal && !subTypeIsTemporal) {
MutableSet<CoreInstance> topNonAnyTypes = Type.getTopMostNonTopTypeGeneralizations(cls, processorSupport);
StringBuilder builder = new StringBuilder("Temporal stereotypes must be applied at all levels in a temporal class hierarchy, top most supertype");
if (topNonAnyTypes.size() != 1) {
builder.append('s');
}
topNonAnyTypes.collect(PackageableElement::getUserPathForPackageableElement, Lists.mutable.ofInitialCapacity(topNonAnyTypes.size())).sortThis().appendString(builder, " ", ", ", " ");
builder.append((topNonAnyTypes.size() == 1) ? "has" : "have");
builder.append(" milestoning stereotype: '").append(topMostTypeMilestoningStereotype).append("'");
throw new PureCompilationException(cls.getSourceInformation(), builder.toString());
}
if (topMostTypeIsTemporal && subTypeIsTemporal && (topMostTypeMilestoningStereotype != subTypeMilestoningStereotype)) {
MutableSet<CoreInstance> topNonAnyTypes = Type.getTopMostNonTopTypeGeneralizations(cls, processorSupport);
StringBuilder builder = PackageableElement.writeUserPathForPackageableElement(new StringBuilder("All temporal stereotypes in a hierarchy must be the same, class "), cls);
builder.append(" is ").append(subTypeMilestoningStereotype).append(", top most supertype");
if (topNonAnyTypes.size() != 1) {
builder.append('s');
}
topNonAnyTypes.collect(PackageableElement::getUserPathForPackageableElement, Lists.mutable.ofInitialCapacity(topNonAnyTypes.size())).sortThis().appendString(builder, " ", ", ", " ");
builder.append((topNonAnyTypes.size() == 1) ? "has" : "have");
builder.append(" milestoning stereotype: '").append(topMostTypeMilestoningStereotype).append("'");
throw new PureCompilationException(cls.getSourceInformation(), builder.toString());
}
} else if (subTypeIsTemporal) {
MutableSet<CoreInstance> topNonAnyTypes = Type.getTopMostNonTopTypeGeneralizations(cls, processorSupport);
StringBuilder builder = PackageableElement.writeUserPathForPackageableElement(new StringBuilder("All temporal stereotypes in a hierarchy must be the same, class "), cls);
builder.append(" is ").append(subTypeMilestoningStereotype).append(", top most supertype");
if (topNonAnyTypes.size() != 1) {
builder.append('s');
}
topNonAnyTypes.collect(PackageableElement::getUserPathForPackageableElement, Lists.mutable.ofInitialCapacity(topNonAnyTypes.size())).sortThis().appendString(builder, " ", ", ", " ");
builder.append((topNonAnyTypes.size() == 1) ? "is" : "are").append(" not temporal");
throw new PureCompilationException(cls.getSourceInformation(), builder.toString());
}
}
}
use of org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype in project legend-engine by finos.
the class Milestoning method generateMilestoningRangeQualifiedProperty.
private static MutableList<QualifiedProperty<?>> generateMilestoningRangeQualifiedProperty(CompileContext context, Class<?> sourceClass, PropertyOwner propertyOwner, Property originalProperty, MilestoningStereotype returnTypeMilestoningStereotype, MutableList<Stereotype> stereotypes, Property edgePointProperty) {
MutableList<QualifiedProperty<?>> generatedMilestoningRangeQualifiedProperty = Lists.mutable.empty();
if (UNI_TEMPORAL_STEREOTYPE_NAMES.contains(returnTypeMilestoningStereotype.getPurePlatformStereotypeName())) {
String qualifiedPropertyName = MilestoningFunctions.getRangePropertyName(originalProperty._name());
String temporalDatePropertyName = returnTypeMilestoningStereotype.getTemporalDatePropertyNames().getFirst();
VariableExpression thisVar = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name("this")._multiplicity(context.pureModel.getMultiplicity("one"))._genericType(sourceClass._classifierGenericType()._typeArguments().getFirst());
VariableExpression v_milestoning = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name("v_milestoning")._multiplicity(context.pureModel.getMultiplicity("one"))._genericType(edgePointProperty._genericType());
VariableExpression inputStartDate = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name("start")._multiplicity(context.pureModel.getMultiplicity("one"))._genericType(context.pureModel.getGenericType("Date"));
VariableExpression inputEndDate = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name("end")._multiplicity(context.pureModel.getMultiplicity("one"))._genericType(context.pureModel.getGenericType("Date"));
SimpleFunctionExpression temporalDatePropertyExp = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(HelperModelBuilder.getOwnedProperty((Class<Object>) originalProperty._genericType()._rawType(), temporalDatePropertyName, context.pureModel.getExecutionSupport()))._propertyName(new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("")._values(Lists.mutable.of(temporalDatePropertyName)))._genericType(context.pureModel.getGenericType("Date"))._multiplicity(context.pureModel.getMultiplicity("one"))._parametersValues(Lists.mutable.of(v_milestoning));
SimpleFunctionExpression equalExpression = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(context.pureModel.getFunction("meta::pure::functions::boolean::eq_Any_1__Any_1__Boolean_1_", true))._functionName("eq")._genericType(context.pureModel.getGenericType("Boolean"))._multiplicity(context.pureModel.getMultiplicity("one"))._parametersValues(Lists.mutable.of(temporalDatePropertyExp, inputStartDate));
LambdaFunction filterLambda = new Root_meta_pure_metamodel_function_LambdaFunction_Impl("")._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::function::LambdaFunction"))._typeArguments(Lists.mutable.of(PureModel.buildFunctionType(Lists.mutable.of(v_milestoning), context.pureModel.getGenericType("Boolean"), context.pureModel.getMultiplicity("one")))))._openVariables(Lists.mutable.of(temporalDatePropertyName))._expressionSequence(Lists.mutable.of(equalExpression));
InstanceValue filterInstanceValue = new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("")._genericType(filterLambda._classifierGenericType())._multiplicity(context.pureModel.getMultiplicity("one"))._values(Lists.mutable.of(filterLambda));
SimpleFunctionExpression filterLhs = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(edgePointProperty)._propertyName(new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("")._values(Lists.mutable.of(edgePointProperty._name())))._genericType(edgePointProperty._genericType())._multiplicity(edgePointProperty._multiplicity())._parametersValues(Lists.mutable.of(thisVar));
SimpleFunctionExpression filterExpression = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(context.pureModel.getFunction("meta::pure::functions::collection::filter_T_MANY__Function_1__T_MANY_", true))._functionName("filter")._genericType(originalProperty._genericType())._multiplicity(context.pureModel.getMultiplicity("zeromany"))._parametersValues(Lists.mutable.of(filterLhs, filterInstanceValue));
QualifiedProperty<?> milestoningRangeQualifiedProperty = getQualifiedProperty(propertyOwner, originalProperty, qualifiedPropertyName, originalProperty._multiplicity(), stereotypes)._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::function::property::QualifiedProperty"))._typeArguments(Lists.mutable.of(PureModel.buildFunctionType(Lists.mutable.of(thisVar, inputStartDate, inputEndDate), originalProperty._genericType(), originalProperty._multiplicity()))))._expressionSequence(Lists.mutable.of(filterExpression));
generatedMilestoningRangeQualifiedProperty.add(milestoningRangeQualifiedProperty);
}
return generatedMilestoningRangeQualifiedProperty;
}
use of org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype in project legend-engine by finos.
the class Milestoning method milestoningPropertyTransformations.
private static MilestoningPropertyTransformation milestoningPropertyTransformations(Property<?, ?> originalProperty, CompileContext context, Class<?> sourceClass, PropertyOwner propertyOwner) {
List<MilestoningStereotype> returnTypeMilestoningStereotypes = temporalStereotypes(originalProperty._genericType()._rawType()._stereotypes());
MilestoningPropertyTransformation milestoningPropertyTransformation = new MilestoningPropertyTransformation(originalProperty);
if (!returnTypeMilestoningStereotypes.isEmpty()) {
MilestoningStereotype returnTypeMilestoningStereotype = returnTypeMilestoningStereotypes.get(0);
MutableList<Stereotype> stereotypes = Lists.mutable.withAll(originalProperty._stereotypes());
MutableList<Stereotype> withMilestoningStereotype = stereotypes.with(generatedMilestoningStereotype(context, GeneratedMilestoningStereotype.generatedmilestoningproperty));
Property<?, ?> edgePointProperty = edgePointProperty(propertyOwner, originalProperty, stereotypes);
milestoningPropertyTransformation.setEdgePointProperty(edgePointProperty);
MutableList<QualifiedProperty<?>> milestoningQualifiedPropertyWithArg = newSingleDateMilestoningQualifiedPropertyWithArg(context, sourceClass, propertyOwner, originalProperty, returnTypeMilestoningStereotype, withMilestoningStereotype, edgePointProperty);
MutableList<QualifiedProperty<?>> milestoningRangeQualifiedProperty = generateMilestoningRangeQualifiedProperty(context, sourceClass, propertyOwner, originalProperty, returnTypeMilestoningStereotype, withMilestoningStereotype, edgePointProperty);
List<MilestoningStereotype> sourceMilestoningStereotype = temporalStereotypes(sourceClass._stereotypes());
milestoningQualifiedPropertyWithArg.withAll(milestoningRangeQualifiedProperty);
if (!sourceMilestoningStereotype.isEmpty() && (sourceMilestoningStereotype.get(0).equals(returnTypeMilestoningStereotypes.get(0)) || MilestoningStereotypeEnum.bitemporal.equals(sourceMilestoningStereotype.get(0)))) {
QualifiedProperty<?> milestoningQualifiedPropertyNoArg = newSingleDateMilestoningQualifiedPropertyNoArg(context, sourceClass, propertyOwner, originalProperty, returnTypeMilestoningStereotype, withMilestoningStereotype, edgePointProperty);
milestoningQualifiedPropertyWithArg.add(milestoningQualifiedPropertyNoArg);
}
milestoningPropertyTransformation.setQualifiedProperties(milestoningQualifiedPropertyWithArg);
}
return milestoningPropertyTransformation;
}
Aggregations