Monday, March 21, 2011

A Guice Modules DSL

[Update] The code is available at github

Yesterday Sebastian and I were attending GuiceCon. A nice little get-together with the Guice developers and some very smart Guice users. As Guice is key in Xtext's architecture we took the opportunity to show the people what we do with it. The first idea was to just explain how we use Guice, but while we travelled across California last week a better idea came up : We could develop a Guice Modules DSL using Xtext.

So we did and we did it from scratch right in front of the audience without any tricks or shortcuts. The good thing was that everyone in the room knew the domain very well, so we didn't need to explain anything about the domain of the language.
First I defined the grammar and a first shot on the code generator and then Sebastian added type conformance checks and improved content assist. Today I've spent another two hours on it. The screencast below demos the status quo.

Note that there will be an extended tutorial at EclipseCon this Thursday, where you can learn how to create such things yourself in no time. Not to forget the short talk on "What's new in Xtext 2.0", Tuesday 2 pm.

Have fun!

6 comments:

  1. Great work, Sven!

    Could you maybe provide a demo focused on the xbase feaures? Would be very interesting to learn those...

    I can not wait to use closures etc...

    Greets,

    Simon

    ReplyDelete
  2. apart from the really very nice eclipse intergration, how is that any better from using modules defined in the java language?

    generated sourcecode creates all kinds of problems (commit to SCM or not, etc...)

    ReplyDelete
  3. @javadoc:
    The main advantages are

    1) Static analysis is possible. From checks for duplicate keys to sophisticated analysis telling you whether your module is consistent. Most of the validation which is done when an injector is created can be done statically (i.e. while you type).

    2) The tooling is smarter. For instance, the content assist is proposing only subtypes of the "from"-key. Only annotations which are annotated with @BindingAnnotation are proposed.

    3) Type literals and annotations can be written down as is. You don't have to rely on things like TypeLiteral and so on. Also the syntax in general is slightly more readable.

    4) The mixin feature allows for more fine grained control when composing multiple modules.

    But you are right, relying on code generation has its price. Note that you can run the generator without eclipse and have it integrated in a build process, so you don't have to check in the generated code.

    ReplyDelete
  4. Well done!

    Could you maybe provide the sources of this example (sample project + xtext grammar project...), or does the sources already exists in an public repository. Would be very nice, to understand all the things step by step in the code...

    ReplyDelete
  5. Hey Sven, I'm really looking forward to the Xtext tutorial on Thursday. I was the guy in your DI session today using Unity in .Net. Probably not what you were expecting at EclipseCon, but since MS has canned Oslo M I've been retooling to the Java world for more robust modelling and textual DSL support. Anyway, it's an amazing project, thanks for sharing with us.

    ReplyDelete
  6. @Markus You can find the code at github https://github.com/svenefftinge/Guice-Modules-DSL

    ReplyDelete