Search in sources :

Example 1 with EnumerationInstance

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;
}
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)1 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)1 GeneralizationInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance)1 ClassInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)1 EnumerationInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumerationInstance)1 GenericTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance)1 EnumValueContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumValueContext)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)1