NodeInfo tree working (besides litho nodes)

Summary: The second tree has access to all AX NodeInfo properties (they are not in the sidebar yet). Infrastructure set up to customize displayed information bassed on what is most useful. Descriptors for views updated to include AX functionality and non-view descriptors AX functions defaulted to null/empty. Non-view nodes (like Fragments, Window, Appication) no longer included in AX tree. Corresponding nodes will be highlighted (although not expanded) on click in either tree.

Differential Revision: D8795800

fbshipit-source-id: cf2333f69bfecca3ff84aae62681c684dfa14bf3
This commit is contained in:
Sara Valderrama
2018-07-12 09:23:29 -07:00
committed by Facebook Github Bot
parent 9e673a07a8
commit 1c5ecce667
8 changed files with 284 additions and 8 deletions

View File

@@ -126,6 +126,8 @@ public class InspectorSonarPlugin implements SonarPlugin {
connection.receive("setHighlighted", mSetHighlighted);
connection.receive("setSearchActive", mSetSearchActive);
connection.receive("getSearchResults", mGetSearchResults);
connection.receive("getAXRoot", mGetAXRoot);
connection.receive("getAXNodes", mGetAXNodes);
if (mExtensionCommands != null) {
for (ExtensionCommand extensionCommand : mExtensionCommands) {
@@ -156,6 +158,28 @@ public class InspectorSonarPlugin implements SonarPlugin {
}
};
final SonarReceiver mGetAXRoot =
new MainThreadSonarReceiver(mConnection) {
@Override
public void onReceiveOnMainThread(SonarObject params, SonarResponder responder)
throws Exception {
List<View> viewRoots = mApplication.getViewRoots();
// for now only works if one view root
if (viewRoots.size() != 1) {
responder.error(
new SonarObject.Builder().put("message", "Too many view roots.").build());
return;
}
SonarObject response = getAXNode(trackObject(viewRoots.get(0)));
if (response == null) {
responder.error(
new SonarObject.Builder().put("message", "AX root node returned null.").build());
return;
}
responder.success(response);
}
};
final SonarReceiver mGetNodes =
new MainThreadSonarReceiver(mConnection) {
@Override
@@ -183,6 +207,33 @@ public class InspectorSonarPlugin implements SonarPlugin {
}
};
final SonarReceiver mGetAXNodes =
new MainThreadSonarReceiver(mConnection) {
@Override
public void onReceiveOnMainThread(final SonarObject params, final SonarResponder responder)
throws Exception {
final SonarArray ids = params.getArray("ids");
final SonarArray.Builder result = new SonarArray.Builder();
for (int i = 0, count = ids.length(); i < count; i++) {
final String id = ids.getString(i);
final SonarObject node = getAXNode(id);
if (node != null) {
result.put(node);
} else {
responder.error(
new SonarObject.Builder()
.put("message", "No node with given id")
.put("id", id)
.build());
return;
}
}
responder.success(new SonarObject.Builder().put("elements", result).build());
}
};
final SonarReceiver mSetData =
new MainThreadSonarReceiver(mConnection) {
@Override
@@ -435,6 +486,62 @@ public class InspectorSonarPlugin implements SonarPlugin {
.build();
}
private @Nullable SonarObject getAXNode(String id) throws Exception {
final Object obj = mObjectTracker.get(id);
if (obj == null) {
return null;
}
final NodeDescriptor<Object> descriptor = descriptorForObject(obj);
if (descriptor == null) {
return null;
}
final SonarArray.Builder children = new SonarArray.Builder();
new ErrorReportingRunnable(mConnection) {
@Override
protected void runOrThrow() throws Exception {
for (int i = 0, count = descriptor.getChildCount(obj); i < count; i++) {
final Object child = assertNotNull(descriptor.getAXChildAt(obj, i));
children.put(trackObject(child));
}
}
}.run();
final SonarObject.Builder data = new SonarObject.Builder();
new ErrorReportingRunnable(mConnection) {
@Override
protected void runOrThrow() throws Exception {
for (Named<SonarObject> props : descriptor.getAXData(obj)) {
data.put(props.getName(), props.getValue());
}
}
}.run();
final SonarArray.Builder attributes = new SonarArray.Builder();
new ErrorReportingRunnable(mConnection) {
@Override
protected void runOrThrow() throws Exception {
for (Named<String> attribute : descriptor.getAXAttributes(obj)) {
attributes.put(
new SonarObject.Builder()
.put("name", attribute.getName())
.put("value", attribute.getValue())
.build());
}
}
}.run();
return new SonarObject.Builder()
.put("id", descriptor.getId(obj))
.put("name", descriptor.getAXName(obj))
.put("data", data)
.put("children", children)
.put("attributes", attributes)
.build();
}
private String trackObject(Object obj) throws Exception {
final NodeDescriptor<Object> descriptor = descriptorForObject(obj);
final String id = descriptor.getId(obj);