Programmatically read language version

Hi,

I have the requirement to generate a comment into each class that tells which language version was used for modelling.

Is there a way (via smodel language, for example), to access the language version? I am referring to this number:

0
2 comments
Avatar
Permanently deleted user

Okay, i found this in OpenAPI: language/my.dsl/.getLanguageVersion(), but is marked deprecated.

@Deprecated //normally, one shouldn't have used it. If you had, switch to getting version from LanguageRuntime

can someone explain to me what is meant by this comment? I do not know how to get the "LanguageRuntime"

0

I have the same problem to understand what was meant by this comment.

Supposed the stub jetbrains.mps.smodel@java_stub is imported,

you should be able to safely cast the source module to jetbrains.mps.smodel.Language:

((Language) language/my.dsl/.getSourceModule()).getLanguageVersion();

which is a short hand version for

((Language) language/my.dsl/.getSourceModule()).getLanguageDescriptor().getLanguageVersion();

The module version is also available from here:

((Language) language/my.dsl/.getSourceModule()).getLanguageDescriptor().getModuleVersion();

 

LanguageRuntime is the abstract class, which will be extended to implement the abstract method int getVersion().

In the source_gen folder of your language you will find a class named Language extending LanguageRuntime.

There are the generated hard coded values from the LanguageDescriptor along with some other stuff. But you will possibly miss the module version.

0

Please sign in to leave a comment.