Search in sources :

Example 1 with PackageInstance

use of org.finos.legend.pure.m3.coreinstance.PackageInstance in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method nativeFunction.

private void nativeFunction(NativeFunctionContext ctx, ImportGroup importId, String space, MutableList<CoreInstance> coreInstancesResult) {
    this.functionCounter++;
    NativeFunctionInstance function = NativeFunctionInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText() + this.functionCounter, this.sourceInformation.getPureSourceInformation(ctx.NATIVE().getSymbol(), ctx.qualifiedName().identifier().getStart(), ctx.END_LINE().getSymbol()));
    MutableList<String> typeParametersNames = Lists.mutable.empty();
    MutableList<String> multiplicityParametersNames = Lists.mutable.empty();
    if (ctx.typeAndMultiplicityParameters() != null) {
        this.typeParametersAndMultiplicityParameters(ctx.typeAndMultiplicityParameters(), typeParametersNames, multiplicityParametersNames);
    }
    FunctionType signature = functionTypeSignature(ctx.functionTypeSignature(), function, typeParametersNames, multiplicityParametersNames, importId, spacePlusTabs(space, 1));
    function._functionName(ctx.qualifiedName().identifier().getText());
    PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
    function._package(packageInstance);
    packageInstance._childrenAdd(function);
    GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
    Type type = (Type) this.processorSupport.package_getByUserPath(M3Paths.NativeFunction);
    genericTypeInstance._rawTypeCoreInstance(type);
    GenericTypeInstance genericTypeInstanceTa = GenericTypeInstance.createPersistent(this.repository);
    genericTypeInstanceTa._rawTypeCoreInstance(signature);
    genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(genericTypeInstanceTa));
    function._classifierGenericType(genericTypeInstance);
    coreInstancesResult.add(function);
}
Also used : PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) 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) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) NativeFunctionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.NativeFunctionInstance)

Example 2 with PackageInstance

use of org.finos.legend.pure.m3.coreinstance.PackageInstance in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method definition.

