get enumeration for enumeration-valued property of concept

I'm trying to do reflection on the structure of a language. This works fine through the API for that (`concept.getProperties()` etc.), except for enumeration-valued properties whose `.getType()` returns an object of type `SDataTypeAdapter` instead of an `SEnumeration` or an adapter-variant of that.

Is there another way of getting the `SEnumeration` instance for such properties?

6 comments
Comment actions Permalink

Does "enum/MyEnum/.members" help?

0
Comment actions Permalink

It would if I knew how to geld a hold (i.e., a reference to) that "MyEnum" from nothing more than an SProperty instance.

I've looked in the source and found https://github.com/JetBrains/MPS/blob/master/core/kernel/source/jetbrains/mps/smodel/adapter/structure/property/SPropertyAdapter.java
which seems to be the actual implementation backing both its SProperty interface as well as the SProperty concept from the MPS-model. Its "getType()"-method handles primitive types, but for everything else (non-null) it simply returns a no-args instance of SDataTypeAdapter which essentially does nothing. It looks like this is simply not hooked up, also because an SEnumerationAdapter class is suspiciously lacking. The SEnumAdapter class seems to be used for a different purpose and not for returning from the SProperty#getType method.

Is this just an oversight in MPS (i.e., the Open API implementation)?

1
Comment actions Permalink

I see what you are saying, and it looks like you are right, there is some implementation for enum missing.

 

In the meantime, you might be able to do something like this (though it is kludgy):

SNode snodeDeclaration = sproperty.getDeclarationNode(); 

node<> nodeDataType = snodeDeclaration.getReferenceTarget("dataType");

ifInstanceOf (nodeDataType is EnumerationDataTypeDeclaration nodeEnumDataType) {
// nodeDataType.member gives you the members
}

 

0
Comment actions Permalink

Ah, great: this works and it even allows me to clean up some other code that is more kludgy than this (I wasn't aware of the isInstanceOf-construct). Thanks! :)

Nevertheless: I think this should be fixed (i.e., added to the OpenAPI implementation) in MPS also because getDeclarationNode() is deprecated without a real alternative implemented.

0
Comment actions Permalink

Sure, if you haven't already done so, you might want to file an issue at https://youtrack.jetbrains.com/issues so it doesn't get forgotten.

0

Please sign in to leave a comment.