1 package org.apache.velocity.runtime.visitor; 2 3 18 19 import org.apache.velocity.runtime.parser.Token; 20 import org.apache.velocity.runtime.parser.node.*; 21 22 33 public class NodeViewMode extends BaseVisitor 34 { 35 private int indent = 0; 36 private boolean showTokens = true; 37 38 41 private String indentString() 42 { 43 StringBuffer sb = new StringBuffer (); 44 for (int i = 0; i < indent; ++i) 45 { 46 sb.append(" "); 47 } 48 return sb.toString(); 49 } 50 51 55 private Object showNode(Node node, Object data) 56 { 57 String tokens = ""; 58 String special = ""; 59 Token t; 60 61 if (showTokens) 62 { 63 t = node.getFirstToken(); 64 65 if (t.specialToken != null && ! t.specialToken.image.startsWith("##")) 66 special = t.specialToken.image; 67 68 tokens = " -> " + special + t.image; 69 } 70 71 System.out.println(indentString() + node + tokens); 72 ++indent; 73 data = node.childrenAccept(this, data); 74 --indent; 75 return data; 76 } 77 78 79 public Object visit(SimpleNode node, Object data) 80 { 81 return showNode(node,data); 82 } 83 84 85 public Object visit(ASTprocess node, Object data) 86 { 87 return showNode(node,data); 88 } 89 90 91 public Object visit(ASTExpression node, Object data) 92 { 93 return showNode(node,data); 94 } 95 96 97 public Object visit(ASTAssignment node, Object data) 98 { 99 return showNode(node,data); 100 } 101 102 103 public Object visit(ASTOrNode node, Object data) 104 { 105 return showNode(node,data); 106 } 107 108 109 public Object visit(ASTAndNode node, Object data) 110 { 111 return showNode(node,data); 112 } 113 114 115 public Object visit(ASTEQNode node, Object data) 116 { 117 return showNode(node,data); 118 } 119 120 121 public Object visit(ASTNENode node, Object data) 122 { 123 return showNode(node,data); 124 } 125 126 127 public Object visit(ASTLTNode node, Object data) 128 { 129 return showNode(node,data); 130 } 131 132 133 public Object visit(ASTGTNode node, Object data) 134 { 135 return showNode(node,data); 136 } 137 138 139 public Object visit(ASTLENode node, Object data) 140 { 141 return showNode(node,data); 142 } 143 144 145 public Object visit(ASTGENode node, Object data) 146 { 147 return showNode(node,data); 148 } 149 150 151 public Object visit(ASTAddNode node, Object data) 152 { 153 return showNode(node,data); 154 } 155 156 157 public Object visit(ASTSubtractNode node, Object data) 158 { 159 return showNode(node,data); 160 } 161 162 163 public Object visit(ASTMulNode node, Object data) 164 { 165 return showNode(node,data); 166 } 167 168 169 public Object visit(ASTDivNode node, Object data) 170 { 171 return showNode(node,data); 172 } 173 174 175 public Object visit(ASTModNode node, Object data) 176 { 177 return showNode(node,data); 178 } 179 180 181 public Object visit(ASTNotNode node, Object data) 182 { 183 return showNode(node,data); 184 } 185 186 187 public Object visit(ASTNumberLiteral node, Object data) 188 { 189 return showNode(node,data); 190 } 191 192 193 public Object visit(ASTStringLiteral node, Object data) 194 { 195 return showNode(node,data); 196 } 197 198 199 public Object visit(ASTIdentifier node, Object data) 200 { 201 return showNode(node,data); 202 } 203 204 205 public Object visit(ASTMethod node, Object data) 206 { 207 return showNode(node,data); 208 } 209 210 211 public Object visit(ASTReference node, Object data) 212 { 213 return showNode(node,data); 214 } 215 216 217 public Object visit(ASTTrue node, Object data) 218 { 219 return showNode(node,data); 220 } 221 222 223 public Object visit(ASTFalse node, Object data) 224 { 225 return showNode(node,data); 226 } 227 228 229 public Object visit(ASTBlock node, Object data) 230 { 231 return showNode(node,data); 232 } 233 234 235 public Object visit(ASTText node, Object data) 236 { 237 return showNode(node,data); 238 } 239 240 241 public Object visit(ASTIfStatement node, Object data) 242 { 243 return showNode(node,data); 244 } 245 246 247 public Object visit(ASTElseStatement node, Object data) 248 { 249 return showNode(node,data); 250 } 251 252 253 public Object visit(ASTElseIfStatement node, Object data) 254 { 255 return showNode(node,data); 256 } 257 258 public Object visit(ASTObjectArray node, Object data) 259 { 260 return showNode(node,data); 261 } 262 263 public Object visit(ASTDirective node, Object data) 264 { 265 return showNode(node,data); 266 } 267 268 public Object visit(ASTWord node, Object data) 269 { 270 return showNode(node,data); 271 } 272 273 public Object visit(ASTSetDirective node, Object data) 274 { 275 return showNode(node,data); 276 } 277 } 278 | Popular Tags |