Search in sources :

Example 1 with RouteNode

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

the class AntlrContextToM3CoreInstance method propertyRef.

private RouteNodePropertyStub propertyRef(PropertyRefContext ctx, ImportGroup importId, String space, RouteNode routeNode) {
    RouteNodePropertyStub routeNodePropertyStub = RouteNodePropertyStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.identifier().getStart(), ctx.getStop()), routeNode);
    String propertyName = ctx.identifier().getText();
    PropertyStub propertyStub = PropertyStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.identifier().getStart()), null, propertyName);
    routeNodePropertyStub._propertyCoreInstance(Lists.mutable.<CoreInstance>with(propertyStub));
    if (ctx.treePathPropertyParameterType() != null) {
        MutableList<InstanceValue> params = Lists.mutable.of();
        for (TreePathPropertyParameterTypeContext fCtx : ctx.treePathPropertyParameterType()) {
            GenericType type = this.type(fCtx.type(), Lists.mutable.empty(), spacePlusTabs(space, 3), importId, true);
            Multiplicity multiplicity = this.buildMultiplicity(fCtx.multiplicity().multiplicityArgument());
            InstanceValue iv = InstanceValueInstance.createPersistent(this.repository, type, multiplicity);
            params.add(iv);
        }
        routeNodePropertyStub._parameters(params);
    }
    return routeNodePropertyStub;
}
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) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) TreePathPropertyParameterTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathPropertyParameterTypeContext)

Example 2 with RouteNode

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

the class RootRouteNodePostProcessor method secondPass.

private void secondPass(final RootRouteNode root, final ListMultimap<String, RouteNode> resolvedTreeNodes, final Matcher matcher, final ProcessorState state, final ProcessorSupport processorSupport) throws PureCompilationException {
    resolvedTreeNodes.forEachKey(s -> {
        ListIterable<RouteNode> nodes = resolvedTreeNodes.get(s);
        RouteNode firstNode = nodes.get(0);
        PostProcessor.processElement(matcher, firstNode, state, processorSupport);
        if (nodes.size() > 1) {
            for (int i = 1; i < nodes.size(); i++) {
                RouteNode currentNode = nodes.get(i);
                copyNode(root, firstNode, currentNode);
                PostProcessor.processElement(matcher, currentNode, state, processorSupport);
            }
        }
    });
}
Also used : 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)

Example 3 with RouteNode

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

the class RootRouteNodePostProcessor method resolveSimpleProperties.

private void resolveSimpleProperties(RouteNode treePathNode, Type _class, Matcher matcher, ProcessorState state, ProcessorSupport processorSupport) {
    RichIterable<? extends RouteNodePropertyStub> includedProperties = treePathNode._included();
    RichIterable<? extends RouteNodePropertyStub> excludedProperties = treePathNode._excluded();
    MutableList<CoreInstance> resolvedProperties = FastList.newList();
    if ("true".equals(treePathNode._includeAll())) {
        resolvedProperties.addAllIterable(getPrimitiveOrOfGivenTypeProperties(_class, processorSupport));
        resolvedProperties.addAllIterable(getPrimitiveOrOfGivenTypeQualifiedProperties(_class, processorSupport));
    } else if (includedProperties.notEmpty()) {
        for (RouteNodePropertyStub includedPropertyStub : includedProperties) {
            CoreInstance property = this.resolvePropertyStub(_class, includedPropertyStub, matcher, state, processorSupport);
            resolvedProperties.add(property);
        }
    } else if (excludedProperties.notEmpty()) {
        // TODO cannot handle simple and qualified properties with same name
        MapIterable<String, CoreInstance> simplePropertiesByName = processorSupport.class_getSimplePropertiesByName(_class);
        MapIterable<String, CoreInstance> qualifiedPropertiesByName = _Class.getQualifiedPropertiesByName(_class, processorSupport);
        resolvedProperties.addAllIterable(getPrimitiveOrOfGivenTypeProperties(_class, processorSupport));
        resolvedProperties.addAllIterable(getPrimitiveOrOfGivenTypeQualifiedProperties(_class, processorSupport));
        for (RouteNodePropertyStub excludedPropertyStub : excludedProperties) {
            AbstractProperty<?> property = this.resolvePropertyStub(_class, excludedPropertyStub, matcher, state, processorSupport);
            String name = Property.getPropertyId(property, processorSupport);
            if (simplePropertiesByName.containsKey(name)) {
                resolvedProperties.remove(simplePropertiesByName.get(name));
            }
            if (qualifiedPropertiesByName.containsKey(name)) {
                resolvedProperties.remove(qualifiedPropertiesByName.get(name));
            }
        }
    }
    treePathNode._resolvedPropertiesCoreInstance(FastList.<CoreInstance>newList(treePathNode._resolvedPropertiesCoreInstance().size() + resolvedProperties.size()).withAll(treePathNode._resolvedPropertiesCoreInstance()).withAll(resolvedProperties));
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)

