Search in sources :

Example 1 with RootRouteNode

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.

the class InstanceValueProcessor method process.

@Override
public void process(InstanceValue instance, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    TypeInferenceContext typeInferenceContext = state.getTypeInferenceContext();
    ListIterable<? extends CoreInstance> values = ImportStub.withImportStubByPasses(ListHelper.wrapListIterable(instance._valuesCoreInstance()), processorSupport);
    boolean isCollection = values.size() > 1;
    values.forEachWithIndex((child, i) -> {
        if (isCollection) {
            typeInferenceContext.addStateForCollectionElement();
        }
        if (child instanceof ValueSpecification) {
            InstanceValueSpecificationContext usageContext = (InstanceValueSpecificationContext) processorSupport.newAnonymousCoreInstance(null, M3Paths.InstanceValueSpecificationContext);
            usageContext._offset(i);
            usageContext._instanceValue(instance);
            ((ValueSpecification) child)._usageContext(usageContext);
        } else if (child instanceof RootRouteNode) {
            ((RootRouteNode) child)._owner(instance);
        }
        if (child instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) {
            ImportStub.processImportStub((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) child, repository, processorSupport);
        } else // TODO Is this check necessary? The post-processor keeps track of what has been processed.
        if (!(child instanceof Class)) {
            PostProcessor.processElement(matcher, child, state, processorSupport);
        }
    });
    if (isCollection) {
        TypeInference.potentiallyUpdateParentTypeParamForInstanceValueWithManyElements(instance, typeInferenceContext, state, processorSupport);
    }
    updateInstanceValue(instance, processorSupport);
}
Also used : ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) InstanceValueSpecificationContext(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValueSpecificationContext) ImportStub(org.finos.legend.pure.m3.navigation.importstub.ImportStub) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) TypeInferenceContext(org.finos.legend.pure.m3.compiler.postprocessing.inference.TypeInferenceContext)

Example 2 with RootRouteNode

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode 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 3 with RootRouteNode

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode 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 4 with RootRouteNode

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.

the class ClassProjectionProcessor method process.

@Override
public void process(ClassProjection classProjection, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    RootRouteNode projectionSpec = classProjection._projectionSpecification();
    Type projectedRawType = projectionSpec._type() == null ? null : (Type) ImportStub.withImportStubByPass(projectionSpec._type()._rawTypeCoreInstance(), processorSupport);
    PostProcessor.processElement(matcher, projectionSpec, state, processorSupport);
    processDerivedProperties(classProjection, repository, context, processorSupport);
    processSimpleProperties(classProjection, state, repository, context, processorSupport);
    ProjectionUtil.copyAnnotations(projectedRawType, classProjection, true, processorSupport);
    ProjectionUtil.copyAnnotations(projectionSpec, classProjection, true, processorSupport);
    context.update(classProjection);
    processClass(classProjection, state, matcher, repository, processorSupport);
}
Also used : DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)

Example 5 with RootRouteNode

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.

the class ClassProjectionProcessor method validateDerivedProperties.

private static void validateDerivedProperties(RootRouteNode projectionSpec, ProcessorSupport processorSupport) {
    // we can only support derived properties which flatten relations to a primitive type. Qualified Properties are not supported.
    for (PropertyRouteNode derivedProperty : projectionSpec._children()) {
        if (derivedProperty instanceof ExistingPropertyRouteNode) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Found complex property '%s', only simple properties are allowed in a class projection.", derivedProperty._propertyName()));
        }
        CoreInstance derivedPropertyType = derivedProperty._type() == null ? null : ImportStub.withImportStubByPass(derivedProperty._type()._rawTypeCoreInstance(), processorSupport);
        if (!(derivedPropertyType instanceof DataType)) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Derived property '%s' should be of PrimitiveType.", derivedProperty._propertyName()));
        }
        ListIterable<? extends ValueSpecification> valueSpecifications = derivedProperty instanceof NewPropertyRouteNode ? ((NewPropertyRouteNode) derivedProperty)._specifications().toList() : Lists.immutable.<ValueSpecification>empty();
        if (valueSpecifications.size() != 1) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), "Invalid projection specification: derived property '" + derivedProperty._propertyName() + "' should have exactly 1 value specification, found " + valueSpecifications.size());
        }
        if (valueSpecifications.getFirst() instanceof FunctionExpression) {
            CoreInstance func = ImportStub.withImportStubByPass(((FunctionExpression) valueSpecifications.getFirst())._funcCoreInstance(), processorSupport);
            if (func != null && !(func instanceof Property) && Automap.getAutoMapExpressionSequence(valueSpecifications.getFirst()) == null) {
                throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Derived property '%s' should be a simple property.", derivedProperty._propertyName()));
            }
        }
    }
}
Also used : NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) 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) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

RootRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)14 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)7 ExistingPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode)6 NewPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode)6 PropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode)6 DataType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType)6 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)6 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)5 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)5 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)5 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)4 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)4 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)4 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)4 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)3 RouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNode)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)2 RichIterable (org.eclipse.collections.api.RichIterable)1 ListIterable (org.eclipse.collections.api.list.ListIterable)1