groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dinko Srko─Ź <dinko.sr...@gmail.com>
Subject Re: About the syntax of groovy
Date Sat, 31 Oct 2015 01:50:58 GMT
On 30 October 2015 at 17:53, daniel_sun <realbluesun@hotmail.com> wrote:
> Hi all,
>
>      Could you tell me the following gradle code comply with the syntax of
> groovy?  The 'task' can be a method, what about 'taskA' and '<<'?  Thanks in
> advance.

It complies, otherwise you would get a compile error, instead of a
runtime error. `task` is indeed a method. `taskA` is a property, as
the exception MissingPropertyException indicates. `<<` is again a
method, called leftShift, which is invoked on whatever property
`taskA` returns, and has a Closure for its argument.

At least one thing needs to be done for the code to work - `taskA`
property must exist. You could either implement that particular
property, or use e.g. `propertyMissing`. The property needs to return
an object that implements the `leftShift` method. It could be, for
example, a String, a List, or a Closure.

Depending on what you chose for `taskA` to return, the `task` method
would work as-is, or would need to be adjusted.

Hope this helps,
Dinko

>
> task taskA << {
>     println "i'm task A"
> }
>
> ----------- my experimental code, but failed with exceptions
> -----------------
> def task(t) {
>     t()
> }
>
> task taskA << {
>     println "i'm task A"
> }
> =================
> groovy.lang.MissingPropertyException: No such property: taskA for class:
> ConsoleScript8
>
>         at ConsoleScript8.run(ConsoleScript8:5)
> ----------------------------
>
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/About-the-syntax-of-groovy-tp5729026.html
> Sent from the Groovy Users mailing list archive at Nabble.com.

Mime
View raw message