1 16 package com.google.gwt.dev.jjs.ast; 17 18 import com.google.gwt.dev.jjs.InternalCompilerException; 19 import com.google.gwt.dev.jjs.ast.js.JClassSeed; 20 import com.google.gwt.dev.jjs.ast.js.JMultiExpression; 21 import com.google.gwt.dev.jjs.ast.js.JsniFieldRef; 22 import com.google.gwt.dev.jjs.ast.js.JsniMethod; 23 import com.google.gwt.dev.jjs.ast.js.JsniMethodRef; 24 import com.google.gwt.dev.jjs.ast.js.JsonArray; 25 import com.google.gwt.dev.jjs.ast.js.JsonObject; 26 import com.google.gwt.dev.jjs.ast.js.JsonObject.JsonPropInit; 27 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 34 public class JVisitor { 35 36 protected static final Context UNMODIFIABLE_CONTEXT = new Context() { 37 38 public boolean canInsert() { 39 return false; 40 } 41 42 public boolean canRemove() { 43 return false; 44 } 45 46 public void insertAfter(JNode node) { 47 throw new UnsupportedOperationException (); 48 } 49 50 public void insertBefore(JNode node) { 51 throw new UnsupportedOperationException (); 52 } 53 54 public void removeMe() { 55 throw new UnsupportedOperationException (); 56 } 57 58 public void replaceMe(JNode node) { 59 throw new UnsupportedOperationException (); 60 } 61 62 }; 63 64 public final JExpression accept(JExpression node) { 65 return (JExpression) doAccept(node); 66 } 67 68 public final JNode accept(JNode node) { 69 return doAccept(node); 70 } 71 72 public final JStatement accept(JStatement node) { 73 return (JStatement) doAccept(node); 74 } 75 76 public final void accept(List list) { 77 doAccept(list); 78 } 79 80 public final void acceptWithInsertRemove(List list) { 81 doAcceptWithInsertRemove(list); 82 } 83 84 public boolean didChange() { 85 throw new UnsupportedOperationException (); 86 } 87 88 public void endVisit(JAbsentArrayDimension x, Context ctx) { 89 } 90 91 public void endVisit(JArrayRef x, Context ctx) { 92 } 93 94 public void endVisit(JArrayType x, Context ctx) { 95 } 96 97 public void endVisit(JAssertStatement x, Context ctx) { 98 } 99 100 public void endVisit(JBinaryOperation x, Context ctx) { 101 } 102 103 public void endVisit(JBlock x, Context ctx) { 104 } 105 106 public void endVisit(JBooleanLiteral x, Context ctx) { 107 } 108 109 public void endVisit(JBreakStatement x, Context ctx) { 110 } 111 112 public void endVisit(JCaseStatement x, Context ctx) { 113 } 114 115 public void endVisit(JCastOperation x, Context ctx) { 116 } 117 118 public void endVisit(JCharLiteral x, Context ctx) { 119 } 120 121 public void endVisit(JClassLiteral x, Context ctx) { 122 } 123 124 public void endVisit(JClassSeed x, Context ctx) { 125 } 126 127 public void endVisit(JClassType x, Context ctx) { 128 } 129 130 public void endVisit(JConditional x, Context ctx) { 131 } 132 133 public void endVisit(JContinueStatement x, Context ctx) { 134 } 135 136 public void endVisit(JDoStatement x, Context ctx) { 137 } 138 139 public void endVisit(JDoubleLiteral x, Context ctx) { 140 } 141 142 public void endVisit(JExpressionStatement x, Context ctx) { 143 } 144 145 public void endVisit(JField x, Context ctx) { 146 } 147 148 public void endVisit(JFieldRef x, Context ctx) { 149 } 150 151 public void endVisit(JFloatLiteral x, Context ctx) { 152 } 153 154 public void endVisit(JForStatement x, Context ctx) { 155 } 156 157 public void endVisit(JIfStatement x, Context ctx) { 158 } 159 160 public void endVisit(JInstanceOf x, Context ctx) { 161 } 162 163 public void endVisit(JInterfaceType x, Context ctx) { 164 } 165 166 public void endVisit(JIntLiteral x, Context ctx) { 167 } 168 169 public void endVisit(JLabel x, Context ctx) { 170 } 171 172 public void endVisit(JLabeledStatement x, Context ctx) { 173 } 174 175 public void endVisit(JLocal x, Context ctx) { 176 } 177 178 public void endVisit(JLocalDeclarationStatement x, Context ctx) { 179 } 180 181 public void endVisit(JLocalRef x, Context ctx) { 182 } 183 184 public void endVisit(JLongLiteral x, Context ctx) { 185 } 186 187 public void endVisit(JMethod x, Context ctx) { 188 } 189 190 public void endVisit(JMethodCall x, Context ctx) { 191 } 192 193 public void endVisit(JMultiExpression x, Context ctx) { 194 } 195 196 public void endVisit(JNewArray x, Context ctx) { 197 } 198 199 public void endVisit(JNewInstance x, Context ctx) { 200 } 201 202 public void endVisit(JNullLiteral x, Context ctx) { 203 } 204 205 public void endVisit(JNullType x, Context ctx) { 206 } 207 208 public void endVisit(JParameter x, Context ctx) { 209 } 210 211 public void endVisit(JParameterRef x, Context ctx) { 212 } 213 214 public void endVisit(JPostfixOperation x, Context ctx) { 215 } 216 217 public void endVisit(JPrefixOperation x, Context ctx) { 218 } 219 220 public void endVisit(JPrimitiveType x, Context ctx) { 221 } 222 223 public void endVisit(JProgram x, Context ctx) { 224 } 225 226 public void endVisit(JReturnStatement x, Context ctx) { 227 } 228 229 public void endVisit(JsniFieldRef x, Context ctx) { 230 } 231 232 public void endVisit(JsniMethod x, Context ctx) { 233 } 234 235 public void endVisit(JsniMethodRef x, Context ctx) { 236 } 237 238 public void endVisit(JsonArray x, Context ctx) { 239 } 240 241 public void endVisit(JsonObject x, Context ctx) { 242 } 243 244 public void endVisit(JsonPropInit x, Context ctx) { 245 } 246 247 public void endVisit(JStringLiteral x, Context ctx) { 248 } 249 250 public void endVisit(JSwitchStatement x, Context ctx) { 251 } 252 253 public void endVisit(JThisRef x, Context ctx) { 254 } 255 256 public void endVisit(JThrowStatement x, Context ctx) { 257 } 258 259 public void endVisit(JTryStatement x, Context ctx) { 260 } 261 262 public void endVisit(JWhileStatement x, Context ctx) { 263 } 264 265 public boolean visit(JAbsentArrayDimension x, Context ctx) { 266 return true; 267 } 268 269 public boolean visit(JArrayRef x, Context ctx) { 270 return true; 271 } 272 273 public boolean visit(JArrayType x, Context ctx) { 274 return true; 275 } 276 277 public boolean visit(JAssertStatement x, Context ctx) { 278 return true; 279 } 280 281 public boolean visit(JBinaryOperation x, Context ctx) { 282 return true; 283 } 284 285 public boolean visit(JBlock x, Context ctx) { 286 return true; 287 } 288 289 public boolean visit(JBooleanLiteral x, Context ctx) { 290 return true; 291 } 292 293 public boolean visit(JBreakStatement x, Context ctx) { 294 return true; 295 } 296 297 public boolean visit(JCaseStatement x, Context ctx) { 298 return true; 299 } 300 301 public boolean visit(JCastOperation x, Context ctx) { 302 return true; 303 } 304 305 public boolean visit(JCharLiteral x, Context ctx) { 306 return true; 307 } 308 309 public boolean visit(JClassLiteral x, Context ctx) { 310 return true; 311 } 312 313 public boolean visit(JClassSeed x, Context ctx) { 314 return true; 315 } 316 317 public boolean visit(JClassType x, Context ctx) { 318 return true; 319 } 320 321 public boolean visit(JConditional x, Context ctx) { 322 return true; 323 } 324 325 public boolean visit(JContinueStatement x, Context ctx) { 326 return true; 327 } 328 329 public boolean visit(JDoStatement x, Context ctx) { 330 return true; 331 } 332 333 public boolean visit(JDoubleLiteral x, Context ctx) { 334 return true; 335 } 336 337 public boolean visit(JExpressionStatement x, Context ctx) { 338 return true; 339 } 340 341 public boolean visit(JField x, Context ctx) { 342 return true; 343 } 344 345 public boolean visit(JFieldRef x, Context ctx) { 346 return true; 347 } 348 349 public boolean visit(JFloatLiteral x, Context ctx) { 350 return true; 351 } 352 353 public boolean visit(JForStatement x, Context ctx) { 354 return true; 355 } 356 357 public boolean visit(JIfStatement x, Context ctx) { 358 return true; 359 } 360 361 public boolean visit(JInstanceOf x, Context ctx) { 362 return true; 363 } 364 365 public boolean visit(JInterfaceType x, Context ctx) { 366 return true; 367 } 368 369 public boolean visit(JIntLiteral x, Context ctx) { 370 return true; 371 } 372 373 public boolean visit(JLabel x, Context ctx) { 374 return true; 375 } 376 377 public boolean visit(JLabeledStatement x, Context ctx) { 378 return true; 379 } 380 381 public boolean visit(JLocal x, Context ctx) { 382 return true; 383 } 384 385 public boolean visit(JLocalDeclarationStatement x, Context ctx) { 386 return true; 387 } 388 389 public boolean visit(JLocalRef x, Context ctx) { 390 return true; 391 } 392 393 public boolean visit(JLongLiteral x, Context ctx) { 394 return true; 395 } 396 397 public boolean visit(JMethod x, Context ctx) { 398 return true; 399 } 400 401 public boolean visit(JMethodCall x, Context ctx) { 402 return true; 403 } 404 405 public boolean visit(JMultiExpression x, Context ctx) { 406 return true; 407 } 408 409 public boolean visit(JNewArray x, Context ctx) { 410 return true; 411 } 412 413 public boolean visit(JNewInstance x, Context ctx) { 414 return true; 415 } 416 417 public boolean visit(JNullLiteral x, Context ctx) { 418 return true; 419 } 420 421 public boolean visit(JNullType x, Context ctx) { 422 return true; 423 } 424 425 public boolean visit(JParameter x, Context ctx) { 426 return true; 427 } 428 429 public boolean visit(JParameterRef x, Context ctx) { 430 return true; 431 } 432 433 public boolean visit(JPostfixOperation x, Context ctx) { 434 return true; 435 } 436 437 public boolean visit(JPrefixOperation x, Context ctx) { 438 return true; 439 } 440 441 public boolean visit(JPrimitiveType x, Context ctx) { 442 return true; 443 } 444 445 public boolean visit(JProgram x, Context ctx) { 446 return true; 447 } 448 449 public boolean visit(JReturnStatement x, Context ctx) { 450 return true; 451 } 452 453 public boolean visit(JsniFieldRef x, Context ctx) { 454 return true; 455 } 456 457 public boolean visit(JsniMethod x, Context ctx) { 458 return true; 459 } 460 461 public boolean visit(JsniMethodRef x, Context ctx) { 462 return true; 463 } 464 465 public boolean visit(JsonArray x, Context ctx) { 466 return true; 467 } 468 469 public boolean visit(JsonObject x, Context ctx) { 470 return true; 471 } 472 473 public boolean visit(JsonPropInit x, Context ctx) { 474 return true; 475 } 476 477 public boolean visit(JStringLiteral x, Context ctx) { 478 return true; 479 } 480 481 public boolean visit(JSwitchStatement x, Context ctx) { 482 return true; 483 } 484 485 public boolean visit(JThisRef x, Context ctx) { 486 return true; 487 } 488 489 public boolean visit(JThrowStatement x, Context ctx) { 490 return true; 491 } 492 493 public boolean visit(JTryStatement x, Context ctx) { 494 return true; 495 } 496 497 public boolean visit(JWhileStatement x, Context ctx) { 498 return true; 499 } 500 501 protected JNode doAccept(JNode node) { 502 doTraverse(node, UNMODIFIABLE_CONTEXT); 503 return node; 504 } 505 506 protected void doAccept(List list) { 507 for (Iterator it = list.iterator(); it.hasNext();) { 508 doTraverse((JNode) it.next(), UNMODIFIABLE_CONTEXT); 509 } 510 } 511 512 protected void doAcceptWithInsertRemove(List list) { 513 for (Iterator it = list.iterator(); it.hasNext();) { 514 doTraverse((JNode) it.next(), UNMODIFIABLE_CONTEXT); 515 } 516 } 517 518 protected final void doTraverse(JNode node, Context ctx) { 519 try { 520 node.traverse(this, ctx); 521 } catch (Throwable e) { 522 throw translateException(node, e); 523 } 524 } 525 526 private InternalCompilerException translateException(JNode node, Throwable e) { 527 InternalCompilerException ice; 528 if (e instanceof InternalCompilerException) { 529 ice = (InternalCompilerException) e; 530 } else { 531 ice = new InternalCompilerException("Unexpected error during visit.", e); 532 } 533 ice.addNode(node); 534 return ice; 535 } 536 } 537 | Popular Tags |