Example 4 with RouteNode

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

the class RootRouteNodePostProcessor method resolveNewPropertyNode.

private void resolveNewPropertyNode(RootRouteNode root, Type type, Matcher matcher, ProcessorState state, ModelRepository repository, Context context, MutableMultimap<String, RouteNode> resolvedTreeNodes, ProcessorSupport processorSupport, NewPropertyRouteNode childNode) {
    RichIterable<? extends ValueSpecification> valueSpecifications = childNode._specifications();
    if (valueSpecifications.isEmpty()) {
        throw new PureCompilationException(childNode.getSourceInformation(), "Invalid new property defined. New properties must define a valid Value Specification");
    }
    NewPropertyRouteNodeFunctionDefinition<?, ?> functionDefinition = childNode._functionDefinition();
    if (functionDefinition._owner() == null) {
        functionDefinition._owner(childNode);
    }
    // TODO process the full function definition instead of just the expressionSequence
    processDerivedPropertyExpressions(childNode, type, functionDefinition._expressionSequence(), matcher, state, processorSupport);
    // PostProcessor.processElement(matcher, functionDefinition, state, context, processorSupport);
    // Set classifierGenericType for functionDefinition
    GenericType sourceType = (GenericType) org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(type, functionDefinition.getSourceInformation(), processorSupport);
    ValueSpecification lastExpression = functionDefinition._expressionSequence().getLast();
    GenericType returnType = (GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(lastExpression._genericType(), functionDefinition.getSourceInformation(), processorSupport);
    Multiplicity returnMultiplicity = (Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.copyMultiplicity(lastExpression._multiplicity(), functionDefinition.getSourceInformation(), processorSupport);
    GenericType classifierGenericType = (GenericType) org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(functionDefinition.getClassifier(), functionDefinition.getSourceInformation(), processorSupport);
    classifierGenericType._typeArguments(Lists.immutable.with(sourceType, returnType));
    classifierGenericType._multiplicityArguments(Lists.immutable.with(returnMultiplicity));
    functionDefinition._classifierGenericType(classifierGenericType);
    processDerivedPropertyExpressions(childNode, type, valueSpecifications, matcher, state, processorSupport);
    GenericType propertyGenericType = valueSpecifications.getLast()._genericType();
    Type _class = (Type) ImportStub.withImportStubByPass(propertyGenericType._rawTypeCoreInstance(), processorSupport);
    if (childNode._type() == null) {
        GenericType genericTypeCopy = (GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(propertyGenericType, childNode.getSourceInformation(), processorSupport);
        childNode._type(genericTypeCopy);
    }
    this.resolveTreeNode(root, childNode, _class, matcher, state, repository, context, resolvedTreeNodes);
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) 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) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with RouteNode

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

Aggregations

ExistingPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode)6 RouteNodePropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)6 NewPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode)5 PropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode)5 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)5 DataType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType)4 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)4 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)4 RootRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)3 RouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNode)3 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)2 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)2 PropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub)1 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)1 NewPropertyRouteNodeFunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeFunctionDefinition)1 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)1 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)1 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)1 TreePathPropertyParameterTypeContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathPropertyParameterTypeContext)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1