Search in sources :

Example 1 with ClassProjection

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection in project legend-pure by finos.

the class FunctionExpressionProcessor method findFunctionForPropertyBasedOnMultiplicity.

private static AbstractProperty<?> findFunctionForPropertyBasedOnMultiplicity(FunctionExpression propertyFunction, GenericType sourceGenericType, ProcessorState state, ProcessorSupport processorSupport, Matcher matcher) throws PureCompilationException {
    String propertyName = propertyFunction._propertyName()._valuesCoreInstance().toList().get(0).getName();
    Type sourceType = (Type) ImportStub.withImportStubByPass(sourceGenericType._rawTypeCoreInstance(), processorSupport);
    AbstractProperty<?> property = (AbstractProperty<?>) processorSupport.class_findPropertyUsingGeneralization(sourceType, propertyName);
    if (null == property) {
        if (sourceType instanceof ClassProjection) {
            PostProcessor.processElement(matcher, sourceType, state, processorSupport);
            property = (AbstractProperty<?>) processorSupport.class_findPropertyUsingGeneralization(sourceType, propertyName);
        }
        if (null == property) {
            ListIterable<QualifiedProperty<?>> qualifiedProperties = _Class.findQualifiedPropertiesUsingGeneralization(sourceType, propertyName, processorSupport);
            if (qualifiedProperties.isEmpty() && sourceType instanceof ClassProjection) {
                PostProcessor.processElement(matcher, sourceType, state, processorSupport);
                qualifiedProperties = _Class.findQualifiedPropertiesUsingGeneralization(sourceType, propertyName, processorSupport);
            }
            property = (AbstractProperty<?>) findSingleArgumentQualifiedProperty(qualifiedProperties, processorSupport);
            if (null == property) {
                StringBuilder message = new StringBuilder();
                switch(qualifiedProperties.size()) {
                    case 0:
                        {
                            PackageableElement.writeUserPathForPackageableElement(message.append("Can't find the property '").append(propertyName).append("' in the class "), sourceType);
                            break;
                        }
                    case 1:
                        {
                            property = qualifiedProperties.get(0);
                            message.append("The property '").append(propertyName).append("' ");
                            if (MilestoningFunctions.isGeneratedMilestoningProperty(property, processorSupport)) {
                                if (MilestoningFunctions.isAllVersionsInRangeProperty(property, processorSupport)) {
                                    milestoningMissingDateParamErrorMsgForAllVersionInRange(processorSupport, property, message);
                                } else {
                                    milestoningMissingDateParamErrorMsg(processorSupport, property, message);
                                }
                            } else {
                                message.append("requires some parameters.");
                            }
                            break;
                        }
                    default:
                        {
                            if (// bitemporal
                            qualifiedProperties.allSatisfy(qp -> MilestoningFunctions.isGeneratedMilestoningProperty(qp, processorSupport))) {
                                message.append("The property '").append(propertyName).append("' ");
                                milestoningMissingDateParamErrorMsg(processorSupport, qualifiedProperties.getFirst(), message);
                            } else {
                                message.append("There are ").append(qualifiedProperties.size()).append(" properties named '").append(propertyName).append("' and all require additional parameters.");
                            }
                        }
                }
                SourceInformation sourceInfo = propertyFunction._propertyName().getSourceInformation();
                throw new PureCompilationException(sourceInfo, message.toString());
            }
        }
    }
    return property;
}
Also used : ParameterValueSpecificationContext(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ParameterValueSpecificationContext) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) ImportGroup(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup) SetIterable(org.eclipse.collections.api.set.SetIterable) MilestonedPropertyMetaData(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestonedPropertyMetaData) ClassProjection(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection) FunctionDefinitionProcessor(org.finos.legend.pure.m3.compiler.postprocessing.processor.FunctionDefinitionProcessor) MutableList(org.eclipse.collections.api.list.MutableList) ProcessorState(org.finos.legend.pure.m3.compiler.postprocessing.ProcessorState) PureUnmatchedFunctionException(org.finos.legend.pure.m3.exception.PureUnmatchedFunctionException) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) MutableSet(org.eclipse.collections.api.set.MutableSet) TypeInferenceContext(org.finos.legend.pure.m3.compiler.postprocessing.inference.TypeInferenceContext) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) RichIterable(org.eclipse.collections.api.RichIterable) GenericTypeTraceability(org.finos.legend.pure.m3.compiler.postprocessing.GenericTypeTraceability) PostProcessor(org.finos.legend.pure.m3.compiler.postprocessing.PostProcessor) Automap(org.finos.legend.pure.m3.compiler.postprocessing.processor.Automap) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException) ModelRepository(org.finos.legend.pure.m4.ModelRepository) KeyValueValueSpecificationContext(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.KeyValueValueSpecificationContext) TypeInference(org.finos.legend.pure.m3.compiler.postprocessing.inference.TypeInference) ListHelper(org.finos.legend.pure.m3.tools.ListHelper) Matcher(org.finos.legend.pure.m3.tools.matcher.Matcher) Objects(java.util.Objects) UnbindState(org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) org.finos.legend.pure.m3.navigation._class._Class(org.finos.legend.pure.m3.navigation._class._Class) ValueSpecificationBootstrap(org.finos.legend.pure.m3.navigation.ValueSpecificationBootstrap) ImportStub(org.finos.legend.pure.m3.navigation.importstub.ImportStub) MilestoningDatesPropagationFunctions(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDatesPropagationFunctions) ListIterable(org.eclipse.collections.api.list.ListIterable) Processor(org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor) FunctionExpressionMatcher(org.finos.legend.pure.m3.compiler.postprocessing.functionmatch.FunctionExpressionMatcher) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) Instance(org.finos.legend.pure.m3.navigation.Instance) Unbinder(org.finos.legend.pure.m3.compiler.unload.Unbinder) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Lists(org.eclipse.collections.api.factory.Lists) FunctionDefinition(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition) PartitionSet(org.eclipse.collections.api.partition.set.PartitionSet) M3Paths(org.finos.legend.pure.m3.navigation.M3Paths) Context(org.finos.legend.pure.m3.compiler.Context) VariableNameConflictException(org.finos.legend.pure.m3.compiler.postprocessing.VariableContext.VariableNameConflictException) ImportAccessor(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportAccessor) Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) TypeInferenceObserver(org.finos.legend.pure.m3.compiler.postprocessing.inference.TypeInferenceObserver) Package(org.finos.legend.pure.m3.coreinstance.Package) LambdaFunctionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunctionInstance) Sets(org.eclipse.collections.api.factory.Sets) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) MilestoningFunctions(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningFunctions) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Visibility(org.finos.legend.pure.m3.compiler.visibility.Visibility) KeyExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.lang.KeyExpression) M3Properties(org.finos.legend.pure.m3.navigation.M3Properties) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) ClassProjection(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with ClassProjection

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection in project legend-pure by finos.

the class ClassProjectionUnloaderWalk method run.

@Override
public void run(ClassProjection classProjection, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    RootRouteNode treeRoot = classProjection._projectionSpecification();
    matcher.fullMatch(treeRoot, state);
}
Also used : RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)

