[ https://issues.apache.org/jira/browse/GROOVY-8275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16115509#comment-16115509 ]
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|https://github.com/apache/groovy/commit/a0c8d2418286d46182ee647d5f3c6d48212a508f#diff-43aa4979f66a79c1de9464bf9059cf4eR97]. 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: {code} @Newify def x = Integer.new(1) def y = Integer.new(2) def z = Integer.new(3) assert x + y + z == 6 {code} It does lead to unexpected results when used in a Class. {code} class Foo { int bar() { def x = Integer.new(1) } int baz() { @Newify def y = Integer.new(2) } } assert new Foo().bar() == 1 assert new Foo().baz() == 2 {code} > Newify transform docs missing support for local variable declaration > -------------------------------------------------------------------- > > Key: GROOVY-8275 > URL: https://issues.apache.org/jira/browse/GROOVY-8275 > 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 http://groovy-lang.org/metaprogramming.html#xform-Newify > Ruby-style section could be more clear IMO if the {{([Tree,Leaf])}} were > removed since it only enables the Python-style expressions. > 2) Javadoc and online docs do not mention that {{@Newify}} can be applied to > a local variable declaration, like: {{@Newify def o = Object.new()}}. > 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 = Object.new(); ... o = > Object.new() ...}}. 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 (v6.4.14#64029)