Search in sources :

Example 1 with MatcherState

use of org.finos.legend.pure.m3.tools.matcher.MatcherState 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);
}
Also used : RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)

Example 2 with MatcherState

use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.

the class InstanceValueUnbind method run.

@Override
public void run(InstanceValue instanceValue, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    for (CoreInstance value : instanceValue._valuesCoreInstance()) {
        if (!(value instanceof Property)) {
            ((UnbindState) state).freeProcessedAndValidated(value);
        }
        Shared.cleanUpReferenceUsage(value, instanceValue, processorSupport);
        // TODO replace call to Instance.instanceOf once we resolve issue with Path not being available in this module - circular dependency
        if (value instanceof LambdaFunction || value instanceof SimpleFunctionExpression || Instance.instanceOf(value, M3Paths.Path, processorSupport) || value instanceof RootRouteNode) {
            matcher.fullMatch(value, state);
        } else if (Instance.instanceOf(value, M3Paths.RootGraphFetchTree, processorSupport)) {
            matcher.fullMatch(value, state);
        } else if (value instanceof KeyExpression) {
            ((UnbindState) state).freeProcessedAndValidated(modelRepository.newBooleanCoreInstance(((KeyExpression) value)._add()));
            ((UnbindState) state).freeProcessedAndValidated(((KeyExpression) value)._key());
            matcher.fullMatch(((KeyExpression) value)._expression(), state);
        } else {
            Shared.cleanImportStub(value, processorSupport);
        }
        if (value instanceof ValueSpecification) {
            matcher.fullMatch(value, state);
            ((ValueSpecification) value)._usageContextRemove();
        }
    }
}
Also used : ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) KeyExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.lang.KeyExpression) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)

Example 3 with MatcherState

use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.

the class SimpleFunctionExpressionUnbind method cleanAutoMapPropertyIfNecessary.

private static void cleanAutoMapPropertyIfNecessary(FunctionExpression functionExpression, MatcherState state, Matcher matcher) {
    ValueSpecification possiblePropertySfe = (ValueSpecification) Automap.getAutoMapExpressionSequence(functionExpression);
    if (possiblePropertySfe != null) {
        functionExpression._functionNameRemove();
        ListIterable<? extends ValueSpecification> params = functionExpression._parametersValues().toList();
        ValueSpecification firstParam = params.get(0);
        ValueSpecification secondParam = params.get(1);
        matcher.fullMatch(secondParam, state);
        RichIterable<? extends ValueSpecification> possiblePropertySfeParams = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._parametersValues() : // params may have changed after unbinding for the Lambda
        Lists.fixedSize.empty();
        ((UnbindState) state).freeProcessedAndValidated(secondParam);
        GenericType secondParamGenericType = secondParam._genericType();
        if (secondParamGenericType != null) {
            ((UnbindState) state).freeValidated(secondParamGenericType);
        }
        functionExpression._parametersValuesRemove();
        MutableList<ValueSpecification> allVars = Lists.mutable.with(firstParam);
        // add back qualified properties params
        allVars.addAllIterable(possiblePropertySfeParams.toList().subList(1, possiblePropertySfeParams.size()));
        functionExpression._parametersValues(allVars);
        InstanceValue propertyName = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._propertyName() : null;
        if (propertyName == null) {
            InstanceValue qualifiedPropertyName = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._qualifiedPropertyName() : null;
            functionExpression._qualifiedPropertyName(qualifiedPropertyName);
        } else {
            functionExpression._propertyName(propertyName);
        }
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)

Example 4 with MatcherState

use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.

the class SimpleFunctionExpressionUnbind method run.

@Override
public void run(SimpleFunctionExpression functionExpression, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    Function<?> function = (Function<?>) ImportStub.withImportStubByPass(functionExpression._funcCoreInstance(), processorSupport);
    if (function != null) {
        function._applicationsRemove(functionExpression);
        if (function._applications().isEmpty()) {
            function._applicationsRemove();
        }
    }
    cleanAutoMapPropertyIfNecessary(functionExpression, state, matcher);
    MilestoningDatesPropagationFunctions.undoAutoGenMilestonedQualifier(functionExpression, modelRepository, processorSupport);
    functionExpression._funcRemove();
    functionExpression._resolvedTypeParametersRemove();
    functionExpression._resolvedMultiplicityParametersRemove();
    functionExpression._parametersValues().forEach(pv -> matcher.fullMatch(pv, state));
}
Also used : Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport)

Example 5 with MatcherState

use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.

the class TypeUnbind method run.

@Override
public void run(Type type, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    for (Generalization generalization : type._generalizations()) {
        GenericType general = generalization._general();
        Type generalRawType = null;
        try {
            generalRawType = (Type) ImportStub.withImportStubByPass(general._rawTypeCoreInstance(), processorSupport);
        } catch (PureCompilationException ex) {
        // Ignore - if we can't resolve this type was probably already unbound
        }
        if (generalRawType != null) {
            ListIterable<? extends CoreInstance> specializationsToRemove = generalRawType.getValueInValueForMetaPropertyToManyByIndex(M3Properties.specializations, IndexSpecifications.getPropertyValueIndexSpec(M3Properties.specific), type);
            for (CoreInstance specialization : specializationsToRemove.toList()) {
                generalRawType._specializationsRemove((Generalization) specialization);
            }
            if (generalRawType.getValueForMetaPropertyToMany(M3Properties.specializations).isEmpty()) {
                generalRawType._specializationsRemove();
            }
        }
        Shared.cleanUpGenericType(general, (UnbindState) state, processorSupport);
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) 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) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)53 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)21 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)19 ValidatorState (org.finos.legend.pure.m3.compiler.validation.ValidatorState)16 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)12 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)11 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)9 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)8 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)5 ImportStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)5 RootRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)5 RichIterable (org.eclipse.collections.api.RichIterable)4 ProcessorState (org.finos.legend.pure.m3.compiler.postprocessing.ProcessorState)4 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)4 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)4 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)4 PropertyOwnerStrategy (org.finos.legend.pure.m3.compiler.PropertyOwnerStrategy)3 GraphFetchTree (org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree)3 PropertyGraphFetchTree (org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree)3 RootGraphFetchTree (org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.RootGraphFetchTree)3