use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree 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.PropertyGraphFetchTree 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.PropertyGraphFetchTree 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.PropertyGraphFetchTree in project legend-pure by finos.
the class GraphAntlrTreeWalker method visitGraphPathContext.
private String visitGraphPathContext(GraphPathContext graphPathContext) {
SourceInformation definitionSourceInfo = this.sourceInformation.getPureSourceInformation(graphPathContext.start, graphPathContext.start, graphPathContext.stop);
SourceInformation propertySourceInfo = this.sourceInformation.getPureSourceInformation(graphPathContext.identifier().start, graphPathContext.identifier().start, graphPathContext.identifier().stop);
MutableList<String> subTrees = FastList.newList();
if (graphPathContext.graphDefinition() != null) {
for (GraphPathContext subGraphPathContext : graphPathContext.graphDefinition().graphPaths().graphPath()) {
subTrees.add(this.visitGraphPathContext(subGraphPathContext));
}
}
MutableList<String> parameters = FastList.newList();
if (graphPathContext.propertyParameters() != null) {
for (ParameterContext parameterContext : graphPathContext.propertyParameters().parameter()) {
parameters.add(this.visitParameterContext(parameterContext));
}
}
String subType = "";
if (graphPathContext.subtype() != null) {
SourceInformation subTypeSourceInfo = this.sourceInformation.getPureSourceInformation(graphPathContext.subtype().qualifiedName().start, graphPathContext.subtype().qualifiedName().start, graphPathContext.subtype().qualifiedName().stop);
subType = "^meta::pure::metamodel::import::ImportStub " + subTypeSourceInfo.toM4String() + " (importGroup = system::imports::" + this.importId._name() + ", idOrPath = '" + graphPathContext.subtype().qualifiedName().getText() + "')";
}
String alias = "";
if (graphPathContext.alias() != null) {
alias = graphPathContext.alias().STRING().getText();
}
return "^meta::pure::graphFetch::PropertyGraphFetchTree " + definitionSourceInfo.toM4String() + " (" + "property = " + "^meta::pure::metamodel::import::PropertyStub " + propertySourceInfo.toM4String() + " (propertyName = '" + graphPathContext.identifier().getText() + "'), " + "parameters = " + parameters.makeString("[", ", ", "]") + ", " + "subTrees = " + subTrees.makeString("[", ", ", "]") + ", " + "subType = [" + subType + "]" + ", " + "alias = [" + alias + "]" + ")";
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree 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);
}
}
Aggregations