Search in sources :

Example 1 with QualifiedProperty

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty in project legend-pure by finos.

the class TypeInference method storeInferredTypeParametersInFunctionExpression.

public static void storeInferredTypeParametersInFunctionExpression(FunctionExpression functionExpression, ProcessorState state, ProcessorSupport processorSupport, Function<?> foundFunction) throws PureCompilationException {
    // Store the inferred params in the FunctionExpression
    if (!(foundFunction instanceof QualifiedProperty)) {
        TypeInferenceContext typeInferenceContext = state.getTypeInferenceContext();
        FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(foundFunction);
        functionType._typeParameters().forEach(typeParameter -> {
            CoreInstance value = typeInferenceContext.getTypeParameterValue(typeParameter._name());
            if (value != null) {
                functionExpression._resolvedTypeParametersAdd((GenericType) value);
            } else if (typeInferenceContext.getParent() == null) {
                StringBuilder builder = new StringBuilder("The type parameter ").append(typeParameter._name()).append(" was not resolved (").append(foundFunction._functionName()).append(" / ");
                org.finos.legend.pure.m3.navigation.function.FunctionType.print(builder, functionType, processorSupport).append(")!");
                throw new PureCompilationException(functionExpression.getSourceInformation(), builder.toString());
            }
        });
        functionType._multiplicityParameters().forEach(multiplicityParameter -> {
            String parameterName = multiplicityParameter._valuesCoreInstance().getFirst().getName();
            CoreInstance value = typeInferenceContext.getMultiplicityParameterValue(parameterName);
            if (value != null) {
                functionExpression._resolvedMultiplicityParametersAdd((Multiplicity) value);
            } else {
                throw new PureCompilationException(functionExpression.getSourceInformation(), "The multiplicity parameter " + parameterName + " was not resolved!");
            }
        });
    }
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with QualifiedProperty

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty in project legend-pure by finos.

the class AssociationProcessor method getPropertyNameForLeftSideOfQualifiedPropertyFilter.

private static String getPropertyNameForLeftSideOfQualifiedPropertyFilter(Association association, QualifiedProperty qualifiedProperty, ValueSpecification instance, Context context, ProcessorSupport processorSupport) {
    String functionName = instance instanceof FunctionExpression ? ((FunctionExpression) instance)._functionName() : null;
    String propertyNameForLeftSideOfQualifiedPropertyFilter;
    if ("filter".equals(functionName)) {
        ValueSpecification leftSideOfFilter = ((FunctionExpression) instance)._parametersValues().toList().getFirst();
        CoreInstance propertyName = leftSideOfFilter instanceof FunctionExpression ? ((FunctionExpression) leftSideOfFilter)._propertyName()._valuesCoreInstance().toList().getFirst() : null;
        ValueSpecification variableExpression = leftSideOfFilter instanceof FunctionExpression ? ((FunctionExpression) leftSideOfFilter)._parametersValues().toList().getFirst() : null;
        String variableExpressionName = variableExpression instanceof VariableExpression ? ((VariableExpression) variableExpression)._name() : null;
        if (!"this".equals(variableExpressionName)) {
            throw new PureCompilationException(instance.getSourceInformation(), validQualifiedPropertyInAssociationMsg() + qualifiedPropertyCompileErrorMsgPrefix(association, qualifiedProperty) + " left side of filter should refer to '$this' not '" + variableExpressionName + "'");
        }
        propertyNameForLeftSideOfQualifiedPropertyFilter = Objects.requireNonNull(propertyName).getName();
    } else {
        ValueSpecification firstParamValue = instance instanceof FunctionExpression ? ((FunctionExpression) instance)._parametersValues().toList().getFirst() : null;
        if (firstParamValue != null) {
            propertyNameForLeftSideOfQualifiedPropertyFilter = getPropertyNameForLeftSideOfQualifiedPropertyFilter(association, qualifiedProperty, firstParamValue, context, processorSupport);
        } else {
            throw new PureCompilationException(qualifiedProperty.getSourceInformation(), validQualifiedPropertyInAssociationMsg() + qualifiedPropertyCompileErrorMsgPrefix(association, qualifiedProperty) + " does not use the 'filter' function");
        }
    }
    return propertyNameForLeftSideOfQualifiedPropertyFilter;
}
Also used : FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 3 with QualifiedProperty

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty in project legend-pure by finos.

the class AssociationProcessor method updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams.

private static void updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams(Association association, QualifiedProperty qualifiedProperty, final Class qualifiedPropertyReturnType, ListIterable<? extends Property> assnProperties, final Context context, final ProcessorSupport processorSupport) {
    validateQualifiedPropertyLeftSideOfFilterByPropertyName(association, qualifiedProperty, qualifiedPropertyReturnType, assnProperties, context, processorSupport);
    Property leftSideOfFilterProperty = getQualifiedPropertiesFilterLeftSideParam(qualifiedPropertyReturnType, assnProperties, processorSupport);
    Property leftSideOfFilterOtherProperty = assnProperties.detect(Predicates.notEqual(leftSideOfFilterProperty));
    GenericType leftSideOfFilterOtherPropertyGenericType = leftSideOfFilterOtherProperty._genericType();
    FunctionType functionType = (FunctionType) qualifiedProperty._classifierGenericType()._typeArguments().toList().getFirst()._rawTypeCoreInstance();
    Iterable<? extends VariableExpression> functionTypeParams = functionType._parameters();
    for (VariableExpression functionTypeParam : functionTypeParams) {
        if (functionTypeParam != null && "this".equals(functionTypeParam._name())) {
            GenericType genericTypeCopy = (GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(leftSideOfFilterOtherPropertyGenericType, processorSupport);
            functionTypeParam._genericType(genericTypeCopy);
            context.update(functionTypeParam);
            if (functionTypeParam.hasBeenValidated()) {
                functionTypeParam.markNotValidated();
                context.update(functionTypeParam);
            }
        }
    }
}
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) 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) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)

