Use MPS Concepts in IntelliJ Idea Java source files (Inline MPS?)


I am successfully creating IntelliJ IDEA plugins which I am able to load and use as described in the documentation[1].

This works great - however I am wondering how to allow a user to use my concepts within their normal java source files (similar to [2]). Think of it as some sort of inline DSL. All my efforts end up in me creating a MPS model within my project which works but is not what I am looking for...

Is there any way to allow this? Cheers!




1 comment
Comment actions Permalink


Because MPS editor is not text editor, you can't directly use your DSL in java source files.
But there several ways, that probably can suit you:

  • Use baseLanguage classes instead of java. This way you stay in MPS editor, so can mix languages. In such case using MPS IDE directly even better. But as you've created plugin for Idea in the first place, it is probably not what you want.
  • Do other way around and use your java sources in DSL. MPS facet on module creates java source stub model from your java sources, if you import this model, then you will be able to use your classes from DSL as baseLanguage classes.
  • Create some sort of adapter between your DSL and java: this can be some runtime baseLanguage class with methods to use DSL. MPS plugin for Idea also allows you to import and reference baseLanguage classes from you MPS models. So it is not direct use of DSL, but way to avoid referencing generated sources directly and do this in more controllable way. 

Probably you can mix this approaches, for example: use baseLanguage classes instead of java source classes, where you want to use DSL and then use such baseLanguage classes in other java sources directly.

One more suggestion: you can use per-root persistence for baseLanguage classes to mix java sources with MPS roots in one package: 


Please sign in to leave a comment.