You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/07/29 10:03:37 UTC

groovy git commit: GROOVY-7894: Add access to declared variables within VariableScope (closes #370)

Repository: groovy
Updated Branches:
  refs/heads/master 571e8eea4 -> dc2e10464


GROOVY-7894: Add access to declared variables within VariableScope (closes #370)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/dc2e1046
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/dc2e1046
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/dc2e1046

Branch: refs/heads/master
Commit: dc2e10464ca6559ba656cfe333a688bdaa7f2186
Parents: 571e8ee
Author: Natacha Gabbamonte <ng...@palantir.com>
Authored: Thu Jul 21 15:32:04 2016 -0400
Committer: paulk <pa...@asert.com.au>
Committed: Fri Jul 29 19:56:15 2016 +1000

----------------------------------------------------------------------
 .../org/codehaus/groovy/ast/VariableScope.java  | 24 +++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/dc2e1046/src/main/org/codehaus/groovy/ast/VariableScope.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/VariableScope.java b/src/main/org/codehaus/groovy/ast/VariableScope.java
index b96617e..077c7f1 100644
--- a/src/main/org/codehaus/groovy/ast/VariableScope.java
+++ b/src/main/org/codehaus/groovy/ast/VariableScope.java
@@ -178,4 +178,26 @@ public class VariableScope  {
     public Iterator<Variable> getReferencedClassVariablesIterator() {
         return getReferencedClassVariables().values().iterator();
     }
-}
\ No newline at end of file
+
+    /**
+     * Gets a map containing the variables declared in this scope.
+     * This map cannot be modified.
+     * @return a map containing the declared variable references
+     */
+    public Map<String, Variable> getDeclaredVariables() {
+        if (declaredVariables == Collections.EMPTY_MAP) {
+            return declaredVariables;
+        } else {
+            return Collections.unmodifiableMap(declaredVariables);
+        }
+    }
+
+    /**
+     * Gets an iterator for the declared class variables. The remove
+     * operation is not supported.
+     * @return an iterator for the declared variables
+     */
+    public Iterator<Variable> getDeclaredVariablesIterator() {
+        return getDeclaredVariables().values().iterator();
+    }
+}