1 /* 2 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.source.util; 27 28 import com.sun.source.tree.*; 29 30 /** 31 * A TreeVisitor that visits all the child tree nodes. 32 * To visit nodes of a particular type, just override the 33 * corresponding visitXYZ method. 34 * Inside your method, call super.visitXYZ to visit descendant 35 * nodes. 36 * 37 * <p>The default implementation of the visitXYZ methods will determine 38 * a result as follows: 39 * <ul> 40 * <li>If the node being visited has no children, the result will be {@code null}. 41 * <li>If the node being visited has one child, the result will be the 42 * result of calling {@code scan} on that child. The child may be a simple node 43 * or itself a list of nodes. 44 * <li> If the node being visited has more than one child, the result will 45 * be determined by calling {@code scan} each child in turn, and then combining the 46 * result of each scan after the first with the cumulative result 47 * so far, as determined by the {@link #reduce} method. Each child may be either 48 * a simple node of a list of nodes. The default behavior of the {@code reduce} 49 * method is such that the result of the visitXYZ method will be the result of 50 * the last child scanned. 51 * </ul> 52 * 53 * <p>Here is an example to count the number of identifier nodes in a tree: 54 * <pre> 55 * class CountIdentifiers extends TreeScanner<Integer,Void> { 56 * {@literal @}Override 57 * public Integer visitIdentifier(IdentifierTree node, Void p) { 58 * return 1; 59 * } 60 * {@literal @}Override 61 * public Integer reduce(Integer r1, Integer r2) { 62 * return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2); 63 * } 64 * } 65 * </pre> 66 * 67 * @param <R> the return type of this visitor's methods. Use {@link 68 * Void} for visitors that do not need to return results. 69 * @param <P> the type of the additional parameter to this visitor's 70 * methods. Use {@code Void} for visitors that do not need an 71 * additional parameter. 72 * 73 * @author Peter von der Ahé 74 * @author Jonathan Gibbons 75 * @since 1.6 76 */ 77 public class TreeScanner<R,P> implements TreeVisitor<R,P> { 78 79 /** 80 * Scans a single node. 81 * @param tree the node to be scanned 82 * @param p a parameter value passed to the visit method 83 * @return the result value from the visit method 84 */ 85 public R scan(Tree tree, P p) { 86 return (tree == null) ? null : tree.accept(this, p); 87 } 88 89 private R scanAndReduce(Tree node, P p, R r) { 90 return reduce(scan(node, p), r); 91 } 92 93 /** 94 * Scans a sequence of nodes. 95 * @param nodes the nodes to be scanned 96 * @param p a parameter value to be passed to the visit method for each node 97 * @return the combined return value from the visit methods. 98 * The values are combined using the {@link #reduce reduce} method. 99 */ 100 public R scan(Iterable<? extends Tree> nodes, P p) { 101 R r = null; 102 if (nodes != null) { 103 boolean first = true; 104 for (Tree node : nodes) { 105 r = (first ? scan(node, p) : scanAndReduce(node, p, r)); 106 first = false; 107 } 108 } 109 return r; 110 } 111 112 private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) { 113 return reduce(scan(nodes, p), r); 114 } 115 116 /** 117 * Reduces two results into a combined result. 118 * The default implementation is to return the first parameter. 119 * The general contract of the method is that it may take any action whatsoever. 120 * @param r1 the first of the values to be combined 121 * @param r2 the second of the values to be combined 122 * @return the result of combining the two parameters 123 */ 124 public R reduce(R r1, R r2) { 125 return r1; 126 } 127 128 129 /* *************************************************************************** 130 * Visitor methods 131 ****************************************************************************/ 132 133 /** 134 * {@inheritDoc} This implementation scans the children in left to right order. 135 * 136 * @param node {@inheritDoc} 137 * @param p {@inheritDoc} 138 * @return the result of scanning 139 */ 140 @Override 141 public R visitCompilationUnit(CompilationUnitTree node, P p) { 142 R r = scan(node.getPackage(), p); 143 r = scanAndReduce(node.getImports(), p, r); 144 r = scanAndReduce(node.getTypeDecls(), p, r); 145 return r; 146 } 147 148 /** 149 * {@inheritDoc} This implementation scans the children in left to right order. 150 * 151 * @param node {@inheritDoc} 152 * @param p {@inheritDoc} 153 * @return the result of scanning 154 */ 155 @Override 156 public R visitPackage(PackageTree node, P p) { 157 R r = scan(node.getAnnotations(), p); 158 r = scanAndReduce(node.getPackageName(), p, r); 159 return r; 160 } 161 162 /** 163 * {@inheritDoc} This implementation scans the children in left to right order. 164 * 165 * @param node {@inheritDoc} 166 * @param p {@inheritDoc} 167 * @return the result of scanning 168 */ 169 @Override 170 public R visitImport(ImportTree node, P p) { 171 return scan(node.getQualifiedIdentifier(), p); 172 } 173 174 /** 175 * {@inheritDoc} This implementation scans the children in left to right order. 176 * 177 * @param node {@inheritDoc} 178 * @param p {@inheritDoc} 179 * @return the result of scanning 180 */ 181 @Override 182 public R visitClass(ClassTree node, P p) { 183 R r = scan(node.getModifiers(), p); 184 r = scanAndReduce(node.getTypeParameters(), p, r); 185 r = scanAndReduce(node.getExtendsClause(), p, r); 186 r = scanAndReduce(node.getImplementsClause(), p, r); 187 r = scanAndReduce(node.getMembers(), p, r); 188 return r; 189 } 190 191 /** 192 * {@inheritDoc} This implementation scans the children in left to right order. 193 * 194 * @param node {@inheritDoc} 195 * @param p {@inheritDoc} 196 * @return the result of scanning 197 */ 198 @Override 199 public R visitMethod(MethodTree node, P p) { 200 R r = scan(node.getModifiers(), p); 201 r = scanAndReduce(node.getReturnType(), p, r); 202 r = scanAndReduce(node.getTypeParameters(), p, r); 203 r = scanAndReduce(node.getParameters(), p, r); 204 r = scanAndReduce(node.getReceiverParameter(), p, r); 205 r = scanAndReduce(node.getThrows(), p, r); 206 r = scanAndReduce(node.getBody(), p, r); 207 r = scanAndReduce(node.getDefaultValue(), p, r); 208 return r; 209 } 210 211 /** 212 * {@inheritDoc} This implementation scans the children in left to right order. 213 * 214 * @param node {@inheritDoc} 215 * @param p {@inheritDoc} 216 * @return the result of scanning 217 */ 218 @Override 219 public R visitVariable(VariableTree node, P p) { 220 R r = scan(node.getModifiers(), p); 221 r = scanAndReduce(node.getType(), p, r); 222 r = scanAndReduce(node.getNameExpression(), p, r); 223 r = scanAndReduce(node.getInitializer(), p, r); 224 return r; 225 } 226 227 /** 228 * {@inheritDoc} This implementation returns {@code null}. 229 * 230 * @param node {@inheritDoc} 231 * @param p {@inheritDoc} 232 * @return the result of scanning 233 */ 234 @Override 235 public R visitEmptyStatement(EmptyStatementTree node, P p) { 236 return null; 237 } 238 239 /** 240 * {@inheritDoc} This implementation scans the children in left to right order. 241 * 242 * @param node {@inheritDoc} 243 * @param p {@inheritDoc} 244 * @return the result of scanning 245 */ 246 @Override 247 public R visitBlock(BlockTree node, P p) { 248 return scan(node.getStatements(), p); 249 } 250 251 /** 252 * {@inheritDoc} This implementation scans the children in left to right order. 253 * 254 * @param node {@inheritDoc} 255 * @param p {@inheritDoc} 256 * @return the result of scanning 257 */ 258 @Override 259 public R visitDoWhileLoop(DoWhileLoopTree node, P p) { 260 R r = scan(node.getStatement(), p); 261 r = scanAndReduce(node.getCondition(), p, r); 262 return r; 263 } 264 265 /** 266 * {@inheritDoc} This implementation scans the children in left to right order. 267 * 268 * @param node {@inheritDoc} 269 * @param p {@inheritDoc} 270 * @return the result of scanning 271 */ 272 @Override 273 public R visitWhileLoop(WhileLoopTree node, P p) { 274 R r = scan(node.getCondition(), p); 275 r = scanAndReduce(node.getStatement(), p, r); 276 return r; 277 } 278 279 /** 280 * {@inheritDoc} This implementation scans the children in left to right order. 281 * 282 * @param node {@inheritDoc} 283 * @param p {@inheritDoc} 284 * @return the result of scanning 285 */ 286 @Override 287 public R visitForLoop(ForLoopTree node, P p) { 288 R r = scan(node.getInitializer(), p); 289 r = scanAndReduce(node.getCondition(), p, r); 290 r = scanAndReduce(node.getUpdate(), p, r); 291 r = scanAndReduce(node.getStatement(), p, r); 292 return r; 293 } 294 295 /** 296 * {@inheritDoc} This implementation scans the children in left to right order. 297 * 298 * @param node {@inheritDoc} 299 * @param p {@inheritDoc} 300 * @return the result of scanning 301 */ 302 @Override 303 public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) { 304 R r = scan(node.getVariable(), p); 305 r = scanAndReduce(node.getExpression(), p, r); 306 r = scanAndReduce(node.getStatement(), p, r); 307 return r; 308 } 309 310 /** 311 * {@inheritDoc} This implementation scans the children in left to right order. 312 * 313 * @param node {@inheritDoc} 314 * @param p {@inheritDoc} 315 * @return the result of scanning 316 */ 317 @Override 318 public R visitLabeledStatement(LabeledStatementTree node, P p) { 319 return scan(node.getStatement(), p); 320 } 321 322 /** 323 * {@inheritDoc} This implementation scans the children in left to right order. 324 * 325 * @param node {@inheritDoc} 326 * @param p {@inheritDoc} 327 * @return the result of scanning 328 */ 329 @Override 330 public R visitSwitch(SwitchTree node, P p) { 331 R r = scan(node.getExpression(), p); 332 r = scanAndReduce(node.getCases(), p, r); 333 return r; 334 } 335 336 /** 337 * {@inheritDoc} This implementation scans the children in left to right order. 338 * 339 * @param node {@inheritDoc} 340 * @param p {@inheritDoc} 341 * @return the result of scanning 342 */ 343 @Override 344 public R visitSwitchExpression(SwitchExpressionTree node, P p) { 345 R r = scan(node.getExpression(), p); 346 r = scanAndReduce(node.getCases(), p, r); 347 return r; 348 } 349 350 /** 351 * {@inheritDoc} This implementation scans the children in left to right order. 352 * 353 * @param node {@inheritDoc} 354 * @param p {@inheritDoc} 355 * @return the result of scanning 356 */ 357 @Override 358 public R visitCase(CaseTree node, P p) { 359 R r = scan(node.getExpressions(), p); 360 if (node.getCaseKind() == CaseTree.CaseKind.RULE) 361 r = scanAndReduce(node.getBody(), p, r); 362 else 363 r = scanAndReduce(node.getStatements(), p, r); 364 return r; 365 } 366 367 /** 368 * {@inheritDoc} This implementation scans the children in left to right order. 369 * 370 * @param node {@inheritDoc} 371 * @param p {@inheritDoc} 372 * @return the result of scanning 373 */ 374 @Override 375 public R visitSynchronized(SynchronizedTree node, P p) { 376 R r = scan(node.getExpression(), p); 377 r = scanAndReduce(node.getBlock(), p, r); 378 return r; 379 } 380 381 /** 382 * {@inheritDoc} This implementation scans the children in left to right order. 383 * 384 * @param node {@inheritDoc} 385 * @param p {@inheritDoc} 386 * @return the result of scanning 387 */ 388 @Override 389 public R visitTry(TryTree node, P p) { 390 R r = scan(node.getResources(), p); 391 r = scanAndReduce(node.getBlock(), p, r); 392 r = scanAndReduce(node.getCatches(), p, r); 393 r = scanAndReduce(node.getFinallyBlock(), p, r); 394 return r; 395 } 396 397 /** 398 * {@inheritDoc} This implementation scans the children in left to right order. 399 * 400 * @param node {@inheritDoc} 401 * @param p {@inheritDoc} 402 * @return the result of scanning 403 */ 404 @Override 405 public R visitCatch(CatchTree node, P p) { 406 R r = scan(node.getParameter(), p); 407 r = scanAndReduce(node.getBlock(), p, r); 408 return r; 409 } 410 411 /** 412 * {@inheritDoc} This implementation scans the children in left to right order. 413 * 414 * @param node {@inheritDoc} 415 * @param p {@inheritDoc} 416 * @return the result of scanning 417 */ 418 @Override 419 public R visitConditionalExpression(ConditionalExpressionTree node, P p) { 420 R r = scan(node.getCondition(), p); 421 r = scanAndReduce(node.getTrueExpression(), p, r); 422 r = scanAndReduce(node.getFalseExpression(), p, r); 423 return r; 424 } 425 426 /** 427 * {@inheritDoc} This implementation scans the children in left to right order. 428 * 429 * @param node {@inheritDoc} 430 * @param p {@inheritDoc} 431 * @return the result of scanning 432 */ 433 @Override 434 public R visitIf(IfTree node, P p) { 435 R r = scan(node.getCondition(), p); 436 r = scanAndReduce(node.getThenStatement(), p, r); 437 r = scanAndReduce(node.getElseStatement(), p, r); 438 return r; 439 } 440 441 /** 442 * {@inheritDoc} This implementation scans the children in left to right order. 443 * 444 * @param node {@inheritDoc} 445 * @param p {@inheritDoc} 446 * @return the result of scanning 447 */ 448 @Override 449 public R visitExpressionStatement(ExpressionStatementTree node, P p) { 450 return scan(node.getExpression(), p); 451 } 452 453 /** 454 * {@inheritDoc} This implementation returns {@code null}. 455 * 456 * @param node {@inheritDoc} 457 * @param p {@inheritDoc} 458 * @return the result of scanning 459 */ 460 @Override 461 public R visitBreak(BreakTree node, P p) { 462 return null; 463 } 464 465 /** 466 * {@inheritDoc} This implementation returns {@code null}. 467 * 468 * @param node {@inheritDoc} 469 * @param p {@inheritDoc} 470 * @return the result of scanning 471 */ 472 @Override 473 public R visitContinue(ContinueTree node, P p) { 474 return null; 475 } 476 477 /** 478 * {@inheritDoc} This implementation scans the children in left to right order. 479 * 480 * @param node {@inheritDoc} 481 * @param p {@inheritDoc} 482 * @return the result of scanning 483 */ 484 @Override 485 public R visitReturn(ReturnTree node, P p) { 486 return scan(node.getExpression(), p); 487 } 488 489 /** 490 * {@inheritDoc} This implementation scans the children in left to right order. 491 * 492 * @param node {@inheritDoc} 493 * @param p {@inheritDoc} 494 * @return the result of scanning 495 */ 496 @Override 497 public R visitThrow(ThrowTree node, P p) { 498 return scan(node.getExpression(), p); 499 } 500 501 /** 502 * {@inheritDoc} This implementation scans the children in left to right order. 503 * 504 * @param node {@inheritDoc} 505 * @param p {@inheritDoc} 506 * @return the result of scanning 507 */ 508 @Override 509 public R visitAssert(AssertTree node, P p) { 510 R r = scan(node.getCondition(), p); 511 r = scanAndReduce(node.getDetail(), p, r); 512 return r; 513 } 514 515 /** 516 * {@inheritDoc} This implementation scans the children in left to right order. 517 * 518 * @param node {@inheritDoc} 519 * @param p {@inheritDoc} 520 * @return the result of scanning 521 */ 522 @Override 523 public R visitMethodInvocation(MethodInvocationTree node, P p) { 524 R r = scan(node.getTypeArguments(), p); 525 r = scanAndReduce(node.getMethodSelect(), p, r); 526 r = scanAndReduce(node.getArguments(), p, r); 527 return r; 528 } 529 530 /** 531 * {@inheritDoc} This implementation scans the children in left to right order. 532 * 533 * @param node {@inheritDoc} 534 * @param p {@inheritDoc} 535 * @return the result of scanning 536 */ 537 @Override 538 public R visitNewClass(NewClassTree node, P p) { 539 R r = scan(node.getEnclosingExpression(), p); 540 r = scanAndReduce(node.getIdentifier(), p, r); 541 r = scanAndReduce(node.getTypeArguments(), p, r); 542 r = scanAndReduce(node.getArguments(), p, r); 543 r = scanAndReduce(node.getClassBody(), p, r); 544 return r; 545 } 546 547 /** 548 * {@inheritDoc} This implementation scans the children in left to right order. 549 * 550 * @param node {@inheritDoc} 551 * @param p {@inheritDoc} 552 * @return the result of scanning 553 */ 554 @Override 555 public R visitNewArray(NewArrayTree node, P p) { 556 R r = scan(node.getType(), p); 557 r = scanAndReduce(node.getDimensions(), p, r); 558 r = scanAndReduce(node.getInitializers(), p, r); 559 r = scanAndReduce(node.getAnnotations(), p, r); 560 for (Iterable< ? extends Tree> dimAnno : node.getDimAnnotations()) { 561 r = scanAndReduce(dimAnno, p, r); 562 } 563 return r; 564 } 565 566 /** 567 * {@inheritDoc} This implementation scans the children in left to right order. 568 * 569 * @param node {@inheritDoc} 570 * @param p {@inheritDoc} 571 * @return the result of scanning 572 */ 573 @Override 574 public R visitLambdaExpression(LambdaExpressionTree node, P p) { 575 R r = scan(node.getParameters(), p); 576 r = scanAndReduce(node.getBody(), p, r); 577 return r; 578 } 579 580 /** 581 * {@inheritDoc} This implementation scans the children in left to right order. 582 * 583 * @param node {@inheritDoc} 584 * @param p {@inheritDoc} 585 * @return the result of scanning 586 */ 587 @Override 588 public R visitParenthesized(ParenthesizedTree node, P p) { 589 return scan(node.getExpression(), p); 590 } 591 592 /** 593 * {@inheritDoc} This implementation scans the children in left to right order. 594 * 595 * @param node {@inheritDoc} 596 * @param p {@inheritDoc} 597 * @return the result of scanning 598 */ 599 @Override 600 public R visitAssignment(AssignmentTree node, P p) { 601 R r = scan(node.getVariable(), p); 602 r = scanAndReduce(node.getExpression(), p, r); 603 return r; 604 } 605 606 /** 607 * {@inheritDoc} This implementation scans the children in left to right order. 608 * 609 * @param node {@inheritDoc} 610 * @param p {@inheritDoc} 611 * @return the result of scanning 612 */ 613 @Override 614 public R visitCompoundAssignment(CompoundAssignmentTree node, P p) { 615 R r = scan(node.getVariable(), p); 616 r = scanAndReduce(node.getExpression(), p, r); 617 return r; 618 } 619 620 /** 621 * {@inheritDoc} This implementation scans the children in left to right order. 622 * 623 * @param node {@inheritDoc} 624 * @param p {@inheritDoc} 625 * @return the result of scanning 626 */ 627 @Override 628 public R visitUnary(UnaryTree node, P p) { 629 return scan(node.getExpression(), p); 630 } 631 632 /** 633 * {@inheritDoc} This implementation scans the children in left to right order. 634 * 635 * @param node {@inheritDoc} 636 * @param p {@inheritDoc} 637 * @return the result of scanning 638 */ 639 @Override 640 public R visitBinary(BinaryTree node, P p) { 641 R r = scan(node.getLeftOperand(), p); 642 r = scanAndReduce(node.getRightOperand(), p, r); 643 return r; 644 } 645 646 /** 647 * {@inheritDoc} This implementation scans the children in left to right order. 648 * 649 * @param node {@inheritDoc} 650 * @param p {@inheritDoc} 651 * @return the result of scanning 652 */ 653 @Override 654 public R visitTypeCast(TypeCastTree node, P p) { 655 R r = scan(node.getType(), p); 656 r = scanAndReduce(node.getExpression(), p, r); 657 return r; 658 } 659 660 /** 661 * {@inheritDoc} This implementation scans the children in left to right order. 662 * 663 * @param node {@inheritDoc} 664 * @param p {@inheritDoc} 665 * @return the result of scanning 666 */ 667 @Override 668 public R visitInstanceOf(InstanceOfTree node, P p) { 669 R r = scan(node.getExpression(), p); 670 r = scanAndReduce(node.getType(), p, r); 671 return r; 672 } 673 674 /** 675 * {@inheritDoc} This implementation scans the children in left to right order. 676 * 677 * @param node {@inheritDoc} 678 * @param p {@inheritDoc} 679 * @return the result of scanning 680 */ 681 @Override 682 public R visitArrayAccess(ArrayAccessTree node, P p) { 683 R r = scan(node.getExpression(), p); 684 r = scanAndReduce(node.getIndex(), p, r); 685 return r; 686 } 687 688 /** 689 * {@inheritDoc} This implementation scans the children in left to right order. 690 * 691 * @param node {@inheritDoc} 692 * @param p {@inheritDoc} 693 * @return the result of scanning 694 */ 695 @Override 696 public R visitMemberSelect(MemberSelectTree node, P p) { 697 return scan(node.getExpression(), p); 698 } 699 700 /** 701 * {@inheritDoc} This implementation scans the children in left to right order. 702 * 703 * @param node {@inheritDoc} 704 * @param p {@inheritDoc} 705 * @return the result of scanning 706 */ 707 @Override 708 public R visitMemberReference(MemberReferenceTree node, P p) { 709 R r = scan(node.getQualifierExpression(), p); 710 r = scanAndReduce(node.getTypeArguments(), p, r); 711 return r; 712 } 713 714 /** 715 * {@inheritDoc} This implementation returns {@code null}. 716 * 717 * @param node {@inheritDoc} 718 * @param p {@inheritDoc} 719 * @return the result of scanning 720 */ 721 @Override 722 public R visitIdentifier(IdentifierTree node, P p) { 723 return null; 724 } 725 726 /** 727 * {@inheritDoc} This implementation returns {@code null}. 728 * 729 * @param node {@inheritDoc} 730 * @param p {@inheritDoc} 731 * @return the result of scanning 732 */ 733 @Override 734 public R visitLiteral(LiteralTree node, P p) { 735 return null; 736 } 737 738 /** 739 * {@inheritDoc} This implementation returns {@code null}. 740 * 741 * @param node {@inheritDoc} 742 * @param p {@inheritDoc} 743 * @return the result of scanning 744 */ 745 @Override 746 public R visitPrimitiveType(PrimitiveTypeTree node, P p) { 747 return null; 748 } 749 750 /** 751 * {@inheritDoc} This implementation scans the children in left to right order. 752 * 753 * @param node {@inheritDoc} 754 * @param p {@inheritDoc} 755 * @return the result of scanning 756 */ 757 @Override 758 public R visitArrayType(ArrayTypeTree node, P p) { 759 return scan(node.getType(), p); 760 } 761 762 /** 763 * {@inheritDoc} This implementation scans the children in left to right order. 764 * 765 * @param node {@inheritDoc} 766 * @param p {@inheritDoc} 767 * @return the result of scanning 768 */ 769 @Override 770 public R visitParameterizedType(ParameterizedTypeTree node, P p) { 771 R r = scan(node.getType(), p); 772 r = scanAndReduce(node.getTypeArguments(), p, r); 773 return r; 774 } 775 776 /** 777 * {@inheritDoc} This implementation scans the children in left to right order. 778 * 779 * @param node {@inheritDoc} 780 * @param p {@inheritDoc} 781 * @return the result of scanning 782 */ 783 @Override 784 public R visitUnionType(UnionTypeTree node, P p) { 785 return scan(node.getTypeAlternatives(), p); 786 } 787 788 /** 789 * {@inheritDoc} This implementation scans the children in left to right order. 790 * 791 * @param node {@inheritDoc} 792 * @param p {@inheritDoc} 793 * @return the result of scanning 794 */ 795 @Override 796 public R visitIntersectionType(IntersectionTypeTree node, P p) { 797 return scan(node.getBounds(), p); 798 } 799 800 /** 801 * {@inheritDoc} This implementation scans the children in left to right order. 802 * 803 * @param node {@inheritDoc} 804 * @param p {@inheritDoc} 805 * @return the result of scanning 806 */ 807 @Override 808 public R visitTypeParameter(TypeParameterTree node, P p) { 809 R r = scan(node.getAnnotations(), p); 810 r = scanAndReduce(node.getBounds(), p, r); 811 return r; 812 } 813 814 /** 815 * {@inheritDoc} This implementation scans the children in left to right order. 816 * 817 * @param node {@inheritDoc} 818 * @param p {@inheritDoc} 819 * @return the result of scanning 820 */ 821 @Override 822 public R visitWildcard(WildcardTree node, P p) { 823 return scan(node.getBound(), p); 824 } 825 826 /** 827 * {@inheritDoc} This implementation scans the children in left to right order. 828 * 829 * @param node {@inheritDoc} 830 * @param p {@inheritDoc} 831 * @return the result of scanning 832 */ 833 @Override 834 public R visitModifiers(ModifiersTree node, P p) { 835 return scan(node.getAnnotations(), p); 836 } 837 838 /** 839 * {@inheritDoc} This implementation scans the children in left to right order. 840 * 841 * @param node {@inheritDoc} 842 * @param p {@inheritDoc} 843 * @return the result of scanning 844 */ 845 @Override 846 public R visitAnnotation(AnnotationTree node, P p) { 847 R r = scan(node.getAnnotationType(), p); 848 r = scanAndReduce(node.getArguments(), p, r); 849 return r; 850 } 851 852 /** 853 * {@inheritDoc} This implementation scans the children in left to right order. 854 * 855 * @param node {@inheritDoc} 856 * @param p {@inheritDoc} 857 * @return the result of scanning 858 */ 859 @Override 860 public R visitAnnotatedType(AnnotatedTypeTree node, P p) { 861 R r = scan(node.getAnnotations(), p); 862 r = scanAndReduce(node.getUnderlyingType(), p, r); 863 return r; 864 } 865 866 @Override 867 public R visitModule(ModuleTree node, P p) { 868 R r = scan(node.getAnnotations(), p); 869 r = scanAndReduce(node.getName(), p, r); 870 r = scanAndReduce(node.getDirectives(), p, r); 871 return r; 872 } 873 874 @Override 875 public R visitExports(ExportsTree node, P p) { 876 R r = scan(node.getPackageName(), p); 877 r = scanAndReduce(node.getModuleNames(), p, r); 878 return r; 879 } 880 881 @Override 882 public R visitOpens(OpensTree node, P p) { 883 R r = scan(node.getPackageName(), p); 884 r = scanAndReduce(node.getModuleNames(), p, r); 885 return r; 886 } 887 888 @Override 889 public R visitProvides(ProvidesTree node, P p) { 890 R r = scan(node.getServiceName(), p); 891 r = scanAndReduce(node.getImplementationNames(), p, r); 892 return r; 893 } 894 895 @Override 896 public R visitRequires(RequiresTree node, P p) { 897 return scan(node.getModuleName(), p); 898 } 899 900 @Override 901 public R visitUses(UsesTree node, P p) { 902 return scan(node.getServiceName(), p); 903 } 904 905 /** 906 * {@inheritDoc} This implementation returns {@code null}. 907 * 908 * @param node {@inheritDoc} 909 * @param p {@inheritDoc} 910 * @return the result of scanning 911 */ 912 @Override 913 public R visitOther(Tree node, P p) { 914 return null; 915 } 916 917 /** 918 * {@inheritDoc} This implementation returns {@code null}. 919 * 920 * @param node {@inheritDoc} 921 * @param p {@inheritDoc} 922 * @return the result of scanning 923 */ 924 @Override 925 public R visitErroneous(ErroneousTree node, P p) { 926 return null; 927 } 928 929 /** 930 * {@inheritDoc} This implementation returns {@code null}. 931 * 932 * @param node {@inheritDoc} 933 * @param p {@inheritDoc} 934 * @return the result of scanning 935 */ 936 @Override 937 public R visitYield(YieldTree node, P p) { 938 return scan(node.getValue(), p); 939 } 940 }