use of org.finos.legend.pure.m4.ModelRepository in project legend-pure by finos.
the class TypeInference method processParamTypesOfLambdaUsedAsAFunctionExpressionParamValue.
public static boolean processParamTypesOfLambdaUsedAsAFunctionExpressionParamValue(ValueSpecification instanceValueContainer, LambdaFunction<?> lambdaFunction, VariableExpression templateToMatchLambdaTo, Matcher matcher, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) throws PureCompilationException {
GenericType templateGenericType = templateToMatchLambdaTo._genericType();
Type templateFunctionType = templateGenericType._typeArguments().notEmpty() ? (Type) ImportStub.withImportStubByPass(templateGenericType._typeArguments().getFirst()._rawTypeCoreInstance(), processorSupport) : null;
FunctionType lambdaFunctionType = (FunctionType) ImportStub.withImportStubByPass(lambdaFunction._classifierGenericType()._typeArguments().getFirst()._rawTypeCoreInstance(), processorSupport);
if (org.finos.legend.pure.m3.navigation.generictype.GenericType.isGenericTypeConcrete(templateGenericType) && org.finos.legend.pure.m3.navigation.type.Type.subTypeOf(ImportStub.withImportStubByPass(templateGenericType._rawTypeCoreInstance(), processorSupport), processorSupport.package_getByUserPath(M3Paths.Function), processorSupport)) {
ListIterable<? extends VariableExpression> parameters = ListHelper.wrapListIterable(lambdaFunctionType._parameters());
for (int j = 0; j < parameters.size(); j++) {
VariableExpression param = parameters.get(j);
if (param._genericType() == null) {
if (org.finos.legend.pure.m3.navigation.type.Type.isBottomType(templateFunctionType, processorSupport) || org.finos.legend.pure.m3.navigation.type.Type.isTopType(templateFunctionType, processorSupport)) {
throw new PureCompilationException(lambdaFunction.getSourceInformation(), "Can't infer the parameters' types for the lambda. Please specify it in the signature.");
}
VariableExpression templateParam = ListHelper.wrapListIterable(((FunctionType) Objects.requireNonNull(templateFunctionType))._parameters()).get(j);
CoreInstance genericType = org.finos.legend.pure.m3.navigation.generictype.GenericType.makeTypeArgumentAsConcreteAsPossible(templateParam._genericType(), state.getTypeInferenceContext().getTypeParameterToGenericType(), state.getTypeInferenceContext().getMultiplicityParameterToMultiplicity(), processorSupport);
if (state.getTypeInferenceContext().isTypeParameterResolved(genericType)) {
genericType = state.getTypeInferenceContext().resolve(genericType);
} else {
return true;
}
CoreInstance multiplicity = org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.makeMultiplicityAsConcreteAsPossible(templateParam._multiplicity(), state.getTypeInferenceContext().getMultiplicityParameterToMultiplicity());
param._genericType((GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericTypeAsInferredGenericType(genericType, param.getSourceInformation(), processorSupport));
param._multiplicity((Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.copyMultiplicity(multiplicity, param.getSourceInformation(), processorSupport));
}
}
state.pushVariableContext();
FunctionDefinitionProcessor.process(lambdaFunction, state, matcher, repository);
LambdaFunctionProcessor.process(lambdaFunction, state, matcher, repository);
state.popVariableContext();
} else {
throw new PureCompilationException(lambdaFunction.getSourceInformation(), "Can't infer the parameters' types for the lambda. Please specify it in the signature.");
}
instanceValueContainer._genericTypeRemove();
InstanceValueProcessor.updateInstanceValue(instanceValueContainer, processorSupport);
return false;
}
use of org.finos.legend.pure.m4.ModelRepository in project legend-pure by finos.
the class AssociationProcessor method processAssociationProperty.
private static ListIterable<AbstractProperty<?>> processAssociationProperty(Association association, Property property, GenericType sourceGenericType, Class sourceRawType, ModelRepository modelRepository, Context context, ProcessorSupport processorSupport) {
GeneratedMilestonedProperties generatedMilestonedProperties = MilestoningPropertyProcessor.processAssociationProperty(association, sourceRawType, property, context, processorSupport, modelRepository);
if (generatedMilestonedProperties.hasGeneratedProperties()) {
processOriginalMilestonedProperty(association, property, sourceGenericType, context, processorSupport);
Property edgePointProperty = (Property) generatedMilestonedProperties.getEdgePointProperty();
processAssociationProperty_internal(edgePointProperty, sourceGenericType, sourceRawType, context);
for (CoreInstance qualifiedProperty : generatedMilestonedProperties.getQualifiedProperties()) {
processAssociationQualifiedProperty_internal(association, (QualifiedProperty) qualifiedProperty, sourceRawType, context, processorSupport);
}
if (association.hasBeenValidated()) {
association.markNotValidated();
}
return generatedMilestonedProperties.getAllGeneratedProperties();
} else {
processAssociationProperty_internal(property, sourceGenericType, sourceRawType, context);
return Lists.immutable.empty();
}
}
use of org.finos.legend.pure.m4.ModelRepository in project legend-pure by finos.
the class ReferenceUsage method addReferenceUsage_internal.
private static void addReferenceUsage_internal(CoreInstance used, CoreInstance user, String propertyName, int offset, ModelRepository repository, ProcessorSupport processorSupport, SourceInformation sourceInformationForUsage) {
CoreInstance usageReference = createReferenceUsage(user, propertyName, offset, repository, processorSupport);
usageReference.setSourceInformation(sourceInformationForUsage);
Instance.addValueToProperty(used, M3Properties.referenceUsages, usageReference, processorSupport);
}
use of org.finos.legend.pure.m4.ModelRepository in project legend-pure by finos.
the class ReferenceUsage method createReferenceUsage.
/**
* Create a ReferenceUsage instance. Note that this does add the
* reference usage anywhere - it just creates the object.
*
* @param owner instance that uses the referenced instance
* @param propertyName name of the property for the reference
* @param offset offset of the reference in the list of property values
* @param repository model repository
* @param processorSupport processor support
* @return ReferenceUsage instance
*/
public static CoreInstance createReferenceUsage(CoreInstance owner, String propertyName, int offset, ModelRepository repository, ProcessorSupport processorSupport) {
CoreInstance referenceUsage = processorSupport.newAnonymousCoreInstance(null, M3Paths.ReferenceUsage);
referenceUsage.addKeyValue(M3PropertyPaths.owner_ReferenceUsage, owner);
referenceUsage.addKeyValue(M3PropertyPaths.propertyName_ReferenceUsage, repository.newStringCoreInstance_cached(propertyName));
referenceUsage.addKeyValue(M3PropertyPaths.offset_ReferenceUsage, repository.newIntegerCoreInstance(offset));
return referenceUsage;
}
use of org.finos.legend.pure.m4.ModelRepository in project legend-pure by finos.
the class ConcreteFunctionDefinitionNameProcessor method process.
public static void process(Function<?> function, ModelRepository repository, ProcessorSupport processorSupport) throws PureCompilationException {
Package parent = function._package();
if (parent != null) {
// Make sure we have a unique name for overloaded functions.
String signature = getSignatureAndResolveImports(function, repository, processorSupport);
parent._childrenRemove(function);
function.setName(signature);
parent._childrenAdd(function);
if (function._name() == null) {
function._name(signature);
}
if (parent._children().count(c -> signature.equals(c.getName())) > 1) {
ListIterable<SourceInformation> sourceInfos = parent._children().collectIf(c -> signature.equals(c.getName()), CoreInstance::getSourceInformation, Lists.mutable.empty()).sortThis();
String pkg = PackageableElement.getUserPathForPackageableElement(parent);
if (M3Paths.Root.equals(pkg)) {
pkg = "::";
}
StringBuilder message = new StringBuilder("The function '").append(signature).append("' is defined more than once in the package '").append(pkg).append("' at: ");
boolean first = true;
for (SourceInformation sourceInfo : sourceInfos) {
if (first) {
first = false;
} else {
message.append(", ");
}
message.append(sourceInfo.getSourceId()).append(" (line:").append(sourceInfo.getLine()).append(" column:").append(sourceInfo.getColumn()).append(')');
}
throw new PureCompilationException(function.getSourceInformation(), message.toString());
}
}
}
Aggregations