aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2015-08-06 12:33:47 +0000
committerGravatar David Chen <dzc@google.com>2015-08-06 22:14:13 +0000
commit4f24a7388a3f4261d669e621eeb5dc4aa19be429 (patch)
treea8523e78734c5d7d45e99e9b10c642d126a40c9f /src/main/java/com/google/devtools/build/lib/syntax
parent71423eb5cee46874066bccdacb36169faa404118 (diff)
Fixed a bug where the methods of Skylark dictionaries were not properly recognized by hasattr() and dir()
-- MOS_MIGRATED_REVID=100022797
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Environment.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
index 3de17c8e5a..ea34b621f2 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
@@ -315,6 +315,7 @@ public class Environment {
* Registers a function with namespace to this global environment.
*/
public void registerFunction(Class<?> nameSpace, String name, BaseFunction function) {
+ nameSpace = getCanonicalRepresentation(nameSpace);
Preconditions.checkArgument(parent == null);
if (!functions.containsKey(nameSpace)) {
functions.put(nameSpace, new HashMap<String, BaseFunction>());
@@ -323,6 +324,7 @@ public class Environment {
}
private Map<String, BaseFunction> getNamespaceFunctions(Class<?> nameSpace) {
+ nameSpace = getCanonicalRepresentation(nameSpace);
if (disabledNameSpaces.contains(nameSpace)
|| (parent != null && parent.disabledNameSpaces.contains(nameSpace))) {
return null;
@@ -335,6 +337,17 @@ public class Environment {
}
/**
+ * Returns the canonical representation of the given class, i.e. the super class for which any
+ * functions were registered.
+ *
+ * <p>Currently, this is only necessary for mapping the different subclasses of {@link
+ * java.util.Map} to the interface.
+ */
+ private Class<?> getCanonicalRepresentation(Class<?> clazz) {
+ return Map.class.isAssignableFrom(clazz) ? Map.class : clazz;
+ }
+
+ /**
* Returns the function of the namespace of the given name or null of it does not exists.
*/
public BaseFunction getFunction(Class<?> nameSpace, String name) {