Class TextTreeRenderer

java.lang.Object
net.sourceforge.pmd.util.treeexport.TextTreeRenderer
All Implemented Interfaces:
TreeRenderer

public class TextTreeRenderer extends Object implements TreeRenderer
A simple recursive printer. Output looks like so:

 +- LocalVariableDeclaration
    +- Type
    |  +- PrimitiveType
    +- VariableDeclarator
       +- VariableId
       +- VariableInitializer
          +- 1 child not shown

 
or

 └─ LocalVariableDeclaration
    ├─ Type
    │  └─ PrimitiveType
    └─ VariableDeclarator
       ├─ VariableId
       └─ VariableInitializer
          └─ 1 child not shown

 
By default, just prints the structure, like shown above. You can configure it to render nodes differently by overriding appendNodeInfoLn(Appendable, Node).
  • Constructor Details

    • TextTreeRenderer

      public TextTreeRenderer(boolean onlyAscii, int maxLevel)
      Creates a new text renderer.
      Parameters:
      onlyAscii - Whether to output the skeleton of the tree with only ascii characters. If false, uses unicode chars like '├'
      maxLevel - Max level on which to recurse. Negative means unbounded. If the max level is reached, a placeholder is dumped, like "1 child is not shown". This is controlled by appendBoundaryForNodeLn(Node, Appendable, String).
  • Method Details

    • renderSubtree

      public void renderSubtree(Node node, Appendable out) throws IOException
      Description copied from interface: TreeRenderer
      Appends the subtree rooted at the given node on the provided output writer. The implementation is free to filter out some nodes from the subtree.
      Specified by:
      renderSubtree in interface TreeRenderer
      Parameters:
      node - Node to render
      out - Object onto which the output is appended
      Throws:
      IOException - If an IO error occurs while appending to the output
    • appendIndent

      protected final void appendIndent(Appendable out, String prefix, boolean isTail) throws IOException
      Throws:
      IOException
    • appendNodeInfoLn

      protected void appendNodeInfoLn(Appendable out, Node node) throws IOException
      Append info about the node. The indent has already been appended. This should end with a newline. The default just appends the name of the node, and no other information.
      Throws:
      IOException
    • appendBoundaryForNodeLn

      protected void appendBoundaryForNodeLn(Node node, Appendable out, String indentStr) throws IOException
      Throws:
      IOException