Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
None
-
None
-
None
Description
Let's say you add a source to a CompilationUnit (unit):
Test.java
class Test { int plusOne(int value) { int one = 1; return value + one; } }
and call unit.compile() and then run:
Sample code using groovyc
unit.iterator().forEachRemaining(sourceUnit ->
sourceUnit.getAST().getClasses().forEach(clazz ->
clazz.getAllDeclaredMethods().forEach(method ->
System.out.print(method.getVariableScope()
.getDeclaredVariables().values())
)
)
);
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?