Thursday, May 19, 2011

Writing Groovy DSL descriptors (DSLD) for Eclipse

Andrew Eisenberg  recently announced new great feature in Groovy Eclipse - the new DSL descriptors which brings you better code completion based on domain specific languages into your Groovy scripts and classes. If you are library developer or just enthusiastic user who wants better Eclipse coding go ahead and create your own DSL descriptor. It's surprisingly easy. In this article I want to share my experience from creating DSLD file for the Gaelyk.

Preparation
Before you start, be sure you have all items on the following check list
You should also explore the sources at the end of the article. DSL Descriptors for Groovy Eclipse is actually only source describing the DSLD and DSLD Examples could give you good overview what is possible to achieve with DSLDs.

When everything in place, you can open your Eclipse, create new Groovy project and add libraries you want the DSLD create for to the classpath (for testing and documentation purposes). Then save the DSLD files descriptor into the src folder and also create your new DSLD file in the src folder too.


Creating the DSLD file
The DSL descriptor is all about finding the right places using the pointcuts and contributing right method or properties to the scope found. If you successfully download the DSLD files descriptor you should have a code completion on place and can start coding.

If you are author of the framework or library it is easy to find out which contribution you want to create. If you aren't you should find the origins of contributions you want to cover in your DSLD not to forget anything. In the case of Gaelyk there are a few places where this happens: variables for views and templates are added using GaelykBindingEnhancerroutes DSL is defined in RoutesBaseScript and finally App Engine enhancements comes from GaelykCategory.

The DSLD official documentation is little bit messy so I've created following tables of all available pointcuts and contributions.

Pointcuts and Contributions


As soon as you know what do you want contribute and how should you do it the rest is all about copy pasting and rewriting (unless your DSL comes from a category so you can use the Category Explorer for scaffolding).

Shortcuts for Groovlets
Groovlets are scripts which resides in war/WEB-INF/groovy so we could pick them using sourceFolderOfCurrentType('war/WEB-INF/groovy') pointcut in combination with enclosingScript().  Everything else is just about declaring the right methods and properties.


App Engine Shortcuts
App Engine shortcuts are all defined inside GaelykCategory class. They apply on particular App Engine types (currentType(type)) inside Groovlets which are scripts residing in war/WEB-INF/groovy as written above. We define the pointcut once and then we can use it for each supported type. Since GaelykCategory  is category the Category Explorer was used for scaffolding.


Image Manipulation Language
The definition of image manipulation language is the most advanced one. We are looking for closure passed into the method call named transform on com.google.appengine.api.images.Image type. Everything else is just the same boring copy pasting again.


Tips, tricks and pitfalls 
Here are some ideas which I learnt when I created the Gaelyk DSDL.
  • The DSLD file won't compile and show in DSLD preferences screen if you import any non-standard class even it is on the project's classpath so you'd better prefer to use fully qualified strings to specify the types e.g. javax.servlet.http.HttpServletRequest.
  • Some of the pointcuts could be tricky, e.g. name of the script when name() pointcut is used is always without the suffix. To get name with the suffix included use fileName() one. You can also get only the suffix by using fileSuffix() pointcut.
  • I cannot find the easy way to debug the script but you can run your STS from console and watch the log. You can insert console prints in your DSLD files to explore the states of the variables.
  • Divide a editor viewport on half vertically and show a 'test' file/script/class bellow your DSLD file. If something goes wrong you get visual feedback immediately.
  • Try to be DRY. Combine pointcuts to the closures and reuse them.
  • Find the source of contributions and try to reuse them. For example you can scaffold the DSLD from Category class using the simple Category Explorer
  • Think twice when arguments are type of Map. Aren't they just named args? So you should use useNamedArgs = true and write all the desired named args in params (see e.g. add method on queues)
  • DSLDs are greate but there are still some features missing. For example I couldn't find how to specify what parameters are expected to be passed into the closure or how to specify type parameters for parametrized types e.g. maps.
 Splitted viewport for better visual feedback


Summary 
DSL descriptors takes coding Groovy in Eclipse one level higher. Where used to be underlined methods and properties you now get full code completion. Even more advanced DSL could be supported, just like Gaelyk's image manipulation language. So don't wait and write DSL descriptor for your favourite library! The Groovy Eclipse users will love you for it!

Sources
Written by Vladimir Oraný (@musketyr)

