dumpBlock(..) method for a single formatting block printout

This commit is contained in:
Rustam.Vishnyakov
2010-05-06 20:20:38 +04:00
parent 812ad661a5
commit 20b8bc7e2f
@@ -36,11 +36,21 @@ public class BlockDebugUtil {
*/
public static void dumpBlockTree(PrintStream out, Block block) {
out.println("--- BLOCK TREE DUMP ---");
dumpBlockTree(out, block, "");
dumpBlockTree(out, block, "", true);
out.println("--- END OF DUMP ---\n\n");
}
private static void dumpBlockTree(PrintStream out, Block block, String indent) {
/**
* Print out a single block info without child blocks.
* @param out The output stream.
* @param block The block to print the info for.
*/
public static void dumpBlock(PrintStream out, Block block) {
dumpBlockTree(out, block, "", false);
}
private static void dumpBlockTree(PrintStream out, Block block, String indent, boolean withChildren) {
if (block == null) return;
out.print(indent + block.getClass().getSimpleName());
if (block.getIndent() != null) {
@@ -49,6 +59,7 @@ public class BlockDebugUtil {
else {
out.print(" <NO INDENT>");
}
out.print(" " + block.getTextRange() + " ");
if (block instanceof ASTBlock) {
ASTNode node = ((ASTBlock)block).getNode();
if (node != null) {
@@ -61,20 +72,20 @@ public class BlockDebugUtil {
out.print(" \"" + text + "\"");
}
}
System.out.println();
List<Block> subBlocks = getSubBlocks(block);
if (subBlocks != null && subBlocks.size() > 0) {
out.println(indent + "{");
for (Block child : subBlocks) {
dumpBlockTree(out, child, indent + " ");
out.println();
if (withChildren) {
List<Block> subBlocks = getSubBlocks(block);
if (subBlocks != null && subBlocks.size() > 0) {
out.println(indent + "{");
for (Block child : subBlocks) {
dumpBlockTree(out, child, indent + " ", true);
}
out.println(indent + "}");
}
out.println(indent + "}");
}
}
private static List<Block> getSubBlocks(Block root) {
if (root instanceof AbstractBlock) return ((AbstractBlock)root).getSubBlocks();
if (root instanceof DataLanguageBlockWrapper) return ((DataLanguageBlockWrapper)root).getSubBlocks();
return null;
return root.getSubBlocks();
}
}