Example 4 with QualifiedProperty

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty in project legend-pure by finos.

the class AssociationProcessor method processAssociationQualifiedProperty_internal.

private static void processAssociationQualifiedProperty_internal(Association association, QualifiedProperty qualifiedProperty, Class sourceRawType, Context context, ProcessorSupport processorSupport) {
    addQualifiedPropertyToRawType(qualifiedProperty, sourceRawType, context);
    Class qualifiedPropertyReturnType = (Class) ImportStub.withImportStubByPass(qualifiedProperty._genericType()._rawTypeCoreInstance(), processorSupport);
    ListIterable<? extends Property<?, ?>> assnProperties = association._properties().toList();
    updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams(association, qualifiedProperty, qualifiedPropertyReturnType, assnProperties, context, processorSupport);
    context.update(qualifiedProperty);
}
Also used : Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)

Example 5 with QualifiedProperty

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty in project legend-pure by finos.

the class AssociationProcessor method processNonMilestonedQualifiedProperties.

private static void processNonMilestonedQualifiedProperties(Association association, Class leftRawType, Class rightRawType, Context context, ProcessorSupport processorSupport) {
    RichIterable<? extends QualifiedProperty> qualifiedProperties = association._qualifiedProperties();
    if (qualifiedProperties.notEmpty()) {
        SetIterable<? extends Class> validReturnTypes = Sets.immutable.with(leftRawType, rightRawType);
        ListIterable<? extends Property<?, ?>> assnProperties = association._properties().toList();
        for (QualifiedProperty qualifiedProperty : qualifiedProperties) {
            Class qualifiedPropertyReturnType = (Class) ImportStub.withImportStubByPass(qualifiedProperty._genericType()._rawTypeCoreInstance(), processorSupport);
            validateQualifiedPropertyReturnType(association, qualifiedProperty, qualifiedPropertyReturnType, validReturnTypes);
            Class sourceType = (leftRawType == qualifiedPropertyReturnType) ? rightRawType : leftRawType;
            addQualifiedPropertyToRawType(qualifiedProperty, sourceType, context);
            updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams(association, qualifiedProperty, qualifiedPropertyReturnType, assnProperties, context, processorSupport);
            context.update(qualifiedProperty);
        }
    }
}
Also used : Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Aggregations

QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)27 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)16 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)16 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)15 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)15 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)11 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)10 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)10 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)9 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)9 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)7 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)7 RichIterable (org.eclipse.collections.api.RichIterable)6 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)6 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)6 SimpleFunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression)6 MilestonedPropertyMetaData (org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestonedPropertyMetaData)5 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)5 ListIterable (org.eclipse.collections.api.list.ListIterable)4 Pair (org.eclipse.collections.api.tuple.Pair)4