55 comments:

  1. Not a single word about what this is all about. The link in the beginning explained it for me afterwards - DSL code completion in Groovy Eclipse.

    PS: you have a typo in your summary.

    ReplyDelete
    Replies
    1. The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Project Centers in Chennai for CSE.

      Software management seeks for decision support to identify technologies like JavaScript that meet best the goals and characteristics of a software project or improvement programme. JavaScript Training in Chennai Accessible experiences and repositories that effectively guide that technology selection are still lacking.

      Aim of technology domain analysis is to describe the class of context situations (e.g., kinds of JavaScript software projects) in which a software engineering technology JavaScript Training in Chennai can be applied successfully

      Delete
  2. Thank you for valuable feedback, Lars. I've updated the first paragraph and fixed the typos.

    ReplyDelete
  3. It is possible to debug your dslds. It is very complicated, though and requires using a runtime workspace (generally used for Eclipse plugin development). In the next few days, I'll try to get a blog post together on this.

    ReplyDelete
  4. Thanks for notice, Andrew. Using PDE didn't come on my mind but it's definitely the way it could be done. Looking forward on your blog post! Please, tweet me as soon as it's done.

    ReplyDelete
  5. Nice article! Above all the table with contributions and pointcuts should definitely find its way to the official documentation.

    ReplyDelete
  6. Thanks Matthias! I've written to Andrew if it is possible. Meanwhile I've published the table to be browsed from GDocs directly here

    http://link.appsatori.eu/dsld-table

    ReplyDelete
  7. "The DSLD file won't compile and show in DSLD preferences screen if you import any non-standard class even it is on the project's classpath so you'd better prefer to use fully qualified strings to specify the types"

    Don't you know why this happens:
    annotatedBy("groovy.lang.Delegate") - works
    annotatedBy("my.custom.MyAnnotation") - doesn't work

    ReplyDelete
  8. It might proved to be some sort of great idea to follow above mentioned techniques and tips to show deliberately good results for the future purpose. Visit college paper for best papers.

    ReplyDelete
  9. I am extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a nice blog like this one nowadays. Find out more childrens party ideas for best Ideas.

    ReplyDelete
  10. Creating a successful resume is no easy feat. It takes a lot of time and effort, not to mention you might have to go through several rewrites before it has been perfected. The goal of a resume is to showcase your talents and land you an interview. rewording sentences generator

    ReplyDelete
  11. name Attribute for method or property contributions seems to be mandatory. Is there something like a wild card?
    e.g.:
    images {
    nameOfImage1 "urlToImage1"
    nameOfImage2 "urlToIamge2"
    }
    Now I want the IDE to know that nameOfImage1 and nameOfImage2 are of type Image.
    Is there a way to do this?

    btw: I want it that way, cause it looks more intuitive than image(name=...,url=)

    ReplyDelete
  12. Wow what a Great Information about World Day its exceptionally pleasant educational post. a debt of gratitude is in order for the post.

    Data Science Course

    ReplyDelete
  13. It is the intent to provide valuable information and best practices, including an understanding of the regulatory process.

    Data Science Training

    ReplyDelete
  14. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    Data Science Training Institute in Bangalore

    ReplyDelete
  15. I am impressed by the information that you have on this blog. It shows how well you understand this subject.
    Best Data Science Courses in Bangalore

    ReplyDelete
  16. Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing.
    Data Science Course in Bangalore

    ReplyDelete
  17. It's late finding this act. At least, it's a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act.
    Data Science Training in Bangalore

    ReplyDelete
  18. really this is awesome post. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up.Learn Data Science Course in Hyderabad

    ReplyDelete
  19. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.Learn best Business Analytics Course in Hyderabad

    ReplyDelete
  20. I feel really happy to have seen your post and look forward to so many more interesting post reading here. Thanks once more for all the details.Learn Best Data Science Training in Hyderabad

    ReplyDelete
  21. Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It's really very nice and Useful post.Thanks..

    Data Science Courses

    ReplyDelete
  22. The web site is lovingly serviced and saved as much as date. So it should be, thanks for sharing this with us.

    Data Science Certification

    ReplyDelete
  23. Freelance maintenance technicians also benefit from establishing relationships with multiple clients. Working as a freelancer, you’ll gain employment experience with a variety of businesses, boosting your overall skill set and providing you with more work opportunities in the future.

    maintenance technician

    ReplyDelete
  24. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

    Security Guard License
    Ontario Security License
    Security License Ontario
    Security License

    Thank you..

    ReplyDelete
  25. It's very educational and well-written content for a change. It's good to see that some people still understand how to write a great article!

    Business Analytics Course in Bangalore

    ReplyDelete
  26. Excellent exchange of information ... I am very happy to read this article ... thank you for giving us information. Fantastic. I appreciate this post.

    Data Analytics Course in Bangalore

    ReplyDelete
  27. Awesome article with excellent information found very useful waiting for next blog thank you.
    typeerror nonetype object is not subscriptable

    ReplyDelete
  28. Fantastic blog extremely good well enjoyed with the incredible informative content which surely activates the learners to gain the enough knowledge. Which in turn makes the readers to explore themselves and involve deeply in to the subject. Wish you to dispatch the similar content successively in future as well.

    artificial intelligence training in bhilai

    ReplyDelete
  29. Impressive blog to be honest definitely this post will inspire many more upcoming aspirants. Eventually, this makes the participants to experience and innovate themselves through knowledge wise by visiting this kind of a blog. Once again excellent job keep inspiring with your cool stuff.

    Data Science certification in Bhilai

    ReplyDelete
  30. Extraordinary blog went amazed with the content that they have developed in a very descriptive manner. This type of content surely ensures the participants to explore themselves. Hope you deliver the same near the future as well. Gratitude to the blogger for the efforts.

    Digital Marketing training in Bhilai

    ReplyDelete
  31. Tremendous blog quite easy to grasp the subject since the content is very simple to understand. Obviously, this helps the participants to engage themselves in to the subject without much difficulty. Hope you further educate the readers in the same manner and keep sharing the content as always you do.

    Data Science Course in Raipur

    ReplyDelete
  32. Stupendous blog huge applause to the blogger and hoping you to come up with such an extraordinary content in future. Surely, this post will inspire many aspirants who are very keen in gaining the knowledge. Expecting many more contents with lot more curiosity further.

    Digital Marketing Course

    ReplyDelete
  33. Fantastic blog extremely good well enjoyed with the incredible informative content which surely activates the learners to gain the enough knowledge. Which in turn makes the readers to explore themselves and involve deeply in to the subject. Wish you to dispatch the similar content successively in future as well.

    artificial intelligence course in raipur

    ReplyDelete
  34. Fantastic blog with top quality information, enjoyed reading it and found very valuable thanks for sharing.
    Data Analytics Course Online

    ReplyDelete
  35. Very informative article with valuable information found resourceful looking forward for next blog thanks you.
    Ethical Hacking Course in Bangalore

    ReplyDelete
  36. I will very much appreciate the writer's choice for choosing this excellent article suitable for my topic. Here is a detailed description of the topic of the article that helped me the most. PMP Training in Hyderabad

    ReplyDelete
  37. Really nice and intriguing post. I was trying to find this sort of advice and appreciated reading this one. Keep posting. Thank you for sharing.
    Data Science Training Institute in Bangalore

    ReplyDelete

  38. Nice to be seeing your site once again, it's been weeks for me. This article which ive been waited for so long. I need this guide to complete my mission inside the school, and it's same issue together along with your essay. Thanks, pleasant share.

    Data Science Course In Bangalore With Placement

    ReplyDelete
  39. Fantastic informative article! I'm basically getting willing to over this advice, is quite beneficial my own friend.

    Cyber Security Course In Bangalore

    ReplyDelete
  40. I am more curious to take an interest in some of them. I hope you will provide more information on these topics in your next articles.

    Business Analytics Course in Bangalore

    ReplyDelete
  41. I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.

    Data Analytics Course in Bangalore

    ReplyDelete
  42. I will very much appreciate the writer's choice for choosing this excellent article suitable for my topic. Here is a detailed description of the topic of the article that helped me the most.
    unindent does not match any outer indentation level

    ReplyDelete
  43. I'm glad I found this blog! Occasionally, students want to know the keys to writing productive literary essays. Your first-class knowledge of this great job can become a suitable foundation for these people. Good
    unindent does not match any outer indentation level python

    ReplyDelete
  44. I have to search sites with relevant information ,This is a
    wonderful blog,These type of blog keeps the users interest in
    the website, i am impressed. thank you.
    Data Science Course in Bangalore

    ReplyDelete
  45. I have to search sites with relevant information ,This is a
    wonderful blog,These type of blog keeps the users interest in
    the website, i am impressed. thank you.
    Data Science Training in Bangalore

    ReplyDelete
  46. Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people. I did some research on the subject and found that almost everyone will agree with your blog.
    Cyber Security Course in Bangalore

    ReplyDelete
  47. I have to search sites with relevant information ,This is a
    wonderful blog,These type of blog keeps the users interest in
    the website, i am impressed. thank you.
    pmp training in bangalore

    ReplyDelete
  48. Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
    Cyber Security Training in Bangalore

    ReplyDelete