Search in sources :

Example 1 with PropertyGraphFetchTree

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);
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) RootGraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.RootGraphFetchTree) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) PropertyGraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with PropertyGraphFetchTree

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();
}
Also used : PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) RootGraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.RootGraphFetchTree) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) PropertyGraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)

Example 3 with PropertyGraphFetchTree

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);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) PackageableElementPtr(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PackageableElementPtr) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) BaseExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.BaseExecutionContext) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) AnalyticsExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.AnalyticsExecutionContext) AppliedProperty(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Objects(java.util.Objects) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) org.finos.legend.pure.generated(org.finos.legend.pure.generated) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) List(java.util.List) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Lists(org.eclipse.collections.impl.factory.Lists) ExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.ExecutionContext) VariableExpressionAccessor(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpressionAccessor) ListIterable(org.eclipse.collections.api.list.ListIterable) Optional(java.util.Optional) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)

Example 4 with PropertyGraphFetchTree

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 + "]" + ")";
}
Also used : GraphPathContext(org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphParser.GraphPathContext) ScalarParameterContext(org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphParser.ScalarParameterContext) ParameterContext(org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphParser.ParameterContext) AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 5 with PropertyGraphFetchTree

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);
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RootGraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.RootGraphFetchTree) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) PropertyGraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)

Aggregations

GraphFetchTree (org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree)7 PropertyGraphFetchTree (org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.PropertyGraphFetchTree)6 RootGraphFetchTree (org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.RootGraphFetchTree)6 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)6 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)4 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)4 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)3 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)3 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)3 ImportStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)2 PropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub)2 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)2 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)2 ClassInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)2 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Function (org.eclipse.collections.api.block.function.Function)1 ListIterable (org.eclipse.collections.api.list.ListIterable)1