Class PrettyPrintTree

java.lang.Object
com.vaadin.browserless.internal.PrettyPrintTree

public final class PrettyPrintTree extends Object
Utility class to create a pretty-printed ASCII tree of arbitrary nodes that can be printed to the console. You can build the tree out of any tree structure, just fill in this node name and its children.

To create a pretty tree dump of a Vaadin component, just use ofVaadin(Component).

For internal use only. May be renamed or removed in a future release.

  • Constructor Details

    • PrettyPrintTree

      public PrettyPrintTree(String name, List<PrettyPrintTree> children)
      Creates a tree node.
      Parameters:
      name - the node name.
      children - the node children, mutable.
  • Method Details

    • getName

      public String getName()
      Returns the node name.
      Returns:
      the node name.
    • getChildren

      public List<PrettyPrintTree> getChildren()
      Returns the node children.
      Returns:
      the mutable list of children.
    • print

      public String print()
      Prints this tree.
      Returns:
      the pretty-printed tree.
    • ofVaadin

      public static PrettyPrintTree ofVaadin(Component root)
      Creates a tree out of the given Vaadin component and all of its descendants, as provided by TestingLifecycleHook.getAllChildren(Component).
      Parameters:
      root - the root component.
      Returns:
      the tree.
    • getPrettyPrintUseAscii

      public static boolean getPrettyPrintUseAscii()
      If true, PrettyPrintTree will use \-- instead of └── which tend to render on some terminals as ???.
      Returns:
      whether ASCII characters are used.
    • setPrettyPrintUseAscii

      public static void setPrettyPrintUseAscii(boolean prettyPrintUseAscii)
      Sets whether PrettyPrintTree uses ASCII characters only.
      Parameters:
      prettyPrintUseAscii - true to use ASCII characters only.
    • toPrettyTree

      public static String toPrettyTree(Component component)
      Returns a pretty-printed tree of the given component and its descendants.
      Parameters:
      component - the root component.
      Returns:
      the pretty-printed tree.
    • toPrettyString

      public static String toPrettyString(Component component)
      Returns the most basic properties of the component, formatted as a concise string:
      Parameters:
      component - the component.
      Returns:
      the component properties as a concise string.
    • getPrettyStringHook

      public static BiConsumer<Component,LinkedList<String>> getPrettyStringHook()
      Invoked by toPrettyString(Component) to add additional properties for your custom component. Add additional properties to the list provided, e.g. list.add("icon='" + icon + "'").

      By default does nothing.

      Returns:
      the hook.
    • setPrettyStringHook

      public static void setPrettyStringHook(BiConsumer<Component,LinkedList<String>> prettyStringHook)
      Sets the hook invoked by toPrettyString(Component), see getPrettyStringHook().
      Parameters:
      prettyStringHook - the hook, not null.
    • getDontDumpAttributes

      public static Set<String> getDontDumpAttributes()
      Never dump these attributes in toPrettyString(Component). By default these attributes are ignored:
      • disabled - dumped separately as "DISABLED" string.
      • id - dumped as Component.id
      • href - dumped separately for any component that has an href member.
      Returns:
      the mutable set of attribute names.
    • setDontDumpAttributes

      public static void setDontDumpAttributes(Set<String> dontDumpAttributes)
      Sets the attributes never dumped by toPrettyString(Component), see getDontDumpAttributes().
      Parameters:
      dontDumpAttributes - the set of attribute names, not null.