Search in sources :

Example 1 with ExistingPropertyRouteNode

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

Example 2 with ExistingPropertyRouteNode

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

the class RootRouteNodePostProcessor method populateReferenceUsages.

@Override
public void populateReferenceUsages(RootRouteNode treePathRoot, ModelRepository repository, ProcessorSupport processorSupport) {
    MutableSet<RouteNode> visited = Sets.mutable.empty();
    MutableStack<RouteNode> stack = Stacks.mutable.with(treePathRoot);
    while (stack.notEmpty()) {
        RouteNode node = stack.pop();
        if (visited.add(node)) {
            GenericTypeTraceability.addTraceForTreePath(node, repository, processorSupport);
            addReferenceUsagesForToManyProperty(node, node._resolvedPropertiesCoreInstance(), M3Properties.resolvedProperties, repository, processorSupport);
            if (node instanceof ExistingPropertyRouteNode) {
                GenericTypeTraceability.addTraceForTreePath(node, repository, processorSupport);
                RouteNodePropertyStub propertyStub = ((ExistingPropertyRouteNode) node)._property();
                // TODO Fix this: the reference usage should be to the RouteNodePropertyStub, not to the ExistingPropertyRouteNode
                // addReferenceUsageForToOneProperty(propertyStub, M3Properties.property, repository, context, processorSupport);
                AbstractProperty<?> property = (AbstractProperty<?>) ImportStub.withImportStubByPass(propertyStub._propertyCoreInstance().getFirst(), processorSupport);
                addReferenceUsage(node, property, M3Properties.property, 0, repository, processorSupport);
            } else if (node instanceof NewPropertyRouteNode) {
                NewPropertyRouteNodeFunctionDefinition<?, ?> functionDefinition = ((NewPropertyRouteNode) node)._functionDefinition();
                GenericTypeTraceability.addTraceForNewPropertyRouteNodeFunctionDefinition(functionDefinition, repository, processorSupport);
            }
            for (PropertyRouteNode child : node._children()) {
                if (!visited.contains(child)) {
                    stack.push(child);
                }
            }
        }
    }
}
Also used : ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode) RouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNode) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) NewPropertyRouteNodeFunctionDefinition(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeFunctionDefinition) 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) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)

Example 3 with ExistingPropertyRouteNode

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

the class RootRouteNodeUnbind method unbindExistingPropertyNode.

private void unbindExistingPropertyNode(ExistingPropertyRouteNode treeNode, UnbindState state, ProcessorSupport processorSupport) {
    GenericType type = treeNode._type();
    if (type != null) {
        RouteNodePropertyStub existingPropertyRouteNodeStub = treeNode._property();
        PropertyStub propertyStub = (PropertyStub) existingPropertyRouteNodeStub._propertyCoreInstance().getFirst();
        Shared.cleanUpReferenceUsage(propertyStub._resolvedPropertyCoreInstance(), treeNode, processorSupport);
        this.cleanRouteNodePropertyStub(existingPropertyRouteNodeStub, state, processorSupport);
        Shared.cleanUpGenericType(treeNode._type(), state, processorSupport);
        treeNode._typeRemove();
        treeNode._rootRemove();
    }
}
Also used : PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)

Example 4 with ExistingPropertyRouteNode

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

the class RootRouteNodeUnbind method unbindTreePathNode.

public void unbindTreePathNode(RouteNode treeNode, UnbindState state, Matcher matcher, ProcessorSupport processorSupport) {
    if (treeNode instanceof ExistingPropertyRouteNode) {
        unbindExistingPropertyNode((ExistingPropertyRouteNode) treeNode, state, processorSupport);
    }
    if (treeNode instanceof NewPropertyRouteNode) {
        unbindNewPropertyNode((NewPropertyRouteNode) treeNode, state, matcher, processorSupport);
    }
    unbindResolvedProperties(treeNode, processorSupport);
    for (RouteNodePropertyStub routeNodePropertyStub : treeNode._included()) {
        cleanRouteNodePropertyStub(routeNodePropertyStub, state, processorSupport);
        matcher.fullMatch(routeNodePropertyStub, state);
    }
    for (RouteNodePropertyStub routeNodePropertyStub : treeNode._excluded()) {
        cleanRouteNodePropertyStub(routeNodePropertyStub, state, processorSupport);
    }
    for (PropertyRouteNode childNode : treeNode._children()) {
        unbindTreePathNode(childNode, state, matcher, processorSupport);
        matcher.fullMatch(childNode, state);
    }
}
Also used : ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) 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) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)

Example 5 with ExistingPropertyRouteNode

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

the class RootRouteNodePostProcessor method resolveTreeNode.

private void resolveTreeNode(RootRouteNode root, RouteNode treePathNode, Type type, Matcher matcher, ProcessorState state, ModelRepository repository, Context context, MutableMultimap<String, RouteNode> resolvedTreeNodes) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    String nodeName = treePathNode._name();
    if (resolvedTreeNodes.containsKey(nodeName)) {
        // node has already been resolved
        // throw exception if types don't match
        Type alreadyProcessedNodeType = (Type) ImportStub.withImportStubByPass(resolvedTreeNodes.get(nodeName).getFirst()._type()._rawTypeCoreInstance(), processorSupport);
        if (alreadyProcessedNodeType != type) {
            throw new PureCompilationException(treePathNode.getSourceInformation(), String.format("Invalid Treepath! 2 nodes with same name %s but with different types %s %s", nodeName, type.getName(), alreadyProcessedNodeType.getName()));
        }
        resolvedTreeNodes.put(nodeName, treePathNode);
        return;
    }
    resolvedTreeNodes.put(nodeName, treePathNode);
    this.resolveSimpleProperties(treePathNode, type, matcher, state, processorSupport);
    for (PropertyRouteNode childNode : treePathNode._children()) {
        if (childNode._root() == null) {
            childNode._root(root);
        }
        if (childNode instanceof ExistingPropertyRouteNode) {
            resolveExistingPropertyNode(root, type, matcher, state, repository, context, resolvedTreeNodes, processorSupport, (ExistingPropertyRouteNode) childNode);
        } else {
            // NewProperty, not part of the original model
            resolveNewPropertyNode(root, type, matcher, state, repository, context, resolvedTreeNodes, processorSupport, (NewPropertyRouteNode) childNode);
        }
    }
}
Also used : PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) 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) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

ExistingPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode)5 RouteNodePropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)5 NewPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode)4 PropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode)4 DataType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType)3 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)3 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)2 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)2 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)2 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)2 PropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub)1 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)1 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)1 NewPropertyRouteNodeFunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeFunctionDefinition)1 RootRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)1 RouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNode)1 FunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression)1 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1