DSLDs - how to delegate to a generics argument?

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

DSLDs - how to delegate to a generics argument?

me2stk
Hello,

I did a tool that generates DSLDs and GDSLs based on annotations in the Java docs, and a specific convention of the annotated methods. Next I want to go a little bit further and do something more complicated with the DSLD language.


I have the following scenario:

class MessageAdapter <T extends AbstractMessage> {
    @Delegate
    T delegate;
}

class MyMessage1 extends AbstractMessage{
      public MyMessage2 createMsg2(){
      ...
   }

class MyMessage2 extends AbstractMessage{
      public MyMessage3 createMsg3(){
      ...
   }
...
}


My goal is to write DSL descriptor for MessageAdapter class, that provides auto-completion based on the given generic class argument. The DSLD should also remove the "create" prefix of the "createMsg2" method.

def m = new MessageAdapter<MyMessage1>()
m.Msg2()

Is this possible at all and how whould a descriptor look like? If such extension is somehow written, will the returned class "MyMessage2 " of "Msg2" DSL method be used by the auto-completion machinery?


I tried to somehow change the DSLD for @Delegates, but for now I am having trouble to debug the script I write.
public class MessageAdapter  {
    @Delegate
    MyMessage1 delegate;
}

Generally, how do you debug the DSLDs?

Thanks in advance!

Best Regards,
Mitko
Reply | Threaded
Open this post in threaded view
|

Re: DSLDs - how to delegate to a generics argument?

Andy Clement
Hi Mitko,

Just to say, Andrew Eisenberg, who is responsible for the DSLD support
is out until Thursday.  You might get a reply before that but you'll
hear something by the end of the week at the latest.

cheers
Andy

On 6 June 2011 05:35, me2stk <[hidden email]> wrote:

> Hello,
>
> I did a tool that generates DSLDs and GDSLs based on annotations in the Java
> docs, and a specific convention of the annotated methods. Next I want to go
> a little bit further and do something more complicated with the DSLD
> language.
>
>
> I have the following scenario:
>
> class MessageAdapter <T extends AbstractMessage> {
>     @Delegate
>     T delegate;
> }
>
> class MyMessage1 extends AbstractMessage{
>       public MyMessage2 createMsg2(){
>       ...
>    }
>
> class MyMessage2 extends AbstractMessage{
>       public MyMessage3 createMsg3(){
>       ...
>    }
> ...
> }
>
>
> My goal is to write DSL descriptor for MessageAdapter class, that provides
> auto-completion based on the given generic class argument. The DSLD should
> also remove the "create" prefix of the "createMsg2" method.
>
> def m = new MessageAdapter<MyMessage1>()
> m.Msg2()
>
> Is this possible at all and how whould a descriptor look like? If such
> extension is somehow written, will the returned class "MyMessage2 " of
> "Msg2" DSL method be used by the auto-completion machinery?
>
>
> I tried to somehow change the DSLD for @Delegates, but for now I am having
> trouble to debug the script I write.
> public class MessageAdapter  {
>     @Delegate
>     MyMessage1 delegate;
> }
>
> Generally, how do you debug the DSLDs?
>
> Thanks in advance!
>
> Best Regards,
> Mitko
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: DSLDs - how to delegate to a generics argument?

me2stk
Hi Andy,

Thanks for the info.

Regards,
Mitko


On Tue, Jun 7, 2011 at 12:59 AM, Andy Clement <[hidden email]> wrote:
Hi Mitko,

Just to say, Andrew Eisenberg, who is responsible for the DSLD support
is out until Thursday.  You might get a reply before that but you'll
hear something by the end of the week at the latest.

cheers
Andy

On 6 June 2011 05:35, me2stk <[hidden email]> wrote:
> Hello,
>
> I did a tool that generates DSLDs and GDSLs based on annotations in the Java
> docs, and a specific convention of the annotated methods. Next I want to go
> a little bit further and do something more complicated with the DSLD
> language.
>
>
> I have the following scenario:
>
> class MessageAdapter <T extends AbstractMessage> {
>     @Delegate
>     T delegate;
> }
>
> class MyMessage1 extends AbstractMessage{
>       public MyMessage2 createMsg2(){
>       ...
>    }
>
> class MyMessage2 extends AbstractMessage{
>       public MyMessage3 createMsg3(){
>       ...
>    }
> ...
> }
>
>
> My goal is to write DSL descriptor for MessageAdapter class, that provides
> auto-completion based on the given generic class argument. The DSLD should
> also remove the "create" prefix of the "createMsg2" method.
>
> def m = new MessageAdapter<MyMessage1>()
> m.Msg2()
>
> Is this possible at all and how whould a descriptor look like? If such
> extension is somehow written, will the returned class "MyMessage2 " of
> "Msg2" DSL method be used by the auto-completion machinery?
>
>
> I tried to somehow change the DSLD for @Delegates, but for now I am having
> trouble to debug the script I write.
> public class MessageAdapter  {
>     @Delegate
>     MyMessage1 delegate;
> }
>
> Generally, how do you debug the DSLDs?
>
> Thanks in advance!
>
> Best Regards,
> Mitko
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: DSLDs - how to delegate to a generics argument?

Andrew Eisenberg
In reply to this post by me2stk
> I did a tool that generates DSLDs and GDSLs based on annotations in the Java
> docs, and a specific convention of the annotated methods. Next I want to go
> a little bit further and do something more complicated with the DSLD
> language.

That sounds pretty cool.  Is this available somewhere to try out?


> I have the following scenario:
>
> class MessageAdapter <T extends AbstractMessage> {
>     @Delegate
>     T delegate;
> }
>
> class MyMessage1 extends AbstractMessage{
>       public MyMessage2 createMsg2(){
>       ...
>    }
>
> class MyMessage2 extends AbstractMessage{
>       public MyMessage3 createMsg3(){
>       ...
>    }
> ...
> }
>
>
> My goal is to write DSL descriptor for MessageAdapter class, that provides
> auto-completion based on the given generic class argument. The DSLD should
> also remove the "create" prefix of the "createMsg2" method.
>
> def m = new MessageAdapter<MyMessage1>()
> m.Msg2()
>
> Is this possible at all and how whould a descriptor look like? If such
> extension is somehow written, will the returned class "MyMessage2 " of
> "Msg2" DSL method be used by the auto-completion machinery?

This should be possible, but I have not actually tried it out.  To do
it, you would need to dig a bit deeper into the Groovy AST API and see
what the bound type parameters are to the declaring type.  You would
need to look into the classes org.codehaus.groovy.ast.ClassNode and
org.codehaus.groovy.ast.GenericsType.

You can probably do something like this:

currentType( "com.foo.MessageAdapter").accept {
  def gen = currentType?.genericsTypes
  if (gen && gen.?length == 1) {
    def gt = gen[0]
    method name:'msg2', type:gt.type
  }
}

I haven't tried this out, but it should work.  Let me know if you are
successful.  I should probably think of a cleaner way of accessing
type parameters.

>
>
> I tried to somehow change the DSLD for @Delegates, but for now I am having
> trouble to debug the script I write.
> public class MessageAdapter  {
>     @Delegate
>     MyMessage1 delegate;
> }
>
> Generally, how do you debug the DSLDs?

It is not an easy thing to fire up a debugger to step through your
DSLDs, and it requires using a runtime workspace to run a second
instance of Eclipse that stores the DSLD that you are debugging.

Until I can get some solid documentation together for this, I'd
recommend using 'print' and 'println' in your scripts.  This will
print things to the console that you launched Eclipse from.  You will
notice that every time you edit and save the file, print statements
outside of contribution blocks will be reached and every time a file
is evaluated, print statements inside of contribution blocks will be
reached.

>
> Thanks in advance!
>
> Best Regards,
> Mitko
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: DSLDs - how to delegate to a generics argument?

me2stk
Hello Andrew,

Thank you for the answer.
Ok, I'll try out what you suggested and let you know what the result is.

Yes you (and everybody else) can try this tool.
Actually its a maven plugin available at http://repo.openehealth.org/maven2/releases/orpluging/openehealth/ipf/labs/maven/maven-dsldoc-plugin/ . Version 1.3 has the DSLD generation.

At compile phase the plugin scans classes with *Extension.groovy (configurable). It tries to parse the javadoc for those classes. If there is a  @DSL javadoc tag, the methods of the class are aditionally parsed and DSLDs, GDSLs and HTML fragements are generated for those methods based on a convention. The DSL descriptors are then packaged in their module's jar.
At site:site phase, there is also a reporting mojo, that aggregates the already generated HTML fragments to a .html page. So if you follow the convetion your DSL extensions will be documented.

Currently it is somehow awkward to follow the convention required by the plugin. For every Groovy DSL extension there must be a corresponding method in an *Extension.groovy class for which the delegate is the first parameter of the method. The other parameters are the groovy extension's parameters. This is what must be improved.
An idea for further development of the plugin is that the plugin inspects the AST three of the extension itself - not the redundant convention file. This will eliminate the need of convention files. So contributions and ideas in this direction would be appreciated.

Here is an example of the DLS extensions
http://goo.gl/Vi1K4

and their corresponding convention file
http://goo.gl/aZJB5

Here is an example of a generated HTML on mvn site:site:
http://repo.openehealth.org/sites/ipf/reports/ipf-2.2.0/dslIndex.html

Here is example how to use the plugin:
http://goo.gl/4vjML

Regards,
Mitko



On Wed, Jun 8, 2011 at 2:44 AM, Andrew Eisenberg <[hidden email]> wrote:
> I did a tool that generates DSLDs and GDSLs based on annotations in the Java
> docs, and a specific convention of the annotated methods. Next I want to go
> a little bit further and do something more complicated with the DSLD
> language.

That sounds pretty cool.  Is this available somewhere to try out?


> I have the following scenario:
>
> class MessageAdapter <T extends AbstractMessage> {
>     @Delegate
>     T delegate;
> }
>
> class MyMessage1 extends AbstractMessage{
>       public MyMessage2 createMsg2(){
>       ...
>    }
>
> class MyMessage2 extends AbstractMessage{
>       public MyMessage3 createMsg3(){
>       ...
>    }
> ...
> }
>
>
> My goal is to write DSL descriptor for MessageAdapter class, that provides
> auto-completion based on the given generic class argument. The DSLD should
> also remove the "create" prefix of the "createMsg2" method.
>
> def m = new MessageAdapter<MyMessage1>()
> m.Msg2()
>
> Is this possible at all and how whould a descriptor look like? If such
> extension is somehow written, will the returned class "MyMessage2 " of
> "Msg2" DSL method be used by the auto-completion machinery?

This should be possible, but I have not actually tried it out.  To do
it, you would need to dig a bit deeper into the Groovy AST API and see
what the bound type parameters are to the declaring type.  You would
need to look into the classes org.codehaus.groovy.ast.ClassNode and
org.codehaus.groovy.ast.GenericsType.

You can probably do something like this:

currentType( "com.foo.MessageAdapter").accept {
 def gen = currentType?.genericsTypes
 if (gen && gen.?length == 1) {
   def gt = gen[0]
   method name:'msg2', type:gt.type
 }
}

I haven't tried this out, but it should work.  Let me know if you are
successful.  I should probably think of a cleaner way of accessing
type parameters.

>
>
> I tried to somehow change the DSLD for @Delegates, but for now I am having
> trouble to debug the script I write.
> public class MessageAdapter  {
>     @Delegate
>     MyMessage1 delegate;
> }
>
> Generally, how do you debug the DSLDs?

It is not an easy thing to fire up a debugger to step through your
DSLDs, and it requires using a runtime workspace to run a second
instance of Eclipse that stores the DSLD that you are debugging.

Until I can get some solid documentation together for this, I'd
recommend using 'print' and 'println' in your scripts.  This will
print things to the console that you launched Eclipse from.  You will
notice that every time you edit and save the file, print statements
outside of contribution blocks will be reached and every time a file
is evaluated, print statements inside of contribution blocks will be
reached.

>
> Thanks in advance!
>
> Best Regards,
> Mitko
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email