use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.
the class InstanceValueProcessor method process.
@Override
public void process(InstanceValue instance, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
TypeInferenceContext typeInferenceContext = state.getTypeInferenceContext();
ListIterable<? extends CoreInstance> values = ImportStub.withImportStubByPasses(ListHelper.wrapListIterable(instance._valuesCoreInstance()), processorSupport);
boolean isCollection = values.size() > 1;
values.forEachWithIndex((child, i) -> {
if (isCollection) {
typeInferenceContext.addStateForCollectionElement();
}
if (child instanceof ValueSpecification) {
InstanceValueSpecificationContext usageContext = (InstanceValueSpecificationContext) processorSupport.newAnonymousCoreInstance(null, M3Paths.InstanceValueSpecificationContext);
usageContext._offset(i);
usageContext._instanceValue(instance);
((ValueSpecification) child)._usageContext(usageContext);
} else if (child instanceof RootRouteNode) {
((RootRouteNode) child)._owner(instance);
}
if (child instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) {
ImportStub.processImportStub((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) child, repository, processorSupport);
} else // TODO Is this check necessary? The post-processor keeps track of what has been processed.
if (!(child instanceof Class)) {
PostProcessor.processElement(matcher, child, state, processorSupport);
}
});
if (isCollection) {
TypeInference.potentiallyUpdateParentTypeParamForInstanceValueWithManyElements(instance, typeInferenceContext, state, processorSupport);
}
updateInstanceValue(instance, processorSupport);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.
the class ClassProjectionUnloaderWalk method run.
@Override
public void run(ClassProjection classProjection, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
RootRouteNode treeRoot = classProjection._projectionSpecification();
matcher.fullMatch(treeRoot, state);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.
the class InstanceValueUnbind method run.
@Override
public void run(InstanceValue instanceValue, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (CoreInstance value : instanceValue._valuesCoreInstance()) {
if (!(value instanceof Property)) {
((UnbindState) state).freeProcessedAndValidated(value);
}
Shared.cleanUpReferenceUsage(value, instanceValue, processorSupport);
// TODO replace call to Instance.instanceOf once we resolve issue with Path not being available in this module - circular dependency
if (value instanceof LambdaFunction || value instanceof SimpleFunctionExpression || Instance.instanceOf(value, M3Paths.Path, processorSupport) || value instanceof RootRouteNode) {
matcher.fullMatch(value, state);
} else if (Instance.instanceOf(value, M3Paths.RootGraphFetchTree, processorSupport)) {
matcher.fullMatch(value, state);
} else if (value instanceof KeyExpression) {
((UnbindState) state).freeProcessedAndValidated(modelRepository.newBooleanCoreInstance(((KeyExpression) value)._add()));
((UnbindState) state).freeProcessedAndValidated(((KeyExpression) value)._key());
matcher.fullMatch(((KeyExpression) value)._expression(), state);
} else {
Shared.cleanImportStub(value, processorSupport);
}
if (value instanceof ValueSpecification) {
matcher.fullMatch(value, state);
((ValueSpecification) value)._usageContextRemove();
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode in project legend-pure by finos.
the class ClassProjectionProcessor method process.
@Override
public void process(ClassProjection classProjection, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
RootRouteNode projectionSpec = classProjection._projectionSpecification();
Type projectedRawType = projectionSpec._type() == null ? null : (Type) ImportStub.withImportStubByPass(projectionSpec._type()._rawTypeCoreInstance(), processorSupport);
PostProcessor.processElement(matcher, projectionSpec, state, processorSupport);
processDerivedProperties(classProjection, repository, context, processorSupport);
processSimpleProperties(classProjection, state, repository, context, processorSupport);
ProjectionUtil.copyAnnotations(projectedRawType, classProjection, true, processorSupport);
ProjectionUtil.copyAnnotations(projectionSpec, classProjection, true, processorSupport);
context.update(classProjection);
processClass(classProjection, state, matcher, repository, processorSupport);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode 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()));
}
}
}
}
Aggregations