use of org.python.core.PyInstance in project Pogamut3 by kefik.
the class PyInstanceWrapper method getChildren.
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyInstance))
throw new IllegalArgumentException("object is not instance of PyInstance");
PyInstance pyInstance = (PyInstance) object;
PyList keys = null;
if (pyInstance.__dict__ instanceof PyDictionary)
keys = ((PyDictionary) pyInstance.__dict__).keys();
if (pyInstance.__dict__ instanceof PyStringMap)
keys = ((PyStringMap) pyInstance.__dict__).keys();
if (keys == null)
return null;
final PyObject pyDict = pyInstance.__dict__;
int count = keys.__len__();
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
PyObject obj;
for (int i = 0; i < count; ++i) {
final PyObject key = keys.__getitem__(i);
Object name = (String) key.__tojava__(String.class);
if ((name == Py.NoConversion) || (!(name instanceof String)))
continue;
obj = pyDict.__finditem__(key);
list.add(new PyObjectAdapter((String) name, new PyObjectPlace() {
private PyObject myPlace = key;
@Override
public void set(PyObject newValue) {
pyDict.__setitem__(myPlace, newValue);
}
@Override
public PyObject get() {
try {
return pyDict.__finditem__(myPlace);
} catch (Exception e) {
return null;
}
}
}));
}
return list;
}
Aggregations