use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree in project legend-pure by finos.
the class RootGraphFetchTreeValidator method validatePropertyGraphFetchTrees.
private void validatePropertyGraphFetchTrees(PropertyGraphFetchTree propertyGraphFetchTree, ProcessorSupport processorSupport, Function<CoreInstance, CoreInstance> extractGenericTypeFunction) {
AbstractProperty property = (AbstractProperty) ImportStub.withImportStubByPass(propertyGraphFetchTree._propertyCoreInstance(), processorSupport);
RichIterable<? extends VariableExpression> valueSpecifications = ((FunctionType) processorSupport.function_getFunctionType(property))._parameters();
ListIterable<? extends VariableExpression> parameterSpecifications = valueSpecifications.toList().subList(1, valueSpecifications.size());
ListIterable<? extends ValueSpecification> parameters = propertyGraphFetchTree._parameters().toList();
if (parameterSpecifications.size() != parameters.size()) {
throw new PureCompilationException(propertyGraphFetchTree.getSourceInformation(), "Error finding match for property '" + property._name() + "'. Incorrect number of parameters, function expects " + parameterSpecifications.size() + " parameters");
}
int i = 0;
for (VariableExpression valueSpecification : parameterSpecifications) {
ValueSpecification parameter = parameters.get(i);
if (parameter instanceof InstanceValue) {
ListIterable<? extends CoreInstance> values = ImportStub.withImportStubByPasses(((InstanceValue) parameter)._valuesCoreInstance().toList(), processorSupport);
GenericType genericTypeSpecified = valueSpecification._genericType();
CoreInstance type = values.size() == 1 ? extractGenericTypeFunction.valueOf(values.getFirst()) : org.finos.legend.pure.m3.navigation.generictype.GenericType.findBestCommonGenericType(values.collect(extractGenericTypeFunction), true, false, processorSupport);
if (!org.finos.legend.pure.m3.navigation.generictype.GenericType.subTypeOf(type, genericTypeSpecified, processorSupport)) {
throw new PureCompilationException(propertyGraphFetchTree.getSourceInformation(), "Parameter type mismatch for property '" + property._functionName() + "'. Expected:" + org.finos.legend.pure.m3.navigation.generictype.GenericType.print(genericTypeSpecified, processorSupport) + ", Found:" + org.finos.legend.pure.m3.navigation.generictype.GenericType.print(type, processorSupport));
}
}
i++;
}
FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(property);
CoreInstance returnType = ImportStub.withImportStubByPass(functionType._returnType()._rawTypeCoreInstance(), processorSupport);
CoreInstance subTypeClass = ImportStub.withImportStubByPass(propertyGraphFetchTree._subTypeCoreInstance(), processorSupport);
if (subTypeClass != null) {
if (!Type.subTypeOf(subTypeClass, returnType, processorSupport)) {
throw new PureCompilationException(propertyGraphFetchTree._subTypeCoreInstance().getSourceInformation(), "The type " + subTypeClass.getName() + " is not compatible with " + returnType.getName());
}
}
for (GraphFetchTree child : propertyGraphFetchTree._subTrees()) {
this.validatePropertyGraphFetchTrees((PropertyGraphFetchTree) child, processorSupport, extractGenericTypeFunction);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree in project legend-pure by finos.
the class RootGraphFetchTreeUnbind method unbindPropertyGraphFetchTree.
private void unbindPropertyGraphFetchTree(PropertyGraphFetchTree propertyGraphFetchTree, RootGraphFetchTree mainTree, MatcherState state, Matcher matcher) {
ProcessorSupport processorSupport = state.getProcessorSupport();
PropertyStub property = (PropertyStub) propertyGraphFetchTree._propertyCoreInstance();
CoreInstance resolved = property._resolvedPropertyCoreInstance();
if (resolved != null) {
ReferenceUsage.removeReferenceUsagesForUser(resolved, mainTree, state.getProcessorSupport());
}
Shared.cleanPropertyStub(property, processorSupport);
property._ownerRemove();
for (ValueSpecification vs : propertyGraphFetchTree._parameters()) {
if (vs instanceof InstanceValue) {
for (CoreInstance value : ((InstanceValue) vs)._valuesCoreInstance()) {
Shared.cleanEnumStub(value, processorSupport);
}
vs._genericTypeRemove();
vs._multiplicityRemove();
}
matcher.fullMatch(vs, state);
}
for (GraphFetchTree subTree : propertyGraphFetchTree._subTrees()) {
this.unbindPropertyGraphFetchTree((PropertyGraphFetchTree) subTree, mainTree, state, matcher);
}
ImportStub subTypeClass = (ImportStub) propertyGraphFetchTree._subTypeCoreInstance();
if (subTypeClass != null) {
CoreInstance resolvedSubTypeClass = subTypeClass._resolvedNodeCoreInstance();
if (resolvedSubTypeClass != null) {
ReferenceUsage.removeReferenceUsagesForUser(resolvedSubTypeClass, mainTree, state.getProcessorSupport());
}
Shared.cleanImportStub(subTypeClass, processorSupport);
}
propertyGraphFetchTree._classifierGenericTypeRemove();
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree in project legend-engine by finos.
the class HelperValueSpecificationBuilder method buildPropertyGraphFetchTree.
private static GraphFetchTree buildPropertyGraphFetchTree(PropertyGraphFetchTree propertyGraphFetchTree, CompileContext context, Class<?> parentClass, MutableList<String> openVariables, ProcessingContext processingContext) {
AbstractProperty<?> property;
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> pureParameters = Lists.mutable.empty();
if (!propertyGraphFetchTree.parameters.isEmpty()) {
Variable thisVariable = new Variable("this", HelperModelBuilder.getElementFullPath(parentClass, context.pureModel.getExecutionSupport()), new Multiplicity(1, 1));
property = HelperModelBuilder.getAppliedProperty(context, parentClass, Optional.of(Lists.mutable.<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification>with(thisVariable).withAll(propertyGraphFetchTree.parameters)), propertyGraphFetchTree.property);
processingContext.push("PropertyTree");
processingContext.addInferredVariables("this", HelperModelBuilder.createThisVariableForClass(context, HelperModelBuilder.getElementFullPath(parentClass, context.pureModel.getExecutionSupport())));
pureParameters = ListIterate.collect(propertyGraphFetchTree.parameters, x -> x.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)));
processingContext.flushVariable("this");
processingContext.pop();
} else {
property = HelperModelBuilder.getAppliedProperty(context, parentClass, Optional.empty(), propertyGraphFetchTree.property, propertyGraphFetchTree.sourceInformation);
}
Class<?> subType = propertyGraphFetchTree.subType == null ? null : context.resolveClass(propertyGraphFetchTree.subType, propertyGraphFetchTree.sourceInformation);
Type returnType = subType == null ? property._genericType()._rawType() : subType;
ListIterable<GraphFetchTree> children = ListIterate.collect(propertyGraphFetchTree.subTrees, subTree -> buildGraphFetchTree(subTree, context, (Class<?>) returnType, openVariables, processingContext));
return new Root_meta_pure_graphFetch_PropertyGraphFetchTree_Impl("")._property(property)._parameters(pureParameters)._alias(propertyGraphFetchTree.alias)._subType(subType)._subTrees(children);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree in project legend-pure by finos.
the class RootGraphFetchTreeProcessor method process.
@Override
public void process(RootGraphFetchTree<?> instance, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
CoreInstance _class = ImportStub.withImportStubByPass(instance._classCoreInstance(), processorSupport);
PostProcessor.processElement(matcher, _class, state, processorSupport);
ClassInstance type = (ClassInstance) processorSupport.package_getByUserPath(M3GraphPaths.RootGraphFetchTree);
GenericType classifierGT = GenericTypeInstance.createPersistent(repository);
GenericType typeArg = GenericTypeInstance.createPersistent(repository);
typeArg._rawType((Type) _class);
classifierGT._rawType(type);
classifierGT._typeArgumentsAdd(typeArg);
instance._classifierGenericType(classifierGT);
for (GraphFetchTree subTree : instance._subTrees()) {
this.processPropertyGraphFetchTree((PropertyGraphFetchTree) subTree, _class, state, matcher, repository, processorSupport);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree in project legend-pure by finos.
the class RootGraphFetchTreeProcessor method processPropertyGraphFetchTree.
private void processPropertyGraphFetchTree(PropertyGraphFetchTree propertyGraphFetchTree, CoreInstance _class, ProcessorState state, Matcher matcher, ModelRepository repository, ProcessorSupport processorSupport) {
ClassInstance type = (ClassInstance) processorSupport.package_getByUserPath(M3GraphPaths.PropertyGraphFetchTree);
GenericType classifierGT = GenericTypeInstance.createPersistent(repository);
classifierGT._rawTypeCoreInstance(type);
propertyGraphFetchTree._classifierGenericType(classifierGT);
PropertyStub propertyStubNonResolved = (PropertyStub) propertyGraphFetchTree._propertyCoreInstance();
String propertyName = propertyStubNonResolved._propertyName();
propertyStubNonResolved._ownerCoreInstance(_class);
for (ValueSpecification vs : propertyGraphFetchTree._parameters()) {
PostProcessor.processElement(matcher, vs, state, processorSupport);
if (vs instanceof InstanceValue) {
for (CoreInstance value : ((InstanceValue) vs)._valuesCoreInstance()) {
if (value instanceof EnumStub) {
EnumStub enumStub = (EnumStub) value;
Enumeration<?> enumerationCoreInstance = (Enumeration<?>) ImportStub.withImportStubByPass(enumStub._enumerationCoreInstance(), processorSupport);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum enumValue = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) org.finos.legend.pure.m3.navigation.enumeration.Enumeration.findEnum(enumerationCoreInstance, enumStub._enumName());
if (enumValue == null) {
throw new PureCompilationException(enumStub.getSourceInformation(), "The enum value '" + enumStub._enumName() + "' can't be found in the enumeration " + PackageableElement.getUserPathForPackageableElement(enumerationCoreInstance, "::"));
}
}
}
}
InstanceValueProcessor.updateInstanceValue(vs, processorSupport);
}
AbstractProperty<?> property = null;
if (propertyGraphFetchTree._parameters().isEmpty()) {
CoreInstance resolvedProperty = processorSupport.class_findPropertyUsingGeneralization(_class, propertyName);
if (resolvedProperty != null) {
property = (AbstractProperty<?>) resolvedProperty;
Instance.addValueToProperty(propertyStubNonResolved, M3Properties.resolvedProperty, property, processorSupport);
}
}
if (property == null) {
// Qualified
VariableExpression firstParam = (VariableExpression) processorSupport.newAnonymousCoreInstance(null, M3Paths.VariableExpression);
firstParam._genericType((GenericType) org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(_class, processorSupport));
firstParam._multiplicity((Multiplicity) processorSupport.package_getByUserPath(M3Paths.PureOne));
MutableList<ValueSpecification> params = FastList.newList();
params.add(firstParam);
for (ValueSpecification vs : propertyGraphFetchTree._parameters()) {
params.add(vs);
}
ListIterable<QualifiedProperty<?>> qualifiedProperties = _Class.findQualifiedPropertiesUsingGeneralization(_class, propertyName, processorSupport);
ListIterable<QualifiedProperty<?>> foundQualifiedProperties = FunctionExpressionMatcher.getFunctionMatches(qualifiedProperties, params, propertyName, propertyStubNonResolved.getSourceInformation(), true, processorSupport);
if (foundQualifiedProperties.isEmpty()) {
StringBuilder message = new StringBuilder("The system can't find a match for the property / qualified property: ");
FunctionExpression.printFunctionSignatureFromExpression(message, propertyName, params.without(firstParam), processorSupport);
if (qualifiedProperties.notEmpty()) {
if (MilestoningFunctions.isGeneratedQualifiedProperty(qualifiedProperties.getFirst(), processorSupport)) {
CoreInstance noArgPropertyReturnType = ImportStub.withImportStubByPass(qualifiedProperties.getFirst()._genericType()._rawTypeCoreInstance(), processorSupport);
ListIterable<String> temporalPropertyNames = MilestoningFunctions.getTemporalStereoTypePropertyNamesFromTopMostNonTopTypeGeneralizations(noArgPropertyReturnType, processorSupport);
message.append(". No-Arg milestoned property: '").append(propertyName).append("' is not supported yet in graph fetch flow! It needs to be supplied with ").append(temporalPropertyNames.makeString("[", ",", "]")).append(" parameters");
}
}
throw new PureCompilationException(propertyStubNonResolved.getSourceInformation(), message.toString());
}
property = foundQualifiedProperties.getFirst();
Instance.addValueToProperty(propertyStubNonResolved, M3Properties.resolvedProperty, property, processorSupport);
}
FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(property);
CoreInstance returnType = ImportStub.withImportStubByPass(functionType._returnType()._rawTypeCoreInstance(), processorSupport);
PostProcessor.processElement(matcher, returnType, state, processorSupport);
CoreInstance subTypeClass;
if (propertyGraphFetchTree._subTypeCoreInstance() != null) {
subTypeClass = ImportStub.withImportStubByPass(propertyGraphFetchTree._subTypeCoreInstance(), processorSupport);
PostProcessor.processElement(matcher, subTypeClass, state, processorSupport);
returnType = subTypeClass;
}
for (GraphFetchTree subTree : propertyGraphFetchTree._subTrees()) {
this.processPropertyGraphFetchTree((PropertyGraphFetchTree) subTree, returnType, state, matcher, repository, processorSupport);
}
if (MilestoningFunctions.isGeneratedQualifiedProperty(property, processorSupport)) {
CoreInstance propReturnType = ImportStub.withImportStubByPass(property._genericType()._rawTypeCoreInstance(), processorSupport);
ListIterable<String> temporalPropertyNames = MilestoningFunctions.getTemporalStereoTypePropertyNamesFromTopMostNonTopTypeGeneralizations(propReturnType, processorSupport);
if (propertyGraphFetchTree._parameters().size() != temporalPropertyNames.size()) {
this.throwMilestoningPropertyPathValidationException(property, propertyStubNonResolved.getSourceInformation(), processorSupport);
}
}
}
Aggregations