Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.5
-
None
-
Any
Description
During parsing process, after the AST has been produced and variable scopes have been traversed, the various nodes of the AST contain VariableScope objects that describe variable usage and declaration within particular nodesets of the AST. In previous versions, such VariableScope objects provided access to two maps of variables referenced within that variable scope: one for referenced Class variables and one for referenced Local variables.
In 1.5, access to these maps was restricted to querying/adding or removing specific variables from each map (through get/put or remove methods). This eliminated the ability to iterate each map.
Workaround:
Using reflection on VariableScope.class, get a reference to the private "referencedClassVariables" Field from declared Fields. Make the Field accessible (call setAccessible(true)). Get the underlying object casting it to Map<String, DynamicVariable>.
Proposed Solution(s):
One solution would be to expose public iterator methods for each map. Another would be simply to provide public getter methods for the map.
Discussion:
Since VariableScope provides put and remove methods, it is not clear to me what value comes of hiding access to the maps (a setter for the map(s) would allow them to be set to null, which would be bad). If the intent is to prevent modification of the maps, exposing the iterator and eliminating the put and remove methods would protect them. Given that a caller can modify the content of the maps, however, merely hides useful methods from the Map interface (e.g. iterator(), putAll(), clear(), size(), values(), elements(), keySet()). In particular, the absence of iterator(), values(), elements() and keySet() are the most detrimental.