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;
}
}
Aggregations