Search in sources :

Example 1 with EnumValueContext

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

Example 2 with EnumValueContext

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;
}
Also used : 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)

Aggregations

TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)2 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)2 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)2 PackageInstance (org.finos.legend.pure.m3.coreinstance.PackageInstance)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