mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dumpBlock(..) method for a single formatting block printout
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user