use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumerationInstance 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;
}
Aggregations