Extending Java, *not* Base Language


Hi

I am interested in trying some Java extensions in MPS, but I want to extend Java only - extending Base Language is of no interest to me, and I explicitly must not have any of its extensions. This is, amongst other reasons, so that existing Java codebases can be used directly with any extensions of mine, without any conversion.

Is this possible in MPS?

Thanks
Barney
3 comments
Base language IS Java.  The other extensions (collections, dates, regular expressions, etc.) are added as language extensions.  So you can extend Base Language directly, and it can be used with or without the other extensions as you see fit.
0


So to confirm ... any Java 6 file can be correctly compiled (without modifications) by the base language compiler? And all files which do not compile under Java 6 cannot be compiled by the base language compiler? I was under the impression that various things I saw in "Base Language" examples (such as supporting "string" as an alias to "String", etc.) were part of the the default compiler.  

Thanks.
0
There is no "base language compiler".  It generates the source code and then runs the standard Java compiler, which you can turn off and just compile the code yourself later, if you want.  

So for example, the "string" type you mentioned is generated to a java.lang.String in the source code.  In fact, all of the base language extensions generate to pure Java code, so don't feel like you have to avoid them for that reason.  It's the same way Xtend or Coffeescript works, in that respect.

With a large existing codebase, it would be very risky/insane to try to convert everything over to MPS in one pass.  But there is no reason to - pick a small part of your project that could really benefit from code generation and use it to test the waters.  Modeling your entities and then generating the persistence layer is a popular starting point (seems to be the "hello world" of code generation).  State machines, user interfaces, component models - these are all easy abstractions to model and generate as part of your project as the need arises.

If you are using IntelliJ for your IDE, you can use the MPS plugin, but that's not required (it just makes things a little nicer, because you can edit your models right in the IDE).  Without the plugin, or for another environment like Eclipse, just create a new source folder for your generated code and setup MPS to generate your model to that folder.  Then the source will get picked up by your build scripts.  For example, I usually use Maven, so next to the 'src' folder I create a 'src-gen' folder and set MPS to generate the code to there.  A few changes to the POM to include that folder and you're ready to go.  

There is an Ant script to generate the models, but last I saw it was broken (hopefully they fixed it for 3.0).  That would allow you to even include the model generation as part of your build, but even without it generating the models manually isn't usually a problem if you're just doing a small part, like entities.
I usually don't put the generated code in version control IF I can generate as part of the build, but if you are generating manually, then you probably need to check it in, so the repository is always in a buildable state.
0

Please sign in to leave a comment.