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 overridingappendNodeInfoLn(Appendable, Node)
.
-
-
Constructor Summary
Constructors Constructor Description TextTreeRenderer(boolean onlyAscii, int maxLevel)
Creates a new text renderer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendBoundaryForNodeLn(Node node, Appendable out, String indentStr)
protected void
appendIndent(Appendable out, String prefix, boolean isTail)
protected void
appendNodeInfoLn(Appendable out, Node node)
Append info about the node.void
renderSubtree(Node node, Appendable out)
Appends the subtree rooted at the given node on the provided output writer.
-
-
-
Constructor Detail
-
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 byappendBoundaryForNodeLn(Node, Appendable, String)
.
-
-
Method Detail
-
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 interfaceTreeRenderer
- Parameters:
node
- Node to renderout
- 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
-
-