groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Wagenleitner (JIRA)" <>
Subject [jira] [Commented] (GROOVY-8275) Newify transform docs missing support for local variable declaration
Date Sat, 05 Aug 2017 20:50:02 GMT


John Wagenleitner commented on GROOVY-8275:

For #2 and #3, looks like adding local variable support was part of GROOVY-4876 as a way to
[enable usage in scripts|].
 Based on GROOVY-4876 I'm not sure if this is by design; that the presence of the annotation
on a local variable turns it on for all others in the script.  For example:

def x =
def y =
def z =

assert x + y + z == 6

It does lead to unexpected results when used in a Class.

class Foo {
    int bar() {
        def x =
    int baz() {
        def y =
assert new Foo().bar() == 1
assert new Foo().baz() == 2

> Newify transform docs missing support for local variable declaration
> --------------------------------------------------------------------
>                 Key: GROOVY-8275
>                 URL:
>             Project: Groovy
>          Issue Type: Documentation
>          Components: xforms
>            Reporter: Eric Milles
>            Priority: Minor
> Javadocs and online documentation for the Newify AST transform is not quite clear in
a couple instances.
> 1) Online docs Ruby-style section
could be more clear IMO if the {{([Tree,Leaf])}} were removed since it only enables the Python-style
> 2) Javadoc and online docs do not mention that {{@Newify}} can be applied to a local
variable declaration, like: {{@Newify def o =}}.
> 3) The scoping of the transform is pretty clear for the class, method and field/property
cases.  However for the local variable case, it appears that the transform applies throughout
the containing scope of the local variable.  That is, I can use the extra constructors anywhere
in the block to re-initialize the variable.  {{@Newify def o =; ... o =
...}}.  Is this the intended behavior?  My intuition was that the initializer expression was
the only place the transform applied, like in the case of a field.

This message was sent by Atlassian JIRA

View raw message