[
https://issues.apache.org/jira/browse/GROOVY-7903?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King reopened GROOVY-7903:
-------------------------------
> 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)