Search in sources :

Example 1 with AssociationInstance

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationInstance in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method associationParser.

private CoreInstance associationParser(AssociationContext ctx, ImportGroup importId) throws PureParserException {
    MutableList<Property<? extends CoreInstance, ?>> properties = Lists.mutable.empty();
    MutableList<QualifiedProperty<? extends CoreInstance>> qualifiedProperties = Lists.mutable.empty();
    ListIterable<CoreInstance> stereotypes = null;
    ListIterable<TaggedValue> tags = null;
    AssociationInstance associationInstance;
    ImportStub is;
    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());
    if (ctx.associationProjection() != null) {
        AssociationProjectionContext apCtx = ctx.associationProjection();
        ImportStubInstance projectedAssociation = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(apCtx.qualifiedName(0).getStart()), this.getQualifiedNameString(ctx.associationProjection().qualifiedName(0)), importId);
        ImportStubInstance projectionOne = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(apCtx.qualifiedName(1).getStart()), this.getQualifiedNameString(apCtx.qualifiedName(1)), importId);
        ImportStubInstance projectionTwo = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(apCtx.qualifiedName(2).getStart()), this.getQualifiedNameString(apCtx.qualifiedName(2)), importId);
        AssociationProjectionInstance projection = AssociationProjectionInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText(), this.sourceInformation.getPureSourceInformation(ctx.ASSOCIATION().getSymbol(), ctx.qualifiedName().identifier().getStart(), ctx.associationProjection().getStop()), null);
        projection._name(ctx.qualifiedName().identifier().getText());
        projection._package(packageInstance);
        packageInstance._childrenAdd(projection);
        projection._projectedAssociationCoreInstance(projectedAssociation);
        projection._projectionsCoreInstance(Lists.fixedSize.<CoreInstance>with(projectionOne, projectionTwo));
        if (!Iterate.isEmpty(stereotypes)) {
            projection._stereotypesCoreInstance(stereotypes);
        }
        if (!Iterate.isEmpty(tags)) {
            projection._taggedValues(tags);
        }
        return projection;
    } else {
        String associationName = ctx.qualifiedName().identifier().getText();
        associationInstance = AssociationInstance.createPersistent(this.repository, associationName);
        associationInstance._name(ctx.qualifiedName().identifier().getText());
        associationInstance._package(packageInstance);
        packageInstance._childrenAdd(associationInstance);
        GenericTypeInstance classifierGT = GenericTypeInstance.createPersistent(this.repository);
        ClassInstance assocationType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Association);
        classifierGT._rawTypeCoreInstance(assocationType);
        associationInstance._classifierGenericType(classifierGT);
        associationInstance._stereotypesCoreInstance(stereotypes);
        associationInstance._taggedValues(tags);
        is = ImportStubInstance.createPersistent(this.repository, this.getQualifiedNameString(ctx.qualifiedName()), importId);
        this.propertyParser(ctx.associationBody().properties(), properties, qualifiedProperties, Lists.fixedSize.empty(), Lists.fixedSize.empty(), is, importId, 0);
        associationInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.ASSOCIATION().getSymbol(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
        associationInstance._properties(properties);
        if (Iterate.notEmpty(qualifiedProperties)) {
            associationInstance._qualifiedProperties(qualifiedProperties);
        }
        return associationInstance;
    }
}
Also used : GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) AssociationProjectionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationProjectionInstance) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) AssociationProjectionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AssociationProjectionContext) PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) 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) AssociationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationInstance) 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) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Aggregations

PackageInstance (org.finos.legend.pure.m3.coreinstance.PackageInstance)1 ImportStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)1 ImportStubInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance)1 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)1 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)1 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)1 AssociationInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationInstance)1 AssociationProjectionInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.AssociationProjectionInstance)1 ClassInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)1 GenericTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance)1 AssociationProjectionContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AssociationProjectionContext)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)1