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