Search in sources :

Example 1 with UnbindState

use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState 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 2 with UnbindState

use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.

the class Shared method cleanUpFunctionType.

private static void cleanUpFunctionType(FunctionType functionType, UnbindState state, ProcessorSupport processorSupport) {
    GenericType returnType = functionType._returnType();
    if (returnType != null) {
        returnType._referenceUsagesRemove();
        cleanUpGenericType(returnType, state, processorSupport);
    }
    for (VariableExpression variableExpression : functionType._parameters()) {
        GenericType varGenericType = variableExpression._genericType();
        if (varGenericType != null) {
            cleanUpGenericType(varGenericType, state, processorSupport);
            if (varGenericType instanceof InferredGenericType) {
                variableExpression._genericTypeRemove();
                variableExpression._multiplicityRemove();
            }
        }
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) InferredGenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.InferredGenericType) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) InferredGenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.InferredGenericType)

Example 3 with UnbindState

use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.

the class Shared method cleanUpGenericType.

public static void cleanUpGenericType(GenericType genericType, UnbindState state, ProcessorSupport processorSupport) {
    state.freeValidated(genericType);
    genericType._referenceUsagesRemove();
    CoreInstance rawType = genericType._rawTypeCoreInstance();
    if (rawType != null) {
        cleanUpReferenceUsage(rawType, genericType, processorSupport);
        if (rawType instanceof FunctionType) {
            cleanUpFunctionType((FunctionType) rawType, state, processorSupport);
        } else {
            cleanImportStub(rawType, processorSupport);
        }
    }
    for (GenericType typeArgument : genericType._typeArguments()) {
        cleanUpGenericType(typeArgument, state, processorSupport);
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) InferredGenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.InferredGenericType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 4 with UnbindState

use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState 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 5 with UnbindState

use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState 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

GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)11 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)7 UnbindState (org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState)6 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)6 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)5 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)5 PropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub)3 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)3 RouteNodePropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)3 FunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression)3 RichIterable (org.eclipse.collections.api.RichIterable)2 Function (org.eclipse.collections.api.block.function.Function)2 FunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition)2 InferredGenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.InferredGenericType)2 SimpleFunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression)2 Parser (org.finos.legend.pure.m3.serialization.grammar.Parser)2 InlineDSL (org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSL)2 Matcher (org.finos.legend.pure.m3.tools.matcher.Matcher)2 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)1