From 5397067da9a1dc97ca2d4d036c9614da2f3af46f Mon Sep 17 00:00:00 2001 From: Bill Napier Date: Sun, 17 Oct 2010 15:47:04 -0700 Subject: [PATCH] Fix field visibility by ensuring they stay in __dict__. Change-Id: I0f632f799ac7f554bb524099208385973423a0d0 --- .../src/com/android/monkeyrunner/JythonUtils.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/monkeyrunner/src/com/android/monkeyrunner/JythonUtils.java b/monkeyrunner/src/com/android/monkeyrunner/JythonUtils.java index 8d25dd9b9..864441e59 100644 --- a/monkeyrunner/src/com/android/monkeyrunner/JythonUtils.java +++ b/monkeyrunner/src/com/android/monkeyrunner/JythonUtils.java @@ -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); } } -- 2.11.0