OSDN Git Service

Integrate 5397067d into tools_r8. DO NOT MERGE.
authorBill Napier <napier@google.com>
Sun, 17 Oct 2010 22:47:04 +0000 (15:47 -0700)
committerXavier Ducrohet <xav@android.com>
Wed, 20 Oct 2010 20:20:52 +0000 (13:20 -0700)
Fix field visibility by ensuring they stay in __dict__.

Change-Id: I2e93dd4ba8c8cc3f05ca477091932268ec5d78da

monkeyrunner/src/com/android/monkeyrunner/JythonUtils.java

index 8d25dd9..864441e 100644 (file)
@@ -38,6 +38,7 @@ import org.python.core.PyInteger;
 import org.python.core.PyList;
 import org.python.core.PyNone;
 import org.python.core.PyObject;
+import org.python.core.PyReflectedField;
 import org.python.core.PyReflectedFunction;
 import org.python.core.PyString;
 import org.python.core.PyStringMap;
@@ -302,9 +303,26 @@ public final class JythonUtils {
         }
       }
 
+      // Also look at all the fields (both static and instance).
+      for (Field f : clz.getFields()) {
+          if (f.isAnnotationPresent(MonkeyRunnerExported.class)) {
+              String fieldName = f.getName();
+              PyObject pyField = dict.__finditem__(fieldName);
+              if (pyField != null && pyField instanceof PyReflectedField) {
+                  PyReflectedField realPyfield = (PyReflectedField) pyField;
+                MonkeyRunnerExported doc = f.getAnnotation(MonkeyRunnerExported.class);
+
+                // TODO: figure out how to set field documentation.  __doc__ is Read Only
+                // in this context.
+                // realPyfield.__setattr__("__doc__", new PyString(buildDoc(doc)));
+                functions.remove(fieldName);
+              }
+            }
+      }
+
       // Now remove any elements left from the functions collection
       for (String name : functions) {
-        dict.__delitem__(name);
+          dict.__delitem__(name);
       }
     }