Search in sources :

Example 1 with GrammarInfoStub

use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.

the class PureInstanceSetImplementationProcessor method process.

@Override
public void process(PureInstanceSetImplementation classMapping, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    Type srcClass = (Type) ImportStub.withImportStubByPass(classMapping._srcClassCoreInstance(), processorSupport);
    SourceInformation srcGenericTypeSourceInfo = null;
    LambdaFunction<?> filter = classMapping._filter();
    if (filter != null) {
        state.pushVariableContext();
        if (srcClass != null) {
            FunctionType fType = getFunctionType(filter, processorSupport);
            fType._parameters(Lists.mutable.<VariableExpression>withAll(fType._parameters()).with(createSrcParameter(srcClass, srcGenericTypeSourceInfo, filter.getSourceInformation(), processorSupport)));
        }
        matcher.fullMatch(filter, state);
        state.popVariableContext();
    }
    int i = 0;
    for (PropertyMapping propertyMapping : classMapping._propertyMappings()) {
        state.pushVariableContext();
        if (((PurePropertyMapping) propertyMapping)._transformerCoreInstance() != null) {
            GrammarInfoStub transformerStub = (GrammarInfoStub) ((PurePropertyMapping) propertyMapping)._transformerCoreInstance();
            EnumerationMappingProcessor.processsEnumerationTransformer(transformerStub, propertyMapping, processorSupport);
        }
        LambdaFunction<?> transform = ((PurePropertyMapping) propertyMapping)._transform();
        if (srcClass != null) {
            FunctionType fType = getFunctionType(transform, processorSupport);
            fType._parameters(Lists.mutable.<VariableExpression>withAll(fType._parameters()).with(createSrcParameter(srcClass, srcGenericTypeSourceInfo, propertyMapping.getSourceInformation(), processorSupport)));
        }
        matcher.fullMatch(transform, state);
        ValueSpecification expressionSequence = transform._expressionSequence().getFirst();
        if (expressionSequence != null) {
            PropertyMappingValueSpecificationContext usageContext = (PropertyMappingValueSpecificationContext) processorSupport.newAnonymousCoreInstance(null, M2MappingPaths.PropertyMappingValueSpecificationContext);
            usageContext._offset(i);
            usageContext._propertyMapping(propertyMapping);
            expressionSequence._usageContext(usageContext);
        }
        i++;
        state.popVariableContext();
    }
}
Also used : Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) 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) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) GrammarInfoStub(org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) PropertyMappingValueSpecificationContext(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingValueSpecificationContext)

Example 2 with GrammarInfoStub

use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.

the class EnumerationMappingProcessor method processsEnumerationTransformer.

public static void processsEnumerationTransformer(GrammarInfoStub enumerationTransformer, PropertyMapping propertyMapping, ProcessorSupport processorSupport) {
    if (enumerationTransformer != null) {
        String transformerString = (String) enumerationTransformer._value();
        String mappingName = StringIterate.getFirstToken(transformerString, ",");
        String transformerName = StringIterate.getLastToken(transformerString, ",");
        Mapping mapping = (Mapping) processorSupport.package_getByUserPath(mappingName);
        if (mapping == null) {
            throw new PureCompilationException(propertyMapping.getSourceInformation(), "The mapping '" + mappingName + "' is unknown'. Likely a parser error");
        }
        EnumerationMapping<?> transformer = org.finos.legend.pure.m2.dsl.mapping.Mapping.getEnumerationMappingByName(mapping, transformerName, processorSupport);
        if (transformer == null) {
            throw new PureCompilationException(propertyMapping.getSourceInformation(), "The transformer '" + transformerName + "' is unknown or is not of type EnumerationMapping in the Mapping '" + mappingName + "' for property " + ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport).getName());
        }
        enumerationTransformer._original(enumerationTransformer._value());
        enumerationTransformer._value(transformer);
    }
}
Also used : PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 3 with GrammarInfoStub

use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.

the class PureInstanceSetImplementationUnbind method run.

@Override
public void run(PureInstanceSetImplementation pureInstanceSetImplementation, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ImportStub srcClass = (ImportStub) pureInstanceSetImplementation._srcClassCoreInstance();
    if (srcClass != null) {
        Shared.cleanUpReferenceUsage(srcClass, pureInstanceSetImplementation, state.getProcessorSupport());
        Shared.cleanImportStub(srcClass, state.getProcessorSupport());
    }
    LambdaFunction filter = pureInstanceSetImplementation._filter();
    if (filter != null) {
        matcher.fullMatch(filter, state);
        ((FunctionType) org.finos.legend.pure.m3.navigation.importstub.ImportStub.withImportStubByPass(filter._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), state.getProcessorSupport()))._parametersRemove();
    }
    for (PropertyMapping propertyMapping : pureInstanceSetImplementation._propertyMappings()) {
        Shared.cleanPropertyStub(propertyMapping._propertyCoreInstance(), state.getProcessorSupport());
        LambdaFunction transform = ((PurePropertyMapping) propertyMapping)._transform();
        matcher.fullMatch(transform, state);
        FunctionType functionType = (FunctionType) org.finos.legend.pure.m3.navigation.importstub.ImportStub.withImportStubByPass(transform._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), state.getProcessorSupport());
        functionType._parametersRemove();
        functionType._functionRemove();
        if (((PurePropertyMapping) propertyMapping)._transformerCoreInstance() != null) {
            GrammarInfoStub transformerStub = (GrammarInfoStub) ((PurePropertyMapping) propertyMapping)._transformerCoreInstance();
            transformerStub._value(transformerStub._original());
            transformerStub._originalRemove();
        }
    }
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) GrammarInfoStub(org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)

