Search in sources :

Example 1 with ModelRepository

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;
}
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) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) 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) 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 2 with ModelRepository

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();
    }
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) GeneratedMilestonedProperties(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.GeneratedMilestonedProperties) 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 3 with ModelRepository

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);
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 4 with ModelRepository

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;
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 5 with ModelRepository

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());
        }
    }
}
Also used : Multiplicity(org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) ModelRepository(org.finos.legend.pure.m4.ModelRepository) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) Lists(org.eclipse.collections.api.factory.Lists) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) MutableList(org.eclipse.collections.api.list.MutableList) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) M3Paths(org.finos.legend.pure.m3.navigation.M3Paths) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ImportStub(org.finos.legend.pure.m3.navigation.importstub.ImportStub) Package(org.finos.legend.pure.m3.coreinstance.Package) ListIterable(org.eclipse.collections.api.list.ListIterable) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException) Package(org.finos.legend.pure.m3.coreinstance.Package) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)94 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)51 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)34 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)25 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)21 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)18 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)17 ModelRepository (org.finos.legend.pure.m4.ModelRepository)17 AntlrSourceInformation (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation)13 RichIterable (org.eclipse.collections.api.RichIterable)12 ListIterable (org.eclipse.collections.api.list.ListIterable)12 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)11 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)11 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)11 M4Parser (org.finos.legend.pure.m4.serialization.grammar.M4Parser)11 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)10 VoidM4StateListener (org.finos.legend.pure.m4.statelistener.VoidM4StateListener)10 ValidatorState (org.finos.legend.pure.m3.compiler.validation.ValidatorState)9 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)9 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)8