Repository: PebbleTemplates/pebble (java)

Issue:
Allow all variable names to be retrieve from ScopeChain/Scope
Hi, 

I want to write a custom function to return all the variable names available from the current context (it's very valuable for debugging purpose). I can get ScopeChain from EvaluationContext, but there is no method exposed to retrieve all the keys from each Scope's backingMap. I got around this by using Java reflection so far, but it will be nice to have this available from the API.

Thanks,
Zemian

Pull request description:
Allow to retrieve all variable names of a Scope
Resolves #291

Patch:
diff --git a/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java b/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java
index 8b09a5d9..b1600175 100644
--- a/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java
+++ b/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java
@@ -9,6 +9,7 @@
 package com.mitchellbosecke.pebble.template;
 
 import java.util.HashMap;
+import java.util.Set;
 import java.util.Map;
 
 /**
@@ -96,4 +97,13 @@ public class Scope {
   public boolean isLocal() {
     return this.local;
   }
+
+  /**
+   * Returns keys of all the variables at this scope.
+   *
+   * @return A set of keys
+   */
+  public Set<String> getKeys(){
+    return backingMap.keySet();
+  }
 }


Test patch:
diff --git a/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java b/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java
new file mode 100644
index 00000000..8ef59acb
--- /dev/null
+++ b/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java
@@ -0,0 +1,28 @@
+package com.mitchellbosecke.pebble;
+
+import com.mitchellbosecke.pebble.template.Scope;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ScopeTest {
+
+    @Test
+    void testGetKeys() {
+        Map<String, Object> map = new HashMap<>();
+        map.putIfAbsent("key1", new String("value1"));
+        map.putIfAbsent("key2", new String("value2"));
+
+        Scope scope = new Scope(map, false);
+        Set<String> expected = new HashSet<>();
+        expected.add("key1");
+        expected.add("key2");
+
+        assertEquals(expected, scope.getKeys());
+    }
+}