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;
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations