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
- We can push these files with the code and all the developers in the team will start getting auto-completes for the dynamic code.
- Simple to write and understand as they use the groovy DSL format.
- 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.
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
- GDSL Awesomeness – Introduction to GDSL in IntelliJ Idea
- GDSL Awesomeness – Understanding Context And Contributors in Detail
- GDSL Awesomeness – Defining dynamic property in a class
- GDSL Awesomeness – Defining dynamic method in a class
- GDSL Awesomeness – Adding Hinting for missingMethod implementation
- GDSL Awesomeness – Setting a global context
- GDSL Awesomeness – Delegating Closure Calls
- GDSL Awesomeness – Defining methods in a closure passed to method of particular name
- GDSL Awesomeness – Defining Properties in a closure passed to method of particular name
- GDSL Awesomeness – Contributing to classes which match a path/name pattern
- GDSL Awesomeness – contributing methods with current class return types or parameters
- GDSL Awesomeness – AutoComplete Script for grails-Mail-Plugin “sendMail” closure
- GDSL Awesomeness – Getting Code of a method or Field in GDSL Script
- GDSL Awesomeness – Advanced Example showing domain properties implementation
Hope It Helped.