use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association 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;
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association 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);
}
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association 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);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association 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);
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association in project legend-pure by finos.
the class AssociationProcessor method process.
@Override
public void process(Association association, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
RichIterable<? extends AbstractProperty> properties = association._properties();
RichIterable<? extends AbstractProperty> originalMilestonedProperties = association._originalMilestonedProperties();
RichIterable<? extends AbstractProperty> qualifiedProperties = association._qualifiedProperties();
for (AbstractProperty property : LazyIterate.concatenate((Iterable<AbstractProperty>) properties, (Iterable<AbstractProperty>) qualifiedProperties).concatenate((Iterable<AbstractProperty>) originalMilestonedProperties)) {
PostProcessor.processElement(matcher, property, state, processorSupport);
}
}
Aggregations