Class HierarchyInspector


  • public class HierarchyInspector
    extends Object
    Provides helpers to analyze a hierarchy of widgets.
    • Method Detail

      • visitHierarchy

        public static void visitHierarchy​(Widget widget,
                                          WidgetVisitor visitor)
        Visits a widget hierarchy.

        If the root widget is a Container, this method calls:

         visitWidget(root);
         beginContainer();
         for (Widget child: getChildren(root)) { visitHierarchy(child, visitor); }
         endContainer()
         
        Otherwise, it simply calls `visitWidget(root)`.
        Parameters:
        widget - the root of the widget hierarchy.
        visitor - the visitor.
      • countInstances

        public static int countInstances​(Widget root,
                                         Class<? extends Widget> clazz)
        Counts instances of a Widget type in a widget hierarchy.

        The method is recursive: if the given widget is a container, it browses its children.

        Parameters:
        root - the root of the widget hierarchy.
        clazz - the widget class.
        Returns:
        the number of instances.
      • countNumberOfContainers

        public static int countNumberOfContainers​(Widget root)
        Counts containers in a given widget hierarchy.

        The method is recursive: if the given widget is a container, it browses its children.

        Parameters:
        root - the root of the widget hierarchy.
        Returns:
        the number of containers.
      • countNumberOfWidgets

        public static int countNumberOfWidgets​(Widget root)
        Counts widgets in a widget hierarchy.

        The method is recursive: if the given widget is a container, it browses its children.

        Parameters:
        root - the root of the widget hierarchy.
        Returns:
        the number of widgets.
      • countMaxDepth

        public static int countMaxDepth​(Widget root)
        Counts the maximum depth of a widget hierarchy.

        The method is recursive: if the given widget is a container, it browses its children.

        Parameters:
        root - the root of the widget hierarchy.
        Returns:
        the maximum depth.
      • hierarchyToString

        public static String hierarchyToString​(Widget root)
        Prints a widget hierarchy.

        Prints the root widget and its children recursively in a tree format.

        Parameters:
        root - the root of the widget hierarchy.
        Returns:
        the widget hierarchy serialized in a tree format.
      • printHierarchy

        public static void printHierarchy​(Widget root)
        Prints the widget hierarchy of a desktop on the "standard" output stream.

        For each widget and its children recursively in a tree format, prints its class name.

        This method writes on the "standard" output stream, for use during time-sensitive operations, prefer hierarchyStyleToString(Widget).

        Parameters:
        root - the root of the widget hierarchy.
        Throws:
        IllegalArgumentException - if root is null or is not attached.
        See Also:
        standard output stream, Widget.isAttached()
      • hierarchyStyleToString

        public static String hierarchyStyleToString​(Widget root)
        Prints the widget hierarchy of a desktop.

        For each widget and its children recursively in a tree format, prints its class name and current style.

        Parameters:
        root - the root of the widget hierarchy.
        Returns:
        the hierarchy.
        Throws:
        IllegalArgumentException - if root is null or is not attached.
        See Also:
        Widget.isAttached()
      • printHierarchyStyle

        public static void printHierarchyStyle​(Widget root)
        Prints the widget hierarchy of a desktop on the "standard" output stream.

        For each widget and its children recursively in a tree format, prints its class name and current style.

        This method writes on the "standard" output stream, for use during time-sensitive operations, prefer hierarchyStyleToString(Widget).

        Parameters:
        root - the root of the widget hierarchy.
        Throws:
        IllegalArgumentException - if root is null or is not attached.
        See Also:
        standard output stream, Widget.isAttached()
      • pathToWidgetToString

        public static String pathToWidgetToString​(Widget widget)
        Prints the path to the given widget with > separator.
        Parameters:
        widget - the widget to inspect.
        Returns:
        the path.
        See Also:
        pathToWidgetToString(Widget, char)
      • pathToWidgetToString

        public static String pathToWidgetToString​(Widget widget,
                                                  char separator)
        Prints the path to the given widget.

        Prints the containers from the root (including the desktop) to the widget, separated with the given separator. Example: Desktop > Scroll > ScrollableList > Label

        Parameters:
        widget - the widget to inspect.
        separator - the separator between the items.
        Returns:
        the path.