GDSL Awesomeness – Introduction to GDSL in IntelliJ Idea

25 / Sep / 2012 by Kushal Likhi 0 comments

One of the disadvantage of using meta-programming and DSL is that we don’t get auto-completes in Our IDE.

Hence IntelliJ provided us with an awesome and intelligent toolkit to handle dynamic properties and methods when writing code in groovy.

In IntelliJ IDEA we can write GDSL Files in order to give us the auto-completes(code Completion) on the injected Methods/properties and closures.

Advantages of GDSL files

  1. We can push these files with the code and all the developers in the team will start getting auto-completes for the dynamic code.
  2. Simple to write and understand as they use the groovy DSL format.
  3. These files can be packaged in a jar and all projects using that jar will start getting auto-completes and syntax hinting for the dynamic code.

Illustration

Image illustrating the auto-completes for the injected code. You can see that there is no property “log” defined in the project, but IDEA is showing syntax-hint for this property.

 

Where to write GDSL Scripts

We can create a file with an extension “.gdsl” anywhere in the classpath.
For an example go to any package in your project src, and right click on it from within the IDE and select new>Groovy Script.
Now a dialog will appear and then select “GroovyDSL Script” in the “kind” parameter.

Now you have the script file and you can start coding GDSL in here.

 

Read Further in the “GDSL AWESOMENESS” Series

  1. GDSL Awesomeness – Introduction to GDSL in IntelliJ Idea
  2. GDSL Awesomeness – Understanding Context And Contributors in Detail
  3. GDSL Awesomeness – Defining dynamic property in a class
  4. GDSL Awesomeness – Defining dynamic method in a class
  5. GDSL Awesomeness – Adding Hinting for missingMethod implementation
  6. GDSL Awesomeness – Setting a global context
  7. GDSL Awesomeness – Delegating Closure Calls
  8. GDSL Awesomeness – Defining methods in a closure passed to method of particular name
  9. GDSL Awesomeness – Defining Properties in a closure passed to method of particular name
  10. GDSL Awesomeness – Contributing to classes which match a path/name pattern
  11. GDSL Awesomeness – contributing methods with current class return types or parameters
  12. GDSL Awesomeness – AutoComplete Script for grails-Mail-Plugin “sendMail” closure
  13. GDSL Awesomeness – Getting Code of a method or Field in GDSL Script
  14. GDSL Awesomeness – Advanced Example showing domain properties implementation

 

 

Hope It Helped.

FOUND THIS USEFUL? SHARE IT

Leave a comment -