in stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/Runtime.java [396:432]
private GetPropertiesResponse getPropertiesForObject(Object object) {
GetPropertiesResponse response = new GetPropertiesResponse();
List<PropertyDescriptor> properties = new ArrayList<>();
for (
Class<?> declaringClass = object.getClass();
declaringClass != null;
declaringClass = declaringClass.getSuperclass()
) {
// Reverse the list of fields while going up the superclass chain.
// When we're done, we'll reverse the full list so that the superclasses
// appear at the top, but within each class they properties are in declared order.
List<Field> fields =
new ArrayList<Field>(Arrays.asList(declaringClass.getDeclaredFields()));
Collections.reverse(fields);
String prefix = declaringClass == object.getClass()
? ""
: declaringClass.getSimpleName() + ".";
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
field.setAccessible(true);
try {
Object fieldValue = field.get(object);
PropertyDescriptor property = new PropertyDescriptor();
property.name = prefix + field.getName();
property.value = objectForRemote(fieldValue);
properties.add(property);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
Collections.reverse(properties);
response.result = properties;
return response;
}