use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode 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()));
}
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode 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);
}
}
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode 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);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode in project legend-pure by finos.
the class PropertyRouteNodeUnloaderWalk method run.
@Override
public void run(PropertyRouteNode propertyRouteNode, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
RootRouteNode rootNode = propertyRouteNode._root();
matcher.fullMatch(rootNode, state);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode 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);
}
}
}
Aggregations