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) {
// implementation of dynamic method synthesis, it will intercept methods in signature increment<propertyName>(Integer step)
}
}
[/java]
Now GDSL Script for the above class will be like:
[java]
def ctx = context(ctype: "my.package.Pixel")
contributor (ctx) {
// Add generic methods
classType?.fields?.each {
method(name: "increment${it.name}", params: [step: Integer], type: ‘int’)
}
}
[/java]
The above script will give autoCompletes for these dynamic methods.
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.
Kushal Likhi