DSLD Support for Geb

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

DSLD Support for Geb

Christian Baranowski
Hi,

I would like develop some basic DSL support for the Geb DSL in Eclipse. For this I need some Help. When I have the following page class:

class SomePage extends Page {
  
  static content = {
     button { $('button') }
     form { module MyFormModule }
  }
 

The DSLD script should add to this class a method with the name button and a method with the name form and the return type of the form method should be the type of the first module method argument in the closure. In the demo case the return type of the form method should be MyFormModule. Can some one give me a hint who to write such a DSLD script?

thank you
Christian
Reply | Threaded
Open this post in threaded view
|

Re: DSLD Support for Geb

Andrew Eisenberg
Hi,

Adding the 'form' method is straightforward, but ensuring that the return type is correct is not.  The reason is that the only way to determine the return type is by doing a parse of the 'content' closure.  So, this is not the kind of DSL that DSLD is really meant to support.

To provide proper inferencing of the form method's return type, there are two suggestions I can make.  Neither one is particularly easy:

1. create a proper Eclipse plugin that can parse a Geb file and cache the information that you require. This is what we do for some cases in grails-ide. And if you want to go this way, then I can show you some examples.
2. change Geb so that it is easier for tooling to infer this kind of information.  Eg- instead of calling 'form' in the content closure, create some kind of @Form annotation, like this

@Form(module=MyFormModule)
@Button( ... )
class SomePage extends Page { }

Maybe this is less "groovy", but this would be simpler for tooling to use.

Anyway, to simply add the form method, you can do something like this:

contribute(currentType(subType('geb.Page')) {
  method name:'form', params: [...], type: 'geb.Module'
}

or something like that.  Hope this helps.


On Wed, Sep 18, 2013 at 3:06 AM, Christian Baranowski <[hidden email]> wrote:
Hi,

I would like develop some basic DSL support for the Geb DSL in Eclipse. For this I need some Help. When I have the following page class:

class SomePage extends Page {
  
  static content = {
     button { $('button') }
     form { module MyFormModule }
  }
 

The DSLD script should add to this class a method with the name button and a method with the name form and the return type of the form method should be the type of the first module method argument in the closure. In the demo case the return type of the form method should be MyFormModule. Can some one give me a hint who to write such a DSLD script?

thank you
Christian