use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumValueContext 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;
}
use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumValueContext in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method enumValue.
private CoreInstance enumValue(EnumValueContext ctx, CoreInstance enumeration, ImportGroup importId) {
ListIterable<CoreInstance> stereotypes = null;
ListIterable<TaggedValue> tags = null;
if (ctx.stereotypes() != null) {
stereotypes = this.stereotypes(ctx.stereotypes(), importId);
}
if (ctx.taggedValues() != null) {
tags = this.taggedValues(ctx.taggedValues(), importId);
}
CoreInstance enumValue = this.repository.newCoreInstance(ctx.identifier().getText(), enumeration, this.sourceInformation.getPureSourceInformation(ctx.identifier().getStart()), true);
enumValue.addKeyValue(Lists.immutable.of("Root", "children", "meta", "children", "pure", "children", "metamodel", "children", "type", "children", "Enum", "properties", "name"), this.repository.newStringCoreInstance_cached(ctx.identifier().getText()));
if (stereotypes != null) {
enumValue.setKeyValues(Lists.immutable.of("Root", "children", "meta", "children", "pure", "children", "metamodel", "children", "extension", "children", "ElementWithStereotypes", "properties", "stereotypes"), Lists.mutable.withAll(stereotypes));
}
if (tags != null) {
enumValue.setKeyValues(Lists.immutable.of("Root", "children", "meta", "children", "pure", "children", "metamodel", "children", "extension", "children", "ElementWithTaggedValues", "properties", "taggedValues"), Lists.mutable.<CoreInstance>withAll(tags));
}
return enumValue;
}
Aggregations