Search in sources :

Example 1 with MilestoningStereotype

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());
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)

Example 2 with MilestoningStereotype

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;
}
Also used : ElementWithStereotypes(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)

Example 3 with MilestoningStereotype

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());
        }
    }
}
Also used : MutableSet(org.eclipse.collections.api.set.MutableSet) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) MilestoningStereotype(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) MilestoningStereotypeEnum(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotypeEnum) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 4 with MilestoningStereotype

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;
}
Also used : Root_meta_pure_metamodel_function_LambdaFunction_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_LambdaFunction_Impl) Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) Root_meta_pure_metamodel_type_generics_GenericType_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Example 5 with MilestoningStereotype

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;
}
Also used : MilestoningStereotype(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype) MilestoningStereotype(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype) Stereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Aggregations

Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)5 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)5 MilestoningStereotype (org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype)4 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)4 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)4 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)4 Root_meta_pure_metamodel_function_LambdaFunction_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_LambdaFunction_Impl)3 Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl)3 Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl)3 Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl)3 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)3 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)3 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)3 SimpleFunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression)3 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)3 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)3 Pair (org.eclipse.collections.api.tuple.Pair)2 MutableSet (org.eclipse.collections.api.set.MutableSet)1 Root_meta_pure_metamodel_function_property_Property_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_property_Property_Impl)1 MilestoningDates (org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDates)1