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;
}
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);
}
}
});
}
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));
}
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);
}
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);
}
}
}
}
}
Aggregations