Initial commit 🎉

fbshipit-source-id: b6fc29740c6875d2e78953b8a7123890a67930f2
Co-authored-by: Sebastian McKenzie <sebmck@fb.com>
Co-authored-by: John Knox <jknox@fb.com>
Co-authored-by: Emil Sjölander <emilsj@fb.com>
Co-authored-by: Pritesh Nandgaonkar <prit91@fb.com>
This commit is contained in:
Daniel Büchele
2018-04-13 08:38:06 -07:00
committed by Daniel Buchele
commit fbbf8cf16b
659 changed files with 87130 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.sonar.plugins.inspector.descriptors;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import com.facebook.sonar.core.SonarDynamic;
import com.facebook.sonar.core.SonarObject;
import com.facebook.sonar.plugins.inspector.Named;
import com.facebook.sonar.plugins.inspector.NodeDescriptor;
import com.facebook.sonar.plugins.inspector.Touch;
import com.facebook.stetho.common.android.ResourcesUtil;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
public class SupportFragmentDescriptor extends NodeDescriptor<Fragment> {
@Override
public void init(Fragment node) {}
@Override
public String getId(Fragment node) {
return Integer.toString(System.identityHashCode(node));
}
@Override
public String getName(Fragment node) {
return node.getClass().getSimpleName();
}
@Override
public int getChildCount(Fragment node) {
return node.getView() == null ? 0 : 1;
}
@Override
public @Nullable Object getChildAt(Fragment node, int index) {
return node.getView();
}
@Override
public List<Named<SonarObject>> getData(Fragment node) {
final Bundle args = node.getArguments();
if (args == null || args.isEmpty()) {
return Collections.EMPTY_LIST;
}
final SonarObject.Builder bundle = new SonarObject.Builder();
for (String key : args.keySet()) {
bundle.put(key, args.get(key));
}
return Arrays.asList(new Named<>("Arguments", bundle.build()));
}
@Override
public void setValue(Fragment node, String[] path, SonarDynamic value) {}
@Override
public List<Named<String>> getAttributes(Fragment node) {
final int id = node.getId();
if (id == View.NO_ID || node.getHost() == null) {
return Collections.EMPTY_LIST;
}
return Arrays.asList(
new Named<>(
"id", ResourcesUtil.getIdStringQuietly(node.getContext(), node.getResources(), id)));
}
@Override
public void setHighlighted(Fragment node, boolean selected) throws Exception {
if (node.getView() == null) {
return;
}
final NodeDescriptor descriptor = descriptorForClass(View.class);
descriptor.setHighlighted(node.getView(), selected);
}
@Override
public void hitTest(Fragment node, Touch touch) {
touch.continueWithOffset(0, 0, 0);
}
@Override
public @Nullable String getDecoration(Fragment obj) {
return null;
}
@Override
public boolean matches(String query, Fragment node) throws Exception {
final NodeDescriptor descriptor = descriptorForClass(Object.class);
return descriptor.matches(query, node);
}
}