Search in sources :

Example 1 with NewPropertyRouteNode

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

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

the class AntlrContextToM3CoreInstance method treePathDerivedComplexProperty.

private NewPropertyRouteNode treePathDerivedComplexProperty(DerivedPropertyContext ctx, LambdaContext lambdaContext, ImportGroup importId, String space) {
    String propertyName = ctx.alias() != null ? ctx.alias().identifier().getText() : ctx.propertyRef().identifier().getText();
    boolean includeAll = ctx.treePathClassBody() != null && ctx.treePathClassBody().simplePropertyFilter() != null && ctx.treePathClassBody().simplePropertyFilter().STAR() != null;
    NewPropertyRouteNode dpRouteNode = NewPropertyRouteNodeInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.propertyRef().getStart(), ctx.getStop()), null, String.valueOf(includeAll), propertyName, ctx.propertyRef().identifier().getText(), null, null);
    ListIterable<ValueSpecification> codeSpecifications = this.codeBlock(ctx.codeBlock(), Lists.mutable.empty(), importId, lambdaContext, true, space);
    dpRouteNode._specifications(codeSpecifications);
    NewPropertyRouteNodeFunctionDefinition<?, ?> functionDefinition = NewPropertyRouteNodeFunctionDefinitionInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.codeBlock().getStart()), dpRouteNode);
    functionDefinition._expressionSequence(codeSpecifications);
    dpRouteNode._functionDefinition(functionDefinition);
    if (ctx.treePathClassBody() != null) {
        this.treepathBody(ctx.treePathClassBody(), dpRouteNode, importId, lambdaContext, space);
    }
    if (ctx.taggedValues() != null) {
        dpRouteNode._taggedValues(this.taggedValues(ctx.taggedValues(), importId));
    }
    if (ctx.stereotypes() != null) {
        dpRouteNode._stereotypesCoreInstance(this.stereotypes(ctx.stereotypes(), importId));
    }
    return dpRouteNode;
}
Also used : ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode)

Example 3 with NewPropertyRouteNode

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

the class NewPropertyRouteNodeFunctionDefinitionUnloaderWalk method run.

@Override
public void run(NewPropertyRouteNodeFunctionDefinition functionDefinition, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    NewPropertyRouteNode owner = functionDefinition._owner();
    matcher.fullMatch(owner, state);
}
Also used : NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode)

Example 4 with NewPropertyRouteNode

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

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

NewPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode)7 ExistingPropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode)5 PropertyRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode)5 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)4 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)3 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 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)3 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)2 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)2 RootRouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode)2 RouteNodePropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub)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 FunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression)2 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)2 ListIterable (org.eclipse.collections.api.list.ListIterable)1 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)1 NewPropertyRouteNodeFunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeFunctionDefinition)1 RouteNode (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNode)1