Example 4 with GrammarInfoStub

use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.

the class DiagramProcessor method resolvePathViewSourceAndTarget.

private void resolvePathViewSourceAndTarget(AbstractPathView view, MapIterable<String, CoreInstance> viewsById, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) {
    GrammarInfoStub sourceViewStub = view._sourceCoreInstance() != null ? (GrammarInfoStub) repository.newAnonymousCoreInstance(view._sourceCoreInstance().getSourceInformation(), _Package.getByUserPath("meta::pure::tools::GrammarInfoStub", state.getProcessorSupport())) : null;
    GrammarInfoStub targetViewStub = view._targetCoreInstance() != null ? (GrammarInfoStub) repository.newAnonymousCoreInstance(view._targetCoreInstance().getSourceInformation(), _Package.getByUserPath("meta::pure::tools::GrammarInfoStub", state.getProcessorSupport())) : null;
    String sourceViewId = view._sourceCoreInstance() != null ? view._sourceCoreInstance().getName() : null;
    String targetViewId = view._targetCoreInstance() != null ? view._targetCoreInstance().getName() : null;
    CoreInstance sourceView = viewsById.get(sourceViewId);
    CoreInstance targetView = viewsById.get(targetViewId);
    // source view
    if (sourceView == null) {
        state.getSourceMutation().delete(view);
        return;
    }
    if (!(sourceView instanceof TypeView)) {
        throw new PureCompilationException(view.getSourceInformation(), "Object with id '" + sourceViewId + "' is not a TypeView");
    }
    if (sourceViewStub != null) {
        sourceViewStub._original(view._sourceCoreInstance());
        sourceViewStub._value(sourceView);
    }
    view._sourceCoreInstance(sourceViewStub);
    // target view
    if (targetView == null) {
        state.getSourceMutation().delete(view);
        return;
    }
    if (!(targetView instanceof TypeView)) {
        throw new PureCompilationException(view.getSourceInformation(), "Object with id '" + targetViewId + "' is not a TypeView");
    }
    if (targetViewStub != null) {
        targetViewStub._original(view._targetCoreInstance());
        targetViewStub._value(targetView);
    }
    view._targetCoreInstance(targetViewStub);
}
Also used : TypeView(org.finos.legend.pure.m3.coreinstance.meta.pure.diagram.TypeView) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) GrammarInfoStub(org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with GrammarInfoStub

use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.

the class DiagramValidator method validatePropertyView.

private void validatePropertyView(PropertyView propertyView, ProcessorSupport processorSupport) {
    AbstractProperty property = (AbstractProperty) ImportStub.withImportStubByPass(propertyView._propertyCoreInstance(), processorSupport);
    FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(property);
    // Check that source type matches property source type
    Type source = (Type) ImportStub.withImportStubByPass(((TypeView) ((GrammarInfoStub) propertyView._sourceCoreInstance())._value())._typeCoreInstance(), processorSupport);
    PropertyOwner propertySource = property._owner();
    if (propertySource != source) {
        StringBuilder message = new StringBuilder("Source type for PropertyView ");
        message.append(propertyView._id());
        message.append(" (");
        PackageableElement.writeUserPathForPackageableElement(message, source, "::");
        message.append(") does not match the owner of the property ");
        PackageableElement.writeUserPathForPackageableElement(message, propertySource, "::");
        message.append('.');
        message.append(Property.getPropertyName(property));
        message.append(" (");
        PackageableElement.writeUserPathForPackageableElement(message, propertySource, "::");
        message.append(')');
        throw new PureCompilationException(propertyView.getSourceInformation(), message.toString());
    }
    // Check that target type matches property target type
    Type target = (Type) ImportStub.withImportStubByPass(((TypeView) ((GrammarInfoStub) propertyView._targetCoreInstance())._value())._typeCoreInstance(), processorSupport);
    Type propertyTarget = (Type) ImportStub.withImportStubByPass(functionType._returnType()._rawTypeCoreInstance(), processorSupport);
    if (propertyTarget != target) {
        StringBuilder message = new StringBuilder("Target type for PropertyView ");
        message.append(propertyView._id());
        message.append(" (");
        PackageableElement.writeUserPathForPackageableElement(message, target, "::");
        message.append(") does not match the target type of the property ");
        PackageableElement.writeUserPathForPackageableElement(message, propertySource, "::");
        message.append('.');
        message.append(Property.getPropertyName(property));
        message.append(" (");
        PackageableElement.writeUserPathForPackageableElement(message, propertyTarget, "::");
        message.append(')');
        throw new PureCompilationException(propertyView.getSourceInformation(), message.toString());
    }
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) PropertyOwner(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PropertyOwner) TypeView(org.finos.legend.pure.m3.coreinstance.meta.pure.diagram.TypeView) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)6 TypeView (org.finos.legend.pure.m3.coreinstance.meta.pure.diagram.TypeView)5 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)5 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)5 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)4 GrammarInfoStub (org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub)4 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)3 PurePropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping)2 RichIterable (org.eclipse.collections.api.RichIterable)1 MapIterable (org.eclipse.collections.api.map.MapIterable)1 GeneralizationView (org.finos.legend.pure.m3.coreinstance.meta.pure.diagram.GeneralizationView)1 EnumValueMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping)1 EnumerationMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping)1 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)1 PropertyMappingValueSpecificationContext (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingValueSpecificationContext)1 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)1 PropertyOwner (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PropertyOwner)1 ImportStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)1 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)1 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)1