[ https://issues.apache.org/jira/browse/GROOVY-7903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15431669#comment-15431669 ]
Natacha Gabbamonte edited comment on GROOVY-7903 at 8/22/16 9:44 PM: --------------------------------------------------------------------- Locally declared variables of methods are accessible through: {code} if (method.getCode() instanceof BlockStatement) { System.out.print(((BlockStatement) method.getCode()).getVariableScope().getDeclaredVariables().values()) } {code} was (Author: natgabb): Locally declared variables of methods are accessible through: {code} if (method.getCode() instanceof BlockStatement) { System.out.print(((BlockStatement) method.getCode()).getVariableScope() .getDeclaredVariables().values()) } {code} > 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)