public CoreInstance definition(DefinitionContext ctx, boolean useImportStubsInInstanceParser) throws PureParserException {
    CoreInstance result = null;
    ImportGroup importId = null;
    if (ctx.imports() != null) {
        importId = this.imports(ctx.imports());
        if (this.oldState == null) {
            this.hasImportChanged = true;
        } else {
            String importGroupID = importId._name();
            RichIterable<? extends PackageableElement> oldImportGroups = this.oldState.getImportGroups().select(e -> importGroupID.equals(e._name()));
            if (oldImportGroups.size() == 1) {
                ImportGroup oldImportGroup = (ImportGroup) oldImportGroups.toList().get(0);
                MutableSet<String> oldPaths = oldImportGroup._imports().collect(Import::_path, Sets.mutable.empty());
                MutableSet<String> newPaths = importId._imports().collect(Import::_path, Sets.mutable.empty());
                if (oldPaths.equals(newPaths)) {
                    this.hasImportChanged = false;
                    PackageInstance parent = (PackageInstance) this.processorSupport.package_getByUserPath("system::imports");
                    parent._children(parent._children().reject(e -> importGroupID.equals(e._name())));
                    parent._childrenAdd(oldImportGroup);
                    oldImportGroup._package(parent);
                    oldImportGroup.setSourceInformation(importId.getSourceInformation());
                    oldImportGroup._imports(importId._imports());
                    importId = oldImportGroup;
                } else {
                    this.hasImportChanged = true;
                }
            } else {
                this.hasImportChanged = true;
            }
        }
    }
    if (ctx.profile() != null) {
        for (ProfileContext pCtx : ctx.profile()) {
            if (this.hasImportChanged) {
                result = this.profile(pCtx);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                MutableList<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                if (oldInstances.size() == 1) {
                    CoreInstance thisInstance = oldInstances.get(0);
                    this.oldInstances.remove(thisInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.getStart(), pCtx.qualifiedName().getStop(), pCtx.getStop());
                    if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
                        PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
                        ((PackageableElement) thisInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) thisInstance);
                        result = thisInstance;
                    } else {
                        result = this.profile(pCtx);
                    }
                } else {
                    result = this.profile(pCtx);
                }
            }
            this.coreInstancesResult.add(result);
        }
    }
    if (ctx.classDefinition() != null) {
        for (ClassDefinitionContext dCtx : ctx.classDefinition()) {
            if (this.hasImportChanged) {
                result = this.classParser(dCtx, importId, this.addLines);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(dCtx.start.getInputStream().getText(new Interval(dCtx.start.getStartIndex(), dCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                if (oldInstances.size() == 1) {
                    CoreInstance thisInstance = oldInstances.get(0);
                    this.oldInstances.remove(thisInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(dCtx.getStart(), dCtx.qualifiedName().identifier().getStart(), dCtx.getStop());
                    if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
                        PackageInstance packageInstance = this.buildPackage(dCtx.qualifiedName().packagePath());
                        ((PackageableElement) thisInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) thisInstance);
                        result = thisInstance;
                    } else {
                        result = this.classParser(dCtx, importId, this.addLines);
                    }
                } else {
                    result = this.classParser(dCtx, importId, this.addLines);
                }
            }
            this.coreInstancesResult.add(result);
        }
    }
    if (ctx.measureDefinition() != null) {
        for (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.MeasureDefinitionContext dCtx : ctx.measureDefinition()) {
            if (this.hasImportChanged) {
                result = this.measureParser(dCtx, importId, this.addLines);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(dCtx.start.getInputStream().getText(new Interval(dCtx.start.getStartIndex(), dCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                Predicate2<CoreInstance, SourceInformation> matchesOldInstance = (oldMeasureInstance, newSourceInfo) -> {
                    if (newSourceInfo == null || oldMeasureInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        PackageInstance packageInstance;
                        if (newSourceInfo != null) {
                            offsetSourceInformationForInstanceAndChildren(oldMeasureInstance, newSourceInfo.getStartLine() - oldMeasureInstance.getSourceInformation().getStartLine());
                        }
                        Function<String, IdentifierContext> newIdentifierContext = s -> new IdentifierContext(null, 1) {

                            @Override
                            public String getText() {
                                return s;
                            }
                        };
                        packageInstance = buildPackage(Lists.mutable.with(newIdentifierContext.valueOf(oldMeasureInstance.getValueForMetaPropertyToOne(M3Properties._package).getName())));
                        ((PackageableElement) oldMeasureInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) oldMeasureInstance);
                        return true;
                    }
                    return false;
                };
                CoreInstance oldMeasureInstance = ListIterate.detect(oldInstances, i -> Instance.instanceOf(i, M3Paths.Measure, this.processorSupport));
                if (oldMeasureInstance != null) {
                    this.oldInstances.remove(oldMeasureInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(dCtx.getStart(), dCtx.qualifiedName().identifier().getStart(), dCtx.getStop());
                    if (matchesOldInstance.accept(oldMeasureInstance, newSourceInfo)) {
                        MeasureInstance mI = (MeasureInstance) oldMeasureInstance;
                        result = mI;
                        MutableList<Unit> units = Lists.mutable.with(mI._canonicalUnit()).withAll(mI._nonCanonicalUnits());
                        for (Unit unit : units) {
                            PackageInstance packageInstance = buildPackage(Lists.mutable.withAll(dCtx.qualifiedName().packagePath() == null ? Lists.mutable.empty() : ListAdapter.adapt(dCtx.qualifiedName().packagePath().identifier())));
                            unit._package(packageInstance);
                            packageInstance._childrenAdd(unit);
                        }
                    } else {
                        result = this.measureParser(dCtx, importId, this.addLines);
                    }
                } else {
                    result = this.measureParser(dCtx, importId, this.addLines);
                }
            }
            MeasureInstance mI = (MeasureInstance) result;
            List<Unit> allMeasureUnitInstances = Lists.mutable.<Unit>withAll(mI._nonCanonicalUnits()).with(mI._canonicalUnit()).toList();
            this.coreInstancesResult.add(result);
            this.coreInstancesResult.addAll(allMeasureUnitInstances);
        }
    }
    if (ctx.association() != null) {
        for (AssociationContext pCtx : ctx.association()) {
            if (this.hasImportChanged) {
                result = this.associationParser(pCtx, importId);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                if (oldInstances.size() == 1) {
                    CoreInstance thisInstance = oldInstances.get(0);
                    this.oldInstances.remove(thisInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.ASSOCIATION().getSymbol(), pCtx.qualifiedName().identifier().getStart(), pCtx.getStop());
                    if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
                        PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
                        ((PackageableElement) thisInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) thisInstance);
                        result = thisInstance;
                    } else {
                        result = this.associationParser(pCtx, importId);
                    }
                } else {
                    result = this.associationParser(pCtx, importId);
                }
            }
            this.coreInstancesResult.add(result);
        }
    }
    if (ctx.enumDefinition() != null) {
        for (EnumDefinitionContext pCtx : ctx.enumDefinition()) {
            if (this.hasImportChanged) {
                result = this.enumParser(pCtx, importId);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                if (oldInstances.size() == 1) {
                    CoreInstance thisInstance = oldInstances.get(0);
                    this.oldInstances.remove(thisInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.getStart(), pCtx.qualifiedName().identifier().getStart(), pCtx.getStop());
                    if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
                        PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
                        ((PackageableElement) thisInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) thisInstance);
                        result = thisInstance;
                    } else {
                        result = this.enumParser(pCtx, importId);
                    }
                } else {
                    result = this.enumParser(pCtx, importId);
                }
            }
            this.coreInstancesResult.add(result);
        }
    }
    if (ctx.nativeFunction() != null) {
        for (NativeFunctionContext pCtx : ctx.nativeFunction()) {
            if (this.hasImportChanged) {
                this.nativeFunction(pCtx, importId, "", this.coreInstancesResult);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                if (oldInstances.size() == 1) {
                    CoreInstance thisInstance = oldInstances.get(0);
                    this.oldInstances.remove(thisInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.NATIVE().getSymbol(), pCtx.qualifiedName().identifier().getStart(), pCtx.END_LINE().getSymbol());
                    if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        this.functionCounter++;
                        this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
                        PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
                        ((PackageableElement) thisInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) thisInstance);
                        this.coreInstancesResult.add(thisInstance);
                    } else {
                        this.nativeFunction(pCtx, importId, "", this.coreInstancesResult);
                    }
                } else {
                    this.nativeFunction(pCtx, importId, "", this.coreInstancesResult);
                }
            }
        }
    }
    if (ctx.functionDefinition() != null) {
        for (FunctionDefinitionContext pCtx : ctx.functionDefinition()) {
            if (this.hasImportChanged) {
                result = this.concreteFunctionDefinition(pCtx, importId, true, "", this.coreInstancesResult);
            } else {
                String importGroupID = importId._name();
                String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
                List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
                if (oldInstances.size() == 1) {
                    CoreInstance thisInstance = oldInstances.get(0);
                    this.oldInstances.remove(thisInstance);
                    SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.FUNCTION().getSymbol(), pCtx.qualifiedName().identifier().getStart(), pCtx.getStop());
                    if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
                        this.functionCounter++;
                        this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
                        PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
                        ((PackageableElement) thisInstance)._package(packageInstance);
                        packageInstance._childrenAdd((PackageableElement) thisInstance);
                        this.coreInstancesResult.add(thisInstance);
                        result = thisInstance;
                    } else {
                        result = this.concreteFunctionDefinition(pCtx, importId, true, "", this.coreInstancesResult);
                    }
                } else {
                    result = this.concreteFunctionDefinition(pCtx, importId, true, "", this.coreInstancesResult);
                }
            }
        }
    }
    if (ctx.instance() != null) {
        for (InstanceContext pCtx : ctx.instance()) {
            result = this.instanceParser(pCtx, true, importId, this.addLines, "", true, useImportStubsInInstanceParser);
            this.coreInstancesResult.add(result);
        }
    }
    this.newSourceInfoMap.forEachKeyValue(CoreInstance::setSourceInformation);
    return result;
}
Also used : RootRouteNodeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNodeInstance) StereotypesContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.StereotypesContext) NotExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.NotExpressionContext) MultiplicityArgumentContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.MultiplicityArgumentContext) InstanceValueInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValueInstance) TaggedValueContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TaggedValueContext) ExpressionInstanceContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceContext) EnumDefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumDefinitionContext) InlineDSL(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSL) LambdaPipeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LambdaPipeContext) InstanceAtomicRightSideContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceAtomicRightSideContext) ContravarianceTypeParameterContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ContravarianceTypeParameterContext) LambdaParamTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LambdaParamTypeContext) ClassDefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ClassDefinitionContext) Iterate(org.eclipse.collections.impl.utility.Iterate) Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) Import_statementContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.Import_statementContext) GeneralizationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance) ListIterable(org.eclipse.collections.api.list.ListIterable) ConcreteFunctionDefinitionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinitionInstance) TypeParameterInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameterInstance) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) IdentifierContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.IdentifierContext) PackagePathContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PackagePathContext) Function(org.eclipse.collections.api.block.function.Function) MutableStack(org.eclipse.collections.api.stack.MutableStack) FunctionTypeSignatureContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionTypeSignatureContext) ExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionContext) M3Paths(org.finos.legend.pure.m3.navigation.M3Paths) TreePathContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathContext) ProfileInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ProfileInstance) ProfileContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ProfileContext) TypeParameterContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeParameterContext) MutableMap(org.eclipse.collections.api.map.MutableMap) Package(org.finos.legend.pure.m3.coreinstance.Package) LambdaFunctionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunctionInstance) InstanceLiteralContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceLiteralContext) Sets(org.eclipse.collections.api.factory.Sets) TagInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TagInstance) LetExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LetExpressionContext) ConstraintsContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ConstraintsContext) FunctionExpressionParametersContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionExpressionParametersContext) StereotypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.StereotypeInstance) PureParserException(org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException) InstanceRightSideContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceRightSideContext) MappingLineContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.MappingLineContext) MappingContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.MappingContext) ListIterate(org.eclipse.collections.impl.utility.ListIterate) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) StereotypeDefinitionsContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.StereotypeDefinitionsContext) QualifiedNameContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.QualifiedNameContext) AssociationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationInstance) AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) ExpressionInstanceAtomicRightSideContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceAtomicRightSideContext) AssociationProjectionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AssociationProjectionContext) ConstraintInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.ConstraintInstance) Stacks(org.eclipse.collections.api.factory.Stacks) Constraint(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.Constraint) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) EnumValueContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumValueContext) Tag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag) Interval(org.antlr.v4.runtime.misc.Interval) NativeFunctionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.NativeFunctionContext) Predicate2(org.eclipse.collections.api.block.predicate.Predicate2) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) BuildMilestoningVariableExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.BuildMilestoningVariableExpressionContext) MutableList(org.eclipse.collections.api.list.MutableList) MultiplicityInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.MultiplicityInstance) PropertyExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertyExpressionContext) Maps(org.eclipse.collections.api.factory.Maps) MutableSet(org.eclipse.collections.api.set.MutableSet) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) InstanceContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceContext) DefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.DefinitionContext) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) BooleanPartContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.BooleanPartContext) ExpressionOrExpressionGroupContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionOrExpressionGroupContext) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) QualifiedPropertyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.QualifiedPropertyContext) TypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeContext) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) SourceState(org.finos.legend.pure.m3.serialization.runtime.SourceState) DefaultValueExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.DefaultValueExpressionContext) PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) Unit(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Unit) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) TaggedValueInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValueInstance) RouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNode) DefaultValueInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.DefaultValueInstance) ProgramLineContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ProgramLineContext) CombinedArithmeticOnlyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.CombinedArithmeticOnlyContext) InstanceReferenceContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceReferenceContext) TaggedValuesContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TaggedValuesContext) ImportInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportInstance) CodeBlockContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.CodeBlockContext) Any(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any) ArithmeticPartContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ArithmeticPartContext) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) InlineDSLTextContent(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLTextContent) FunctionVariableExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionVariableExpressionContext) CombinedExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.CombinedExpressionContext) ExistingPropertyRouteNodeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNodeInstance) SimpleFunctionExpressionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpressionInstance) ExpressionInstanceRightSideContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceRightSideContext) NativeFunctionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.NativeFunctionInstance) InstanceLiteralTokenContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceLiteralTokenContext) AssociationContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AssociationContext) EnumStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.EnumStubInstance) PropertyStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStubInstance) DslContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.DslContext) Token(org.antlr.v4.runtime.Token) ImportGroup(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup) VariableContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.VariableContext) TypeParameter(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameter) RichIterable(org.eclipse.collections.api.RichIterable) TreePathClassBodyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathClassBodyContext) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) EqualNotEqualContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EqualNotEqualContext) QualifiedPropertyInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedPropertyInstance) ModelRepository(org.finos.legend.pure.m4.ModelRepository) DefaultValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.DefaultValue) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) SourceAndTargetMappingIdContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.SourceAndTargetMappingIdContext) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) FunctionDefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionDefinitionContext) DerivedPropertyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.DerivedPropertyContext) DefaultValueContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.DefaultValueContext) NewPropertyRouteNodeFunctionDefinition(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeFunctionDefinition) GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) Instance(org.finos.legend.pure.m3.navigation.Instance) ImportsContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ImportsContext) Lists(org.eclipse.collections.api.factory.Lists) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode) MilestoningClassProcessor(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningClassProcessor) NewPropertyRouteNodeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeInstance) FunctionTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionTypeInstance) TreePathPropertyParameterTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathPropertyParameterTypeContext) RuleContext(org.antlr.v4.runtime.RuleContext) FastList(org.eclipse.collections.impl.list.mutable.FastList) InlineDSLLibrary(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary) InstancePropertyAssignmentContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstancePropertyAssignmentContext) PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) TagDefinitionsContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TagDefinitionsContext) Stereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype) ExpressionPartContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionPartContext) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) AllOrFunctionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AllOrFunctionContext) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) VariableExpressionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpressionInstance) PropertiesContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertiesContext) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) ClassProjectionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassProjectionInstance) PropertyRefContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertyRefContext) PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) ComplexPropertyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ComplexPropertyContext) Source(org.finos.legend.pure.m3.serialization.runtime.Source) AtomicExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AtomicExpressionContext) TypeArgumentsContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeArgumentsContext) TypeParametersWithContravarianceAndMultiplicityParametersContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeParametersWithContravarianceAndMultiplicityParametersContext) MultiplicityArgumentsContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.MultiplicityArgumentsContext) AssociationProjectionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationProjectionInstance) ExpressionInstanceParserPropertyAssignmentContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceParserPropertyAssignmentContext) UnitInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.UnitInstance) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) ImportGroupInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroupInstance) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) Tuples(org.eclipse.collections.impl.tuple.Tuples) Import(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.Import) TypeAndMultiplicityParametersContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeAndMultiplicityParametersContext) MultiplicityValueInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.MultiplicityValueInstance) KeyExpressionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.lang.KeyExpressionInstance) List(java.util.List) SimplePropertyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.SimplePropertyContext) org.finos.legend.pure.m3.navigation._package._Package(org.finos.legend.pure.m3.navigation._package._Package) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) StereotypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.StereotypeContext) ConstraintContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ConstraintContext) Context(org.finos.legend.pure.m3.compiler.Context) SignedExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.SignedExpressionContext) Function0(org.eclipse.collections.api.block.function.Function0) PropertyContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertyContext) RouteNodePropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStub) PropertyInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.PropertyInstance) Pair(org.eclipse.collections.api.tuple.Pair) MeasureInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.MeasureInstance) Enumeration(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration) EnumerationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumerationInstance) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) RouteNodePropertyStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RouteNodePropertyStubInstance) ImportStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance) FunctionTypePureTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionTypePureTypeContext) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) NewPropertyRouteNodeFunctionDefinitionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNodeFunctionDefinitionInstance) M3Properties(org.finos.legend.pure.m3.navigation.M3Properties) PropertyOrFunctionExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertyOrFunctionExpressionContext) Import(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.Import) NativeFunctionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.NativeFunctionContext) Unit(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Unit) FunctionDefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionDefinitionContext) Function(org.eclipse.collections.api.block.function.Function) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) ExpressionInstanceContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceContext) InstanceContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.InstanceContext) IdentifierContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.IdentifierContext) ImportGroup(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup) PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) ClassDefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ClassDefinitionContext) EnumDefinitionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumDefinitionContext) AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) MeasureInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.MeasureInstance) PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) ProfileContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ProfileContext) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) AssociationContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AssociationContext) Interval(org.antlr.v4.runtime.misc.Interval)

