1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3.internal;
18
19 import org.apache.commons.jexl3.JexlScript;
20 import org.apache.commons.jexl3.parser.ASTIdentifier;
21 import org.apache.commons.jexl3.parser.ASTIdentifierAccess;
22 import org.apache.commons.jexl3.parser.JexlNode;
23
24
25
26
27 public class Dumper {
28 public static String toString(final JexlScript script) {
29 return new Dumper(script).toString();
30 }
31 private final StringBuilder strb = new StringBuilder();
32
33 private int indent;
34
35 private Dumper(final JexlScript script) {
36 dump(((Script) script).script, null);
37 }
38
39 private void dump(final JexlNode node, final Object data) {
40 final int num = node.jjtGetNumChildren();
41 indent();
42 strb.append(node.getClass().getSimpleName());
43 if (node instanceof ASTIdentifier || node instanceof ASTIdentifierAccess) {
44 strb.append("@");
45 strb.append(node.toString());
46 }
47 strb.append('(');
48 indent += 1;
49 for (int c = 0; c < num; ++c) {
50 final JexlNode child = node.jjtGetChild(c);
51 if (c > 0) {
52 strb.append(',');
53 }
54 strb.append('\n');
55 dump(child, data);
56 }
57 indent -= 1;
58 if (num > 0) {
59 strb.append('\n');
60 indent();
61 }
62 strb.append(')');
63 }
64
65 private void indent() {
66 for (int i = 0; i < indent; ++i) {
67 strb.append(" ");
68 }
69 }
70
71 @Override
72 public String toString() {
73 return strb.toString();
74 }
75 }