Example 3 with ClassProjection

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection in project legend-pure by finos.

the class ProjectionUtil method deepCopyAndBindQualifiedProperty.

public static QualifiedProperty deepCopyAndBindQualifiedProperty(QualifiedProperty originalProperty, ClassProjection projection, ProcessorState state, ModelRepository modelRepository, Context context, ProcessorSupport processorSupport) {
    QualifiedProperty propertyCopy = createQualifiedPropertyCopy(originalProperty, projection, modelRepository, processorSupport);
    if (originalProperty._functionName() != null) {
        propertyCopy._functionName(originalProperty._functionName());
    } else if (propertyCopy._functionName() != null) {
        propertyCopy._functionNameRemove();
    }
    GenericType ownerType = projection._classifierGenericType()._typeArguments().getFirst();
    FunctionType classifierFunctionType = (FunctionType) ImportStub.withImportStubByPass(propertyCopy._classifierGenericType()._typeArguments().getFirst()._rawTypeCoreInstance(), processorSupport);
    VariableExpression propertyOwner = classifierFunctionType._parameters().getFirst();
    propertyOwner._genericType((GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(ownerType, processorSupport));
    classifierFunctionType._functionCoreInstance(Lists.immutable.of(propertyCopy));
    ValueSpecification functionExpression = copyValueSpecification(((RichIterable<ValueSpecification>) originalProperty._expressionSequence()).getFirst(), modelRepository, context, processorSupport, state, projection);
    propertyCopy._expressionSequence(Lists.immutable.with(functionExpression));
    return propertyCopy;
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Example 4 with ClassProjection

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection in project legend-pure by finos.

the class ProjectionUtil method copyFunctionExpression.

private static void copyFunctionExpression(FunctionExpression valueSpecification, final ModelRepository modelRepository, final Context context, final ProcessorSupport processorSupport, final MutableMap<CoreInstance, CoreInstance> processedMap, final ProcessorState state, final ClassProjection classProjection, FunctionExpression copy) {
    RichIterable<? extends CoreInstance> valueCopies = valueSpecification._parametersValues().collect(new Function<ValueSpecification, CoreInstance>() {

        @Override
        public CoreInstance valueOf(ValueSpecification instance) {
            return copyValueSpecification(instance, modelRepository, context, processorSupport, processedMap, state, classProjection);
        }
    });
    copy._parametersValues((RichIterable<? extends ValueSpecification>) valueCopies);
    if (valueSpecification._importGroup() != null) {
        copy._importGroup(valueSpecification._importGroup());
    } else if (copy._importGroup() != null) {
        copy._importGroupRemove();
    }
    if (valueSpecification._functionName() != null) {
        copy._functionName(valueSpecification._functionName());
    } else if (copy._functionName() != null) {
        copy._functionNameRemove();
    }
    if (valueSpecification._propertyName() != null) {
        InstanceValue propertyNameSource = valueSpecification._propertyName();
        InstanceValue propertyNameCopy = (InstanceValue) copyValueSpecification(propertyNameSource, modelRepository, context, processorSupport, state, classProjection);
        propertyNameCopy._genericType((GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(propertyNameSource._genericType(), processorSupport));
        propertyNameCopy._multiplicity((Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.copyMultiplicity(propertyNameSource._multiplicity(), false, processorSupport));
        copy._propertyName(propertyNameCopy);
    }
    if (valueSpecification._qualifiedPropertyName() != null) {
        InstanceValue propertyNameSource = valueSpecification._qualifiedPropertyName();
        InstanceValue qualifiedPropertyNameCopy = (InstanceValue) copyValueSpecification(propertyNameSource, modelRepository, context, processorSupport, state, classProjection);
        qualifiedPropertyNameCopy._genericType((GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(propertyNameSource._genericType(), processorSupport));
        qualifiedPropertyNameCopy._multiplicity((Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.copyMultiplicity(propertyNameSource._multiplicity(), false, processorSupport));
        copy._qualifiedPropertyName(qualifiedPropertyNameCopy);
    }
}
Also used : ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)

Example 5 with ClassProjection

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection in project legend-pure by finos.

the class FunctionExpressionProcessor method findFunctionsForQualifiedPropertyBasedOnMultiplicity.

private static ListIterable<QualifiedProperty<?>> findFunctionsForQualifiedPropertyBasedOnMultiplicity(FunctionExpression propertyFunction, GenericType sourceGenericType, ListIterable<? extends ValueSpecification> parametersValues, ProcessorSupport processorSupport, Matcher matcher, ProcessorState state) throws PureCompilationException {
    String propertyName = propertyFunction._qualifiedPropertyName()._valuesCoreInstance().toList().get(0).getName();
    Type sourceRawType = (Type) ImportStub.withImportStubByPass(sourceGenericType._rawTypeCoreInstance(), processorSupport);
    if (sourceRawType instanceof ClassProjection) {
        PostProcessor.processElement(matcher, sourceRawType, state, processorSupport);
    }
    VariableExpression firstParam = (VariableExpression) processorSupport.newAnonymousCoreInstance(null, M3Paths.VariableExpression);
    firstParam._genericType(parametersValues.get(0)._genericType());
    firstParam._multiplicity((Multiplicity) processorSupport.package_getByUserPath(M3Paths.PureOne));
    MutableList<ValueSpecification> params = Lists.mutable.<ValueSpecification>with(firstParam).withAll(ListHelper.tail(parametersValues));
    ListIterable<QualifiedProperty<?>> properties = _Class.findQualifiedPropertiesUsingGeneralization(sourceRawType, propertyName, processorSupport);
    SourceInformation sourceInformation = propertyFunction._qualifiedPropertyName().getSourceInformation();
    ListIterable<QualifiedProperty<?>> foundFunctions = FunctionExpressionMatcher.getFunctionMatches(properties, params, propertyName, sourceInformation, true, processorSupport);
    if (foundFunctions.isEmpty()) {
        throwNoMatchException(propertyName, params, sourceInformation, processorSupport);
    }
    return foundFunctions;
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) ClassProjection(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Aggregations

GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)8 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)8 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)7 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)7 RootRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)6 ClassProjection (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjection)6 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)5 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)5 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)5 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)5 ListIterable (org.eclipse.collections.api.list.ListIterable)4 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)4 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)4 RichIterable (org.eclipse.collections.api.RichIterable)3 MutableList (org.eclipse.collections.api.list.MutableList)3 UnbindState (org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState)3 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)3 Objects (java.util.Objects)2 Lists (org.eclipse.collections.api.factory.Lists)2 FunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition)2