Example 3 with PackageInstance

use of org.finos.legend.pure.m3.coreinstance.PackageInstance in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method profile.

private ProfileInstance profile(ProfileContext ctx) {
    PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
    String profileName = ctx.qualifiedName().identifier().getText();
    ProfileInstance profileInstance = ProfileInstance.createPersistent(this.repository, profileName);
    profileInstance._package(packageInstance);
    packageInstance._childrenAdd(profileInstance);
    profileInstance._name(profileName);
    profileInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.qualifiedName().getStop(), ctx.getStop()));
    profileInstance._p_stereotypes(this.buildStereoTypes(ctx.stereotypeDefinitions(), profileInstance));
    profileInstance._p_tags(this.buildTags(ctx.tagDefinitions(), profileInstance));
    return profileInstance;
}
Also used : PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) ProfileInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ProfileInstance)

Example 4 with PackageInstance

use of org.finos.legend.pure.m3.coreinstance.PackageInstance in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method classParser.

private CoreInstance classParser(ClassDefinitionContext ctx, ImportGroup importId, boolean addLines) throws PureParserException {
    MutableList<Property<? extends CoreInstance, ?>> properties = Lists.mutable.empty();
    MutableList<QualifiedProperty<? extends CoreInstance>> qualifiedProperties = Lists.mutable.empty();
    MutableList<GenericType> superTypesGenericTypes = Lists.mutable.empty();
    boolean isDirectSubTypeofAny = false;
    MutableList<String> typeParameterNames = Lists.mutable.empty();
    MutableList<Boolean> contravariants = Lists.mutable.empty();
    MutableList<String> multiplicityParameterNames = Lists.mutable.empty();
    ImportStubInstance ownerType;
    ListIterable<CoreInstance> stereotypes = null;
    ListIterable<TaggedValue> tags = null;
    ClassInstance classInstance;
    if (ctx.stereotypes() != null) {
        stereotypes = this.stereotypes(ctx.stereotypes(), importId);
    }
    if (ctx.taggedValues() != null) {
        tags = this.taggedValues(ctx.taggedValues(), importId);
    }
    this.checkExists(ctx.qualifiedName().packagePath(), ctx.qualifiedName().identifier(), null);
    if (ctx.typeParametersWithContravarianceAndMultiplicityParameters() != null) {
        this.typeParametersWithContravarianceAndMultiplicityParameters(ctx.typeParametersWithContravarianceAndMultiplicityParameters(), typeParameterNames, contravariants, multiplicityParameterNames);
    }
    if (ctx.projection() != null) {
        return this.projectionParser(ctx, importId, addLines, stereotypes, tags);
    } else {
        if (ctx.EXTENDS() != null) {
            for (TypeContext typeCtx : ctx.type()) {
                superTypesGenericTypes.add(this.type(typeCtx, typeParameterNames, "", importId, addLines));
            }
        }
        String className = ctx.qualifiedName().identifier().getText();
        classInstance = ClassInstance.createPersistent(this.repository, className);
        PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
        classInstance._package(packageInstance);
        packageInstance._childrenAdd(classInstance);
        String fullName = this.getQualifiedNameString(ctx.qualifiedName());
        ownerType = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.qualifiedName().identifier().getStart()), fullName, importId);
        LambdaContext lambdaContext = new LambdaContext(fullName.replace("::", "_"));
        MutableList<Constraint> constraints = this.constraints(classInstance, ctx.constraints(), importId, lambdaContext, addLines);
        this.propertyParser(ctx.classBody().properties(), properties, qualifiedProperties, typeParameterNames, multiplicityParameterNames, ownerType, importId, 0);
        classInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
        if (superTypesGenericTypes.isEmpty()) {
            isDirectSubTypeofAny = true;
            GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
            genericTypeInstance._rawTypeCoreInstance(this.processorSupport.package_getByUserPath(M3Paths.Any));
            superTypesGenericTypes.add(genericTypeInstance);
        }
        GenericTypeInstance classifierGT = GenericTypeInstance.createPersistent(this.repository);
        ClassInstance classType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Class);
        classifierGT._rawTypeCoreInstance(classType);
        GenericTypeInstance classifierGTTA = GenericTypeInstance.createPersistent(this.repository);
        classifierGTTA._rawTypeCoreInstance(classInstance);
        if (!typeParameterNames.isEmpty()) {
            MutableList<TypeParameter> typeParameters = Lists.mutable.of();
            MutableList<Pair<String, Boolean>> tps = typeParameterNames.zip(contravariants);
            for (Pair<String, Boolean> typeParam : tps) {
                TypeParameterInstance tp = TypeParameterInstance.createPersistent(this.repository, typeParam.getOne());
                tp._contravariant(typeParam.getTwo());
                typeParameters.add(tp);
            }
            classInstance._typeParameters(typeParameters);
            MutableList<GenericType> typeArgs = Lists.mutable.of();
            for (String typeParamName : typeParameterNames) {
                TypeParameterInstance tp = TypeParameterInstance.createPersistent(this.repository, typeParamName);
                GenericTypeInstance gt = GenericTypeInstance.createPersistent(this.repository);
                gt._typeParameter(tp);
                typeArgs.add(gt);
            }
            classifierGTTA._typeArguments(typeArgs);
        }
        if (!multiplicityParameterNames.isEmpty()) {
            MutableList<Multiplicity> multParameters = Lists.mutable.of();
            for (String multiplicityParam : multiplicityParameterNames) {
                MultiplicityInstance mult = MultiplicityInstance.createPersistent(this.repository, null, null);
                mult._multiplicityParameter(multiplicityParam);
                multParameters.add(mult);
            }
            classInstance._multiplicityParameters(this.processMultiplicityParametersInstance(multiplicityParameterNames));
            classifierGTTA._multiplicityArguments(multParameters);
        }
        classifierGT._typeArguments(Lists.mutable.<GenericType>of(classifierGTTA));
        classInstance._classifierGenericType(classifierGT);
        if (properties.notEmpty()) {
            classInstance._properties(properties);
        }
        if (qualifiedProperties.notEmpty()) {
            classInstance._qualifiedProperties(qualifiedProperties);
        }
        classInstance._name(ctx.qualifiedName().identifier().getText());
        if (stereotypes != null) {
            classInstance._stereotypesCoreInstance(stereotypes);
        }
        if (tags != null) {
            classInstance._taggedValues(tags);
        }
        if (constraints.notEmpty()) {
            classInstance._constraints(constraints);
        }
        MutableList<Generalization> generalizations = Lists.mutable.empty();
        for (GenericType superType : superTypesGenericTypes) {
            GeneralizationInstance generalizationInstance = GeneralizationInstance.createPersistent(this.repository, superType, classInstance);
            generalizations.add(generalizationInstance);
        }
        classInstance._generalizations(generalizations);
        if (isDirectSubTypeofAny) {
            MilestoningClassProcessor.addMilestoningProperty(classInstance, this.context, this.processorSupport, this.repository);
        }
        return classInstance;
    }
}
Also used : TypeParameter(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameter) Constraint(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.Constraint) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) LambdaParamTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LambdaParamTypeContext) TypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeContext) TreePathPropertyParameterTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathPropertyParameterTypeContext) FunctionTypePureTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionTypePureTypeContext) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) MultiplicityInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.MultiplicityInstance) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) Pair(org.eclipse.collections.api.tuple.Pair) GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) TypeParameterInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameterInstance) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) GeneralizationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ImportStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Example 5 with PackageInstance

use of org.finos.legend.pure.m3.coreinstance.PackageInstance in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method enumParser.

private Enumeration<?> enumParser(EnumDefinitionContext ctx, ImportGroup importId) throws PureParserException {
    EnumerationInstance enumerationInstance;
    CoreInstance value;
    MutableList<CoreInstance> values = Lists.mutable.empty();
    ListIterable<CoreInstance> stereotypes = Lists.mutable.empty();
    ListIterable<TaggedValue> tags = Lists.mutable.empty();
    if (ctx.stereotypes() != null) {
        stereotypes = this.stereotypes(ctx.stereotypes(), importId);
    }
    if (ctx.taggedValues() != null) {
        tags = this.taggedValues(ctx.taggedValues(), importId);
    }
    this.checkExists(ctx.qualifiedName().packagePath(), ctx.qualifiedName().identifier(), null);
    PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
    GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
    ClassInstance enumerationType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Enumeration);
    genericTypeInstance._rawTypeCoreInstance(enumerationType);
    enumerationInstance = EnumerationInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText());
    enumerationInstance._name(ctx.qualifiedName().identifier().getText());
    enumerationInstance._package(packageInstance);
    GenericTypeInstance taGenericType = GenericTypeInstance.createPersistent(this.repository);
    taGenericType._rawTypeCoreInstance(enumerationInstance);
    genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(taGenericType));
    enumerationInstance._classifierGenericType(genericTypeInstance);
    packageInstance._childrenAdd(enumerationInstance);
    if (!tags.isEmpty()) {
        enumerationInstance._taggedValues(tags);
    }
    if (!stereotypes.isEmpty()) {
        enumerationInstance._stereotypesCoreInstance(stereotypes);
    }
    enumerationInstance._classifierGenericType(genericTypeInstance);
    GenericTypeInstance general = GenericTypeInstance.createPersistent(this.repository);
    ClassInstance enumType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Enum);
    general._rawTypeCoreInstance(enumType);
    GeneralizationInstance gen = GeneralizationInstance.createPersistent(this.repository, general, enumerationInstance);
    enumerationInstance._generalizations(Lists.mutable.<Generalization>of(gen));
    for (EnumValueContext evCtx : ctx.enumValue()) {
        value = this.enumValue(evCtx, enumerationInstance, importId);
        values.add(value);
    }
    enumerationInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
    enumerationInstance._values(values);
    return enumerationInstance;
}
Also used : PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) EnumValueContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumValueContext) GeneralizationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) EnumerationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumerationInstance) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)

Aggregations

PackageInstance (org.finos.legend.pure.m3.coreinstance.PackageInstance)19 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)12 GenericTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance)11 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)11 ClassInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)8 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)8 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)7 GeneralizationInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance)7 Package (org.finos.legend.pure.m3.coreinstance.Package)6 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)6 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)6 Pair (org.eclipse.collections.api.tuple.Pair)5 ImportStubInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance)5 Constraint (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.Constraint)5 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)5 Generalization (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization)5 PackageCoreInstanceWrapper (org.finos.legend.pure.m3.coreinstance.PackageCoreInstanceWrapper)4 ImportGroupInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroupInstance)4 MultiplicityInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.MultiplicityInstance)4 TypeParameter (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameter)4