You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Natacha Gabbamonte (JIRA)" <ji...@apache.org> on 2016/08/22 21:45:20 UTC

[jira] [Closed] (GROOVY-7903) Locally declared variables in methods are not accessible from the VariableScope

     [ https://issues.apache.org/jira/browse/GROOVY-7903?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Natacha Gabbamonte closed GROOVY-7903.
--------------------------------------
    Resolution: Fixed

> Locally declared variables in methods are not accessible from the VariableScope
> -------------------------------------------------------------------------------
>
>                 Key: GROOVY-7903
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7903
>             Project: Groovy
>          Issue Type: Improvement
>          Components: ast builder
>            Reporter: Natacha Gabbamonte
>
> Let's say you add a source to a CompilationUnit ({{unit}}):
> {code:title=Test.java|borderStyle=solid}
> class Test {
>      int plusOne(int value) {
>           int one = 1;
>           return value + one;
>      }
> }
> {code}
> and call {{unit.compile()}} and then run:
> {code:title=Sample code using groovyc}
> unit.iterator().forEachRemaining(sourceUnit ->
>     sourceUnit.getAST().getClasses().forEach(clazz ->
>         clazz.getAllDeclaredMethods().forEach(method -> 
>             System.out.print(method.getVariableScope()
>                 .getDeclaredVariables().values())  
>         )
>     )
> );
> {code}
> The only declared variable you get for method {{plusOne}} is the parameter {{value}}. The local variable {{one}} is not accessible.
> Is there another way of accessing these locally declared variables?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)