Kushal Likhi

Grails

GDSL Awesomeness – Defining dynamic method in a class

We can define dynamic methods in a class as follows:   Suppose we have injected a method name .clone([boolean] clearTime) in Date which clones the date object and returns the cloned one. This method takes an boolean argument argument too. We can do it as follows: (See inline comments for description) [java] //First we...

24-Sep-2012

Grails

GDSL Awesomeness – Understanding Context And Contributors in Detail

GDSL Scripts are based on two main concepts: contexts and contributors. Hence we will discuss about these in detail here.   In GroovyDSL context is an entity which is supposed to give an answer to the question "Where?" this behavior will be available. Contexts are first-order citizens in GroovyDSL, so they may be stored in local...

24-Sep-2012

Grails

GDSL Awesomeness – Adding Hinting for missingMethod implementation

hi,   Suppose we have used method missing in our code and we want to give syntax-hinting for these methods then we can go as follows:   Suppose we have this class which implements method missing: [java] class Pixel { def Top def Left def Color def methodMissing(String name, args) { //...

24-Sep-2012

Grails

GDSL Awesomeness – Delegating Closure Calls

hi,   Very often we use delegates in our closure calls. It would be great if we could get code-hinting in the closure via the delegates.   Now let us take a very simple scenario, where we made a method "with" which delegates the delegate objet to closure and runs it. [java] class Delegator { static def...

24-Sep-2012

Grails

GDSL Awesomeness – Defining methods in a closure passed to method of particular name

hi,   Sometimes we need to add specific methods in the closures which are passed to methods with a particular name. This can be simply done as follows   Suppose we need to add the method named "setHeaders(Map headers)" in all closures passed to method with name "withREST" [java] //Get the context for all closures def...

24-Sep-2012

Grails

GDSL Awesomeness – Defining Properties in a closure passed to method of particular name

hi,   Sometimes we need to add specific properties in the closures which are passed to methods with a particular name. This can be simply done as follows   Suppose we need to add the property named requestMethod of type String in all closures passed to method with name "withREST" [java] //Get the context for all...

24-Sep-2012

Grails

GDSL Awesomeness – Contributing to classes which match a path/name pattern

hi,   If we want to contribute to classes which matches a particular path/name pattern, then we can use PSI Class patterns to do it.   the code is as follows: [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns //get the context of all files, and enable path matching....

24-Sep-2012

Grails

GDSL Awesomeness – contributing methods with current class return types or parameters

Hi,   Sometimes we need to contribute dynamically using current target class type.   Lets take the example of .get() and .list() methods of Grails domain class. The signature of each method is as follows: public <DomainClassType> get(Long id) , Example: DemoClass.get(1) will return an object of "DemoClass" ...

24-Sep-2012

Grails

GDSL Awesomeness – AutoComplete Script for grails-Mail-Plugin “sendMail” closure

Hi,   I have been using the Grails mail plugin for a while now, this plugin injects a method named "sendMail" to all controllers and services.   Our aim will be to provide auto-completes for this method and the closure inside.   The GDSL Script is as follows: [java] import com.intellij.patterns.PsiJavaPatterns ...

24-Sep-2012

Grails

GDSL Awesomeness – Getting Code of a method or Field in GDSL Script

Hi,   Here i will illustrate how you can get the code of a method within GDSL Script:   The script is as follows: [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns def mongoContext = context( ctype:...

24-Sep-2012

Grails

GDSL Awesomeness – Advanced Example showing domain properties implementation

Hi,   Here is an example which uses a lot of gdsl concepts. This example tries to simulate injecting properties to Domains.   The Example is as follows: (The code is self explanatory and can be used as a reference) [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns ...

24-Sep-2012

Grails

Closure Caching For Increased Performance (.memoize())

Well This is something awesome and can increase the performance of the project when used wisely. using the groovy .memoize() we can ask closures to perform kind of caching. This can boost up the performance of the system.   _ Note: This feature is available in groovy 1.8+ Well Let me Explain this Using Examples Now suppose i...

29-Dec-2011