| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 package com.google.dart.compiler.backend.js.ast; | |
| 6 | |
| 7 import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; | |
| 8 | |
| 9 import java.util.Iterator; | |
| 10 import java.util.List; | |
| 11 | |
| 12 /** | |
| 13 * Implemented by nodes that will visit child nodes. | |
| 14 */ | |
| 15 @SuppressWarnings("unused") | |
| 16 public class JsVisitor { | |
| 17 | |
| 18 protected static final JsContext LVALUE_CONTEXT = new JsContext() { | |
| 19 | |
| 20 @Override | |
| 21 public boolean canInsert() { | |
| 22 return false; | |
| 23 } | |
| 24 | |
| 25 @Override | |
| 26 public boolean canRemove() { | |
| 27 return false; | |
| 28 } | |
| 29 | |
| 30 @Override | |
| 31 public void insertAfter(JsVisitable node) { | |
| 32 throw new UnsupportedOperationException(); | |
| 33 } | |
| 34 | |
| 35 @Override | |
| 36 public void insertBefore(JsVisitable node) { | |
| 37 throw new UnsupportedOperationException(); | |
| 38 } | |
| 39 | |
| 40 @Override | |
| 41 public boolean isLvalue() { | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 @Override | |
| 46 public void removeMe() { | |
| 47 throw new UnsupportedOperationException(); | |
| 48 } | |
| 49 | |
| 50 @Override | |
| 51 public void replaceMe(JsVisitable node) { | |
| 52 throw new UnsupportedOperationException(); | |
| 53 } | |
| 54 }; | |
| 55 | |
| 56 protected static final JsContext UNMODIFIABLE_CONTEXT = new JsContext() { | |
| 57 | |
| 58 @Override | |
| 59 public boolean canInsert() { | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 @Override | |
| 64 public boolean canRemove() { | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 @Override | |
| 69 public void insertAfter(JsVisitable node) { | |
| 70 throw new UnsupportedOperationException(); | |
| 71 } | |
| 72 | |
| 73 @Override | |
| 74 public void insertBefore(JsVisitable node) { | |
| 75 throw new UnsupportedOperationException(); | |
| 76 } | |
| 77 | |
| 78 @Override | |
| 79 public boolean isLvalue() { | |
| 80 return false; | |
| 81 } | |
| 82 | |
| 83 @Override | |
| 84 public void removeMe() { | |
| 85 throw new UnsupportedOperationException(); | |
| 86 } | |
| 87 | |
| 88 @Override | |
| 89 public void replaceMe(JsVisitable node) { | |
| 90 throw new UnsupportedOperationException(); | |
| 91 } | |
| 92 }; | |
| 93 | |
| 94 public final <T extends JsVisitable> T accept(T node) { | |
| 95 return this.<T>doAccept(node); | |
| 96 } | |
| 97 | |
| 98 public final <T extends JsVisitable> void acceptList(List<T> collection) { | |
| 99 doAcceptList(collection); | |
| 100 } | |
| 101 | |
| 102 public JsExpression acceptLvalue(JsExpression expr) { | |
| 103 return doAcceptLvalue(expr); | |
| 104 } | |
| 105 | |
| 106 public final <T extends JsVisitable> void acceptWithInsertRemove(List<T> colle
ction) { | |
| 107 doAcceptWithInsertRemove(collection); | |
| 108 } | |
| 109 | |
| 110 public boolean didChange() { | |
| 111 throw new UnsupportedOperationException(); | |
| 112 } | |
| 113 | |
| 114 public void endVisit(JsArrayAccess x, JsContext ctx) { | |
| 115 } | |
| 116 | |
| 117 public void endVisit(JsArrayLiteral x, JsContext ctx) { | |
| 118 } | |
| 119 | |
| 120 public void endVisit(JsBinaryOperation x, JsContext ctx) { | |
| 121 } | |
| 122 | |
| 123 public void endVisit(JsBlock x, JsContext ctx) { | |
| 124 } | |
| 125 | |
| 126 public void endVisit(JsBooleanLiteral x, JsContext ctx) { | |
| 127 } | |
| 128 | |
| 129 public void endVisit(JsBreak x, JsContext ctx) { | |
| 130 } | |
| 131 | |
| 132 public void endVisit(JsCase x, JsContext ctx) { | |
| 133 } | |
| 134 | |
| 135 public void endVisit(JsCatch x, JsContext ctx) { | |
| 136 } | |
| 137 | |
| 138 public void endVisit(JsConditional x, JsContext ctx) { | |
| 139 } | |
| 140 | |
| 141 public void endVisit(JsContinue x, JsContext ctx) { | |
| 142 } | |
| 143 | |
| 144 public void endVisit(JsDebugger x, JsContext ctx) { | |
| 145 } | |
| 146 | |
| 147 public void endVisit(JsDefault x, JsContext ctx) { | |
| 148 } | |
| 149 | |
| 150 public void endVisit(JsDoWhile x, JsContext ctx) { | |
| 151 } | |
| 152 | |
| 153 public void endVisit(JsEmpty x, JsContext ctx) { | |
| 154 } | |
| 155 | |
| 156 public void endVisit(JsExprStmt x, JsContext ctx) { | |
| 157 } | |
| 158 | |
| 159 public void endVisit(JsFor x, JsContext ctx) { | |
| 160 } | |
| 161 | |
| 162 public void endVisit(JsForIn x, JsContext ctx) { | |
| 163 } | |
| 164 | |
| 165 public void endVisit(JsFunction x, JsContext ctx) { | |
| 166 } | |
| 167 | |
| 168 public void endVisit(JsIf x, JsContext ctx) { | |
| 169 } | |
| 170 | |
| 171 public void endVisit(JsInvocation x, JsContext ctx) { | |
| 172 } | |
| 173 | |
| 174 public void endVisit(JsLabel x, JsContext ctx) { | |
| 175 } | |
| 176 | |
| 177 public void endVisit(JsNameRef x, JsContext ctx) { | |
| 178 } | |
| 179 | |
| 180 public void endVisit(JsNew x, JsContext ctx) { | |
| 181 } | |
| 182 | |
| 183 public void endVisit(JsNullLiteral x, JsContext ctx) { | |
| 184 } | |
| 185 | |
| 186 public void endVisit(JsNumberLiteral x, JsContext ctx) { | |
| 187 } | |
| 188 | |
| 189 public void endVisit(JsObjectLiteral x, JsContext ctx) { | |
| 190 } | |
| 191 | |
| 192 public void endVisit(JsParameter x, JsContext ctx) { | |
| 193 } | |
| 194 | |
| 195 public void endVisit(JsPostfixOperation x, JsContext ctx) { | |
| 196 } | |
| 197 | |
| 198 public void endVisit(JsPrefixOperation x, JsContext ctx) { | |
| 199 } | |
| 200 | |
| 201 public void endVisit(JsProgram x, JsContext ctx) { | |
| 202 } | |
| 203 | |
| 204 public void endVisit(JsProgramFragment x, JsContext ctx) { | |
| 205 } | |
| 206 | |
| 207 public void endVisit(JsPropertyInitializer x, JsContext ctx) { | |
| 208 } | |
| 209 | |
| 210 public void endVisit(JsRegExp x, JsContext ctx) { | |
| 211 } | |
| 212 | |
| 213 public void endVisit(JsReturn x, JsContext ctx) { | |
| 214 } | |
| 215 | |
| 216 public void endVisit(JsStringLiteral x, JsContext ctx) { | |
| 217 } | |
| 218 | |
| 219 public void endVisit(JsSwitch x, JsContext ctx) { | |
| 220 } | |
| 221 | |
| 222 public void endVisit(JsThisRef x, JsContext ctx) { | |
| 223 } | |
| 224 | |
| 225 public void endVisit(JsThrow x, JsContext ctx) { | |
| 226 } | |
| 227 | |
| 228 public void endVisit(JsTry x, JsContext ctx) { | |
| 229 } | |
| 230 | |
| 231 public void endVisit(JsVar x, JsContext ctx) { | |
| 232 } | |
| 233 | |
| 234 public void endVisit(JsVars x, JsContext ctx) { | |
| 235 } | |
| 236 | |
| 237 public void endVisit(JsWhile x, JsContext ctx) { | |
| 238 } | |
| 239 | |
| 240 public boolean visit(JsArrayAccess x, JsContext ctx) { | |
| 241 return true; | |
| 242 } | |
| 243 | |
| 244 public boolean visit(JsArrayLiteral x, JsContext ctx) { | |
| 245 return true; | |
| 246 } | |
| 247 | |
| 248 public boolean visit(JsBinaryOperation x, JsContext ctx) { | |
| 249 return true; | |
| 250 } | |
| 251 | |
| 252 public boolean visit(JsBlock x, JsContext ctx) { | |
| 253 return true; | |
| 254 } | |
| 255 | |
| 256 public boolean visit(JsBooleanLiteral x, JsContext ctx) { | |
| 257 return true; | |
| 258 } | |
| 259 | |
| 260 public boolean visit(JsBreak x, JsContext ctx) { | |
| 261 return true; | |
| 262 } | |
| 263 | |
| 264 public boolean visit(JsCase x, JsContext ctx) { | |
| 265 return true; | |
| 266 } | |
| 267 | |
| 268 public boolean visit(JsCatch x, JsContext ctx) { | |
| 269 return true; | |
| 270 } | |
| 271 | |
| 272 public boolean visit(JsConditional x, JsContext ctx) { | |
| 273 return true; | |
| 274 } | |
| 275 | |
| 276 public boolean visit(JsContinue x, JsContext ctx) { | |
| 277 return true; | |
| 278 } | |
| 279 | |
| 280 public boolean visit(JsDebugger x, JsContext ctx) { | |
| 281 return true; | |
| 282 } | |
| 283 | |
| 284 public boolean visit(JsDefault x, JsContext ctx) { | |
| 285 return true; | |
| 286 } | |
| 287 | |
| 288 public boolean visit(JsDoWhile x, JsContext ctx) { | |
| 289 return true; | |
| 290 } | |
| 291 | |
| 292 public boolean visit(JsEmpty x, JsContext ctx) { | |
| 293 return true; | |
| 294 } | |
| 295 | |
| 296 public boolean visit(JsExprStmt x, JsContext ctx) { | |
| 297 return true; | |
| 298 } | |
| 299 | |
| 300 public boolean visit(JsFor x, JsContext ctx) { | |
| 301 return true; | |
| 302 } | |
| 303 | |
| 304 public boolean visit(JsForIn x, JsContext ctx) { | |
| 305 return true; | |
| 306 } | |
| 307 | |
| 308 public boolean visit(JsFunction x, JsContext ctx) { | |
| 309 return true; | |
| 310 } | |
| 311 | |
| 312 public boolean visit(JsIf x, JsContext ctx) { | |
| 313 return true; | |
| 314 } | |
| 315 | |
| 316 public boolean visit(JsInvocation x, JsContext ctx) { | |
| 317 return true; | |
| 318 } | |
| 319 | |
| 320 public boolean visit(JsLabel x, JsContext ctx) { | |
| 321 return true; | |
| 322 } | |
| 323 | |
| 324 public boolean visit(JsNameRef x, JsContext ctx) { | |
| 325 return true; | |
| 326 } | |
| 327 | |
| 328 public boolean visit(JsNew x, JsContext ctx) { | |
| 329 return true; | |
| 330 } | |
| 331 | |
| 332 public boolean visit(JsNullLiteral x, JsContext ctx) { | |
| 333 return true; | |
| 334 } | |
| 335 | |
| 336 public boolean visit(JsNumberLiteral x, JsContext ctx) { | |
| 337 return true; | |
| 338 } | |
| 339 | |
| 340 public boolean visit(JsObjectLiteral x, JsContext ctx) { | |
| 341 return true; | |
| 342 } | |
| 343 | |
| 344 public boolean visit(JsParameter x, JsContext ctx) { | |
| 345 return true; | |
| 346 } | |
| 347 | |
| 348 public boolean visit(JsPostfixOperation x, JsContext ctx) { | |
| 349 return true; | |
| 350 } | |
| 351 | |
| 352 public boolean visit(JsPrefixOperation x, JsContext ctx) { | |
| 353 return true; | |
| 354 } | |
| 355 | |
| 356 public boolean visit(JsProgram x, JsContext ctx) { | |
| 357 return true; | |
| 358 } | |
| 359 | |
| 360 public boolean visit(JsProgramFragment x, JsContext ctx) { | |
| 361 return true; | |
| 362 } | |
| 363 | |
| 364 public boolean visit(JsPropertyInitializer x, JsContext ctx) { | |
| 365 return true; | |
| 366 } | |
| 367 | |
| 368 public boolean visit(JsRegExp x, JsContext ctx) { | |
| 369 return true; | |
| 370 } | |
| 371 | |
| 372 public boolean visit(JsReturn x, JsContext ctx) { | |
| 373 return true; | |
| 374 } | |
| 375 | |
| 376 public boolean visit(JsStringLiteral x, JsContext ctx) { | |
| 377 return true; | |
| 378 } | |
| 379 | |
| 380 public boolean visit(JsSwitch x, JsContext ctx) { | |
| 381 return true; | |
| 382 } | |
| 383 | |
| 384 public boolean visit(JsThisRef x, JsContext ctx) { | |
| 385 return true; | |
| 386 } | |
| 387 | |
| 388 public boolean visit(JsThrow x, JsContext ctx) { | |
| 389 return true; | |
| 390 } | |
| 391 | |
| 392 public boolean visit(JsTry x, JsContext ctx) { | |
| 393 return true; | |
| 394 } | |
| 395 | |
| 396 public boolean visit(JsVar x, JsContext ctx) { | |
| 397 return true; | |
| 398 } | |
| 399 | |
| 400 public boolean visit(JsVars x, JsContext ctx) { | |
| 401 return true; | |
| 402 } | |
| 403 | |
| 404 public boolean visit(JsWhile x, JsContext ctx) { | |
| 405 return true; | |
| 406 } | |
| 407 | |
| 408 protected <T extends JsVisitable> T doAccept(T node) { | |
| 409 doTraverse(node, UNMODIFIABLE_CONTEXT); | |
| 410 return node; | |
| 411 } | |
| 412 | |
| 413 protected <T extends JsVisitable> void doAcceptList(List<T> collection) { | |
| 414 for (T node : collection) { | |
| 415 doTraverse(node, UNMODIFIABLE_CONTEXT); | |
| 416 } | |
| 417 } | |
| 418 | |
| 419 protected JsExpression doAcceptLvalue(JsExpression expr) { | |
| 420 doTraverse(expr, LVALUE_CONTEXT); | |
| 421 return expr; | |
| 422 } | |
| 423 | |
| 424 protected <T extends JsVisitable> void doAcceptWithInsertRemove(List<T> collec
tion) { | |
| 425 for (T node : collection) { | |
| 426 doTraverse(node, UNMODIFIABLE_CONTEXT); | |
| 427 } | |
| 428 } | |
| 429 | |
| 430 protected void doTraverse(JsVisitable node, JsContext ctx) { | |
| 431 node.traverse(this, ctx); | |
| 432 } | |
| 433 } | |
| OLD | NEW |