Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 015 | Do not change parameter value. For comprehensibility, formal parameters should be final | 2 | 82:25 |
Java Inspector 068 | Do not use System.out and System.err to output logging messages. Use loggers instead. | 2 | 79:35 |
Java Inspector 068 | Do not use System.out and System.err to output logging messages. Use loggers instead. | 2 | 95:33 |
Java Inspector 068 | Do not use System.out and System.err to output logging messages. Use loggers instead. | 2 | 96:33 |
Java Inspector 068 | Do not use System.out and System.err to output logging messages. Use loggers instead. | 2 | 98:43 |
Java Inspector 073 [java.lang.StringBuffer] | In Java 5 use StringBuilder instead of StringBuffer if access is single-threaded, e.g. StringBuffer is used as a local variable . | 2 | 66:17 |
Java Inspector 089 | Parameter node is not documented | 2 | 41:9 |
Java Inspector 089 | Parameter tokenNames is not documented | 2 | 41:9 |
Java Inspector 089 | Parameter holder is not documented | 2 | 41:9 |
Java Inspector 089 | Parameter node is not documented | 2 | 53:9 |
Java Inspector 089 | Parameter tokenNames is not documented | 2 | 53:9 |
Java Inspector 089 | Parameter owner is not documented | 2 | 53:9 |
Java Inspector 089 | Method return value is not documented | 2 | 53:9 |
Java Inspector 089 | Parameter node is not documented | 2 | 78:9 |
Java Inspector 089 | Parameter tokenNames is not documented | 2 | 78:9 |
Java Inspector 089 | Parameter node is not documented | 2 | 90:9 |
Java Inspector 089 | Undocumented parameter tokenNames | 2 | 90:9 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 54:49 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 55:34 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 68:35 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 79:36 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 98:44 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 98:64 |
1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.antlr;
24
25import org.w3c.dom.Document;
26import org.w3c.dom.Element;
27
28import antlr.collections.AST;
29
30/**
31 * Serializes AST to DOM
32 * @author Pavel Vlasov
33 */
34public class AstUtil {
35 /**
36 * Serializes AST, its children and its siblings to DOM.
37 * @param node
38 * @param tokenNames
39 * @param holder
40 */
41 public static void toDom(antlr.collections.AST node, String[] tokenNames, Element holder) {
42 for (AST ast=node; ast!=null; ast=ast.getNextSibling()) {
43 holder.appendChild(toDom(ast, tokenNames, holder.getOwnerDocument()));
44 }
45 }
46
47 /**
48 * Serializes AST and its children to DOM.
49 * @param node
50 * @param tokenNames
51 * @param owner
52 */
53 public static Element toDom(antlr.collections.AST node, String[] tokenNames, Document owner) {
54 Element ret=owner.createElement("ast");
55 ret.setAttribute("type", tokenNames[node.getType()]);
56 if (node.getText()!=null) {
57 ret.appendChild(owner.createTextNode(node.getText()));
58 }
59 for (AST child=node.getFirstChild(); child!=null; child=child.getNextSibling()) {
60 ret.appendChild(toDom(child, tokenNames, owner));
61 }
62 return ret;
63 }
64
65 private static String tabs(int t) {
66 StringBuffer sb=new StringBuffer();
67 for (int i=0; i<t; i++) {
68 sb.append("....");
69 }
70 return sb.toString();
71 }
72
73 /**
74 * Dumps node and siblings
75 * @param node
76 * @param tokenNames
77 */
78 public static void dumpAll(antlr.collections.AST node, String[] tokenNames) {
79 System.out.println("=== AST Dump ===");
80 while (node!=null) {
81 dump(node, tokenNames, 0);
82 node=node.getNextSibling();
83 }
84 }
85
86 /**
87 * Dumps this node and its children
88 * @param node
89 */
90 public static void dump(antlr.collections.AST node, String[] tokenNames) {
91 dump(node, tokenNames, 0);
92 }
93
94 private static void dump(antlr.collections.AST node, String[] tokenNames, int tab) {
95 System.out.print(tabs(tab));
96 System.out.print(tokenNames[node.getType()]);
97 if (node.getText()!=null) {
98 System.out.println(" '"+node.getText()+"'");
99 }
100 for (AST child=node.getFirstChild(); child!=null; child=child.getNextSibling()) {
101 dump(child, tokenNames, tab+1);
102 }
103 }
104}
105