1 /* 2 * Copyright (c) 2005, 2020, 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 * Constructor for subclasses to call. 80 */ 81 public TreeScanner() {} 82 83 /** 84 * Scans a single node. 85 * @param tree the node to be scanned 86 * @param p a parameter value passed to the visit method 87 * @return the result value from the visit method 88 */ 89 public R scan(Tree tree, P p) { 90 return (tree == null) ? null : tree.accept(this, p); 91 } 92 93 private R scanAndReduce(Tree node, P p, R r) { 94 return reduce(scan(node, p), r); 95 } 96 97 /** 98 * Scans a sequence of nodes. 99 * @param nodes the nodes to be scanned 100 * @param p a parameter value to be passed to the visit method for each node 101 * @return the combined return value from the visit methods. 102 * The values are combined using the {@link #reduce reduce} method. 103 */ 104 public R scan(Iterable<? extends Tree> nodes, P p) { 105 R r = null; 106 if (nodes != null) { 107 boolean first = true; 108 for (Tree node : nodes) { 109 r = (first ? scan(node, p) : scanAndReduce(node, p, r)); 110 first = false; 111 } 112 } 113 return r; 114 } 115 116 private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) { 117 return reduce(scan(nodes, p), r); 118 } 119 120 /** 121 * Reduces two results into a combined result. 122 * The default implementation is to return the first parameter. 123 * The general contract of the method is that it may take any action whatsoever. 124 * @param r1 the first of the values to be combined 125 * @param r2 the second of the values to be combined 126 * @return the result of combining the two parameters 127 */ 128 public R reduce(R r1, R r2) { 129 return r1; 130 } 131 132 133 /* *************************************************************************** 134 * Visitor methods 135 ****************************************************************************/ 136 137 /** 138 * {@inheritDoc} This implementation scans the children in left to right order. 139 * 140 * @param node {@inheritDoc} 141 * @param p {@inheritDoc} 142 * @return the result of scanning 143 */ 144 @Override 145 public R visitCompilationUnit(CompilationUnitTree node, P p) { 146 R r = scan(node.getPackage(), p); 147 r = scanAndReduce(node.getImports(), p, r); 148 r = scanAndReduce(node.getTypeDecls(), p, r); 149 return r; 150 } 151 152 /** 153 * {@inheritDoc} This implementation scans the children in left to right order. 154 * 155 * @param node {@inheritDoc} 156 * @param p {@inheritDoc} 157 * @return the result of scanning 158 */ 159 @Override 160 public R visitPackage(PackageTree node, P p) { 161 R r = scan(node.getAnnotations(), p); 162 r = scanAndReduce(node.getPackageName(), p, r); 163 return r; 164 } 165 166 /** 167 * {@inheritDoc} This implementation scans the children in left to right order. 168 * 169 * @param node {@inheritDoc} 170 * @param p {@inheritDoc} 171 * @return the result of scanning 172 */ 173 @Override 174 public R visitImport(ImportTree node, P p) { 175 return scan(node.getQualifiedIdentifier(), p); 176 } 177 178 /** 179 * {@inheritDoc} This implementation scans the children in left to right order. 180 * 181 * @param node {@inheritDoc} 182 * @param p {@inheritDoc} 183 * @return the result of scanning 184 */ 185 @SuppressWarnings("preview") 186 @Override 187 public R visitClass(ClassTree node, P p) { 188 R r = scan(node.getModifiers(), p); 189 r = scanAndReduce(node.getTypeParameters(), p, r); 190 r = scanAndReduce(node.getExtendsClause(), p, r); 191 r = scanAndReduce(node.getImplementsClause(), p, r); 192 r = scanAndReduce(node.getPermitsClause(), p, r); 193 r = scanAndReduce(node.getMembers(), p, r); 194 return r; 195 } 196 197 /** 198 * {@inheritDoc} This implementation scans the children in left to right order. 199 * 200 * @param node {@inheritDoc} 201 * @param p {@inheritDoc} 202 * @return the result of scanning 203 */ 204 @Override 205 public R visitMethod(MethodTree node, P p) { 206 R r = scan(node.getModifiers(), p); 207 r = scanAndReduce(node.getReturnType(), p, r); 208 r = scanAndReduce(node.getTypeParameters(), p, r); 209 r = scanAndReduce(node.getParameters(), p, r); 210 r = scanAndReduce(node.getReceiverParameter(), p, r); 211 r = scanAndReduce(node.getThrows(), p, r); 212 r = scanAndReduce(node.getBody(), p, r); 213 r = scanAndReduce(node.getDefaultValue(), p, r); 214 return r; 215 } 216 217 /** 218 * {@inheritDoc} This implementation scans the children in left to right order. 219 * 220 * @param node {@inheritDoc} 221 * @param p {@inheritDoc} 222 * @return the result of scanning 223 */ 224 @Override 225 public R visitVariable(VariableTree node, P p) { 226 R r = scan(node.getModifiers(), p); 227 r = scanAndReduce(node.getType(), p, r); 228 r = scanAndReduce(node.getNameExpression(), p, r); 229 r = scanAndReduce(node.getInitializer(), p, r); 230 return r; 231 } 232 233 /** 234 * {@inheritDoc} This implementation returns {@code null}. 235 * 236 * @param node {@inheritDoc} 237 * @param p {@inheritDoc} 238 * @return the result of scanning 239 */ 240 @Override 241 public R visitEmptyStatement(EmptyStatementTree node, P p) { 242 return null; 243 } 244 245 /** 246 * {@inheritDoc} This implementation scans the children in left to right order. 247 * 248 * @param node {@inheritDoc} 249 * @param p {@inheritDoc} 250 * @return the result of scanning 251 */ 252 @Override 253 public R visitBlock(BlockTree node, P p) { 254 return scan(node.getStatements(), p); 255 } 256 257 /** 258 * {@inheritDoc} This implementation scans the children in left to right order. 259 * 260 * @param node {@inheritDoc} 261 * @param p {@inheritDoc} 262 * @return the result of scanning 263 */ 264 @Override 265 public R visitDoWhileLoop(DoWhileLoopTree node, P p) { 266 R r = scan(node.getStatement(), p); 267 r = scanAndReduce(node.getCondition(), p, r); 268 return r; 269 } 270 271 /** 272 * {@inheritDoc} This implementation scans the children in left to right order. 273 * 274 * @param node {@inheritDoc} 275 * @param p {@inheritDoc} 276 * @return the result of scanning 277 */ 278 @Override 279 public R visitWhileLoop(WhileLoopTree node, P p) { 280 R r = scan(node.getCondition(), p); 281 r = scanAndReduce(node.getStatement(), p, r); 282 return r; 283 } 284 285 /** 286 * {@inheritDoc} This implementation scans the children in left to right order. 287 * 288 * @param node {@inheritDoc} 289 * @param p {@inheritDoc} 290 * @return the result of scanning 291 */ 292 @Override 293 public R visitForLoop(ForLoopTree node, P p) { 294 R r = scan(node.getInitializer(), p); 295 r = scanAndReduce(node.getCondition(), p, r); 296 r = scanAndReduce(node.getUpdate(), p, r); 297 r = scanAndReduce(node.getStatement(), p, r); 298 return r; 299 } 300 301 /** 302 * {@inheritDoc} This implementation scans the children in left to right order. 303 * 304 * @param node {@inheritDoc} 305 * @param p {@inheritDoc} 306 * @return the result of scanning 307 */ 308 @Override 309 public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) { 310 R r = scan(node.getVariable(), p); 311 r = scanAndReduce(node.getExpression(), p, r); 312 r = scanAndReduce(node.getStatement(), p, r); 313 return r; 314 } 315 316 /** 317 * {@inheritDoc} This implementation scans the children in left to right order. 318 * 319 * @param node {@inheritDoc} 320 * @param p {@inheritDoc} 321 * @return the result of scanning 322 */ 323 @Override 324 public R visitLabeledStatement(LabeledStatementTree node, P p) { 325 return scan(node.getStatement(), p); 326 } 327 328 /** 329 * {@inheritDoc} This implementation scans the children in left to right order. 330 * 331 * @param node {@inheritDoc} 332 * @param p {@inheritDoc} 333 * @return the result of scanning 334 */ 335 @Override 336 public R visitSwitch(SwitchTree node, P p) { 337 R r = scan(node.getExpression(), p); 338 r = scanAndReduce(node.getCases(), p, r); 339 return r; 340 } 341 342 /** 343 * {@inheritDoc} This implementation scans the children in left to right order. 344 * 345 * @param node {@inheritDoc} 346 * @param p {@inheritDoc} 347 * @return the result of scanning 348 */ 349 @Override 350 public R visitSwitchExpression(SwitchExpressionTree node, P p) { 351 R r = scan(node.getExpression(), p); 352 r = scanAndReduce(node.getCases(), p, r); 353 return r; 354 } 355 356 /** 357 * {@inheritDoc} This implementation scans the children in left to right order. 358 * 359 * @param node {@inheritDoc} 360 * @param p {@inheritDoc} 361 * @return the result of scanning 362 */ 363 @Override 364 public R visitCase(CaseTree node, P p) { 365 R r = scan(node.getExpressions(), p); 366 if (node.getCaseKind() == CaseTree.CaseKind.RULE) 367 r = scanAndReduce(node.getBody(), p, r); 368 else 369 r = scanAndReduce(node.getStatements(), p, r); 370 return r; 371 } 372 373 /** 374 * {@inheritDoc} This implementation scans the children in left to right order. 375 * 376 * @param node {@inheritDoc} 377 * @param p {@inheritDoc} 378 * @return the result of scanning 379 */ 380 @Override 381 public R visitSynchronized(SynchronizedTree node, P p) { 382 R r = scan(node.getExpression(), p); 383 r = scanAndReduce(node.getBlock(), p, r); 384 return r; 385 } 386 387 /** 388 * {@inheritDoc} This implementation scans the children in left to right order. 389 * 390 * @param node {@inheritDoc} 391 * @param p {@inheritDoc} 392 * @return the result of scanning 393 */ 394 @Override 395 public R visitTry(TryTree node, P p) { 396 R r = scan(node.getResources(), p); 397 r = scanAndReduce(node.getBlock(), p, r); 398 r = scanAndReduce(node.getCatches(), p, r); 399 r = scanAndReduce(node.getFinallyBlock(), p, r); 400 return r; 401 } 402 403 /** 404 * {@inheritDoc} This implementation scans the children in left to right order. 405 * 406 * @param node {@inheritDoc} 407 * @param p {@inheritDoc} 408 * @return the result of scanning 409 */ 410 @Override 411 public R visitCatch(CatchTree node, P p) { 412 R r = scan(node.getParameter(), p); 413 r = scanAndReduce(node.getBlock(), p, r); 414 return r; 415 } 416 417 /** 418 * {@inheritDoc} This implementation scans the children in left to right order. 419 * 420 * @param node {@inheritDoc} 421 * @param p {@inheritDoc} 422 * @return the result of scanning 423 */ 424 @Override 425 public R visitConditionalExpression(ConditionalExpressionTree node, P p) { 426 R r = scan(node.getCondition(), p); 427 r = scanAndReduce(node.getTrueExpression(), p, r); 428 r = scanAndReduce(node.getFalseExpression(), p, r); 429 return r; 430 } 431 432 /** 433 * {@inheritDoc} This implementation scans the children in left to right order. 434 * 435 * @param node {@inheritDoc} 436 * @param p {@inheritDoc} 437 * @return the result of scanning 438 */ 439 @Override 440 public R visitIf(IfTree node, P p) { 441 R r = scan(node.getCondition(), p); 442 r = scanAndReduce(node.getThenStatement(), p, r); 443 r = scanAndReduce(node.getElseStatement(), p, r); 444 return r; 445 } 446 447 /** 448 * {@inheritDoc} This implementation scans the children in left to right order. 449 * 450 * @param node {@inheritDoc} 451 * @param p {@inheritDoc} 452 * @return the result of scanning 453 */ 454 @Override 455 public R visitExpressionStatement(ExpressionStatementTree node, P p) { 456 return scan(node.getExpression(), p); 457 } 458 459 /** 460 * {@inheritDoc} This implementation returns {@code null}. 461 * 462 * @param node {@inheritDoc} 463 * @param p {@inheritDoc} 464 * @return the result of scanning 465 */ 466 @Override 467 public R visitBreak(BreakTree node, P p) { 468 return null; 469 } 470 471 /** 472 * {@inheritDoc} This implementation returns {@code null}. 473 * 474 * @param node {@inheritDoc} 475 * @param p {@inheritDoc} 476 * @return the result of scanning 477 */ 478 @Override 479 public R visitContinue(ContinueTree node, P p) { 480 return null; 481 } 482 483 /** 484 * {@inheritDoc} This implementation scans the children in left to right order. 485 * 486 * @param node {@inheritDoc} 487 * @param p {@inheritDoc} 488 * @return the result of scanning 489 */ 490 @Override 491 public R visitReturn(ReturnTree node, P p) { 492 return scan(node.getExpression(), p); 493 } 494 495 /** 496 * {@inheritDoc} This implementation scans the children in left to right order. 497 * 498 * @param node {@inheritDoc} 499 * @param p {@inheritDoc} 500 * @return the result of scanning 501 */ 502 @Override 503 public R visitThrow(ThrowTree node, P p) { 504 return scan(node.getExpression(), p); 505 } 506 507 /** 508 * {@inheritDoc} This implementation scans the children in left to right order. 509 * 510 * @param node {@inheritDoc} 511 * @param p {@inheritDoc} 512 * @return the result of scanning 513 */ 514 @Override 515 public R visitAssert(AssertTree node, P p) { 516 R r = scan(node.getCondition(), p); 517 r = scanAndReduce(node.getDetail(), p, r); 518 return r; 519 } 520 521 /** 522 * {@inheritDoc} This implementation scans the children in left to right order. 523 * 524 * @param node {@inheritDoc} 525 * @param p {@inheritDoc} 526 * @return the result of scanning 527 */ 528 @Override 529 public R visitMethodInvocation(MethodInvocationTree node, P p) { 530 R r = scan(node.getTypeArguments(), p); 531 r = scanAndReduce(node.getMethodSelect(), p, r); 532 r = scanAndReduce(node.getArguments(), p, r); 533 return r; 534 } 535 536 /** 537 * {@inheritDoc} This implementation scans the children in left to right order. 538 * 539 * @param node {@inheritDoc} 540 * @param p {@inheritDoc} 541 * @return the result of scanning 542 */ 543 @Override 544 public R visitNewClass(NewClassTree node, P p) { 545 R r = scan(node.getEnclosingExpression(), p); 546 r = scanAndReduce(node.getIdentifier(), p, r); 547 r = scanAndReduce(node.getTypeArguments(), p, r); 548 r = scanAndReduce(node.getArguments(), p, r); 549 r = scanAndReduce(node.getClassBody(), p, r); 550 return r; 551 } 552 553 /** 554 * {@inheritDoc} This implementation scans the children in left to right order. 555 * 556 * @param node {@inheritDoc} 557 * @param p {@inheritDoc} 558 * @return the result of scanning 559 */ 560 @Override 561 public R visitNewArray(NewArrayTree node, P p) { 562 R r = scan(node.getType(), p); 563 r = scanAndReduce(node.getDimensions(), p, r); 564 r = scanAndReduce(node.getInitializers(), p, r); 565 r = scanAndReduce(node.getAnnotations(), p, r); 566 for (Iterable< ? extends Tree> dimAnno : node.getDimAnnotations()) { 567 r = scanAndReduce(dimAnno, p, r); 568 } 569 return r; 570 } 571 572 /** 573 * {@inheritDoc} This implementation scans the children in left to right order. 574 * 575 * @param node {@inheritDoc} 576 * @param p {@inheritDoc} 577 * @return the result of scanning 578 */ 579 @Override 580 public R visitLambdaExpression(LambdaExpressionTree node, P p) { 581 R r = scan(node.getParameters(), p); 582 r = scanAndReduce(node.getBody(), p, r); 583 return r; 584 } 585 586 /** 587 * {@inheritDoc} This implementation scans the children in left to right order. 588 * 589 * @param node {@inheritDoc} 590 * @param p {@inheritDoc} 591 * @return the result of scanning 592 */ 593 @Override 594 public R visitParenthesized(ParenthesizedTree node, P p) { 595 return scan(node.getExpression(), p); 596 } 597 598 /** 599 * {@inheritDoc} This implementation scans the children in left to right order. 600 * 601 * @param node {@inheritDoc} 602 * @param p {@inheritDoc} 603 * @return the result of scanning 604 */ 605 @Override 606 public R visitAssignment(AssignmentTree node, P p) { 607 R r = scan(node.getVariable(), p); 608 r = scanAndReduce(node.getExpression(), p, r); 609 return r; 610 } 611 612 /** 613 * {@inheritDoc} This implementation scans the children in left to right order. 614 * 615 * @param node {@inheritDoc} 616 * @param p {@inheritDoc} 617 * @return the result of scanning 618 */ 619 @Override 620 public R visitCompoundAssignment(CompoundAssignmentTree node, P p) { 621 R r = scan(node.getVariable(), p); 622 r = scanAndReduce(node.getExpression(), p, r); 623 return r; 624 } 625 626 /** 627 * {@inheritDoc} This implementation scans the children in left to right order. 628 * 629 * @param node {@inheritDoc} 630 * @param p {@inheritDoc} 631 * @return the result of scanning 632 */ 633 @Override 634 public R visitUnary(UnaryTree node, P p) { 635 return scan(node.getExpression(), p); 636 } 637 638 /** 639 * {@inheritDoc} This implementation scans the children in left to right order. 640 * 641 * @param node {@inheritDoc} 642 * @param p {@inheritDoc} 643 * @return the result of scanning 644 */ 645 @Override 646 public R visitBinary(BinaryTree node, P p) { 647 R r = scan(node.getLeftOperand(), p); 648 r = scanAndReduce(node.getRightOperand(), p, r); 649 return r; 650 } 651 652 /** 653 * {@inheritDoc} This implementation scans the children in left to right order. 654 * 655 * @param node {@inheritDoc} 656 * @param p {@inheritDoc} 657 * @return the result of scanning 658 */ 659 @Override 660 public R visitTypeCast(TypeCastTree node, P p) { 661 R r = scan(node.getType(), p); 662 r = scanAndReduce(node.getExpression(), p, r); 663 return r; 664 } 665 666 /** 667 * {@inheritDoc} This implementation scans the children in left to right order. 668 * 669 * @param node {@inheritDoc} 670 * @param p {@inheritDoc} 671 * @return the result of scanning 672 */ 673 @Override 674 public R visitInstanceOf(InstanceOfTree node, P p) { 675 R r = scan(node.getExpression(), p); 676 if (node.getPattern() != null) { 677 r = scanAndReduce(node.getPattern(), p, r); 678 } else { 679 r = scanAndReduce(node.getType(), p, r); 680 } 681 return r; 682 } 683 684 /** 685 * {@inheritDoc} This implementation scans the children in left to right order. 686 * 687 * @param node {@inheritDoc} 688 * @param p {@inheritDoc} 689 * @return the result of scanning 690 * @since 14 691 */ 692 @Override 693 public R visitBindingPattern(BindingPatternTree node, P p) { 694 return scan(node.getType(), p); 695 } 696 697 /** 698 * {@inheritDoc} This implementation scans the children in left to right order. 699 * 700 * @param node {@inheritDoc} 701 * @param p {@inheritDoc} 702 * @return the result of scanning 703 */ 704 @Override 705 public R visitArrayAccess(ArrayAccessTree node, P p) { 706 R r = scan(node.getExpression(), p); 707 r = scanAndReduce(node.getIndex(), p, r); 708 return r; 709 } 710 711 /** 712 * {@inheritDoc} This implementation scans the children in left to right order. 713 * 714 * @param node {@inheritDoc} 715 * @param p {@inheritDoc} 716 * @return the result of scanning 717 */ 718 @Override 719 public R visitMemberSelect(MemberSelectTree node, P p) { 720 return scan(node.getExpression(), p); 721 } 722 723 /** 724 * {@inheritDoc} This implementation scans the children in left to right order. 725 * 726 * @param node {@inheritDoc} 727 * @param p {@inheritDoc} 728 * @return the result of scanning 729 */ 730 @Override 731 public R visitMemberReference(MemberReferenceTree node, P p) { 732 R r = scan(node.getQualifierExpression(), p); 733 r = scanAndReduce(node.getTypeArguments(), p, r); 734 return r; 735 } 736 737 /** 738 * {@inheritDoc} This implementation returns {@code null}. 739 * 740 * @param node {@inheritDoc} 741 * @param p {@inheritDoc} 742 * @return the result of scanning 743 */ 744 @Override 745 public R visitIdentifier(IdentifierTree node, P p) { 746 return null; 747 } 748 749 /** 750 * {@inheritDoc} This implementation returns {@code null}. 751 * 752 * @param node {@inheritDoc} 753 * @param p {@inheritDoc} 754 * @return the result of scanning 755 */ 756 @Override 757 public R visitLiteral(LiteralTree node, P p) { 758 return null; 759 } 760 761 /** 762 * {@inheritDoc} This implementation returns {@code null}. 763 * 764 * @param node {@inheritDoc} 765 * @param p {@inheritDoc} 766 * @return the result of scanning 767 */ 768 @Override 769 public R visitPrimitiveType(PrimitiveTypeTree node, P p) { 770 return null; 771 } 772 773 /** 774 * {@inheritDoc} This implementation scans the children in left to right order. 775 * 776 * @param node {@inheritDoc} 777 * @param p {@inheritDoc} 778 * @return the result of scanning 779 */ 780 @Override 781 public R visitArrayType(ArrayTypeTree node, P p) { 782 return scan(node.getType(), p); 783 } 784 785 /** 786 * {@inheritDoc} This implementation scans the children in left to right order. 787 * 788 * @param node {@inheritDoc} 789 * @param p {@inheritDoc} 790 * @return the result of scanning 791 */ 792 @Override 793 public R visitParameterizedType(ParameterizedTypeTree node, P p) { 794 R r = scan(node.getType(), p); 795 r = scanAndReduce(node.getTypeArguments(), p, r); 796 return r; 797 } 798 799 /** 800 * {@inheritDoc} This implementation scans the children in left to right order. 801 * 802 * @param node {@inheritDoc} 803 * @param p {@inheritDoc} 804 * @return the result of scanning 805 */ 806 @Override 807 public R visitUnionType(UnionTypeTree node, P p) { 808 return scan(node.getTypeAlternatives(), p); 809 } 810 811 /** 812 * {@inheritDoc} This implementation scans the children in left to right order. 813 * 814 * @param node {@inheritDoc} 815 * @param p {@inheritDoc} 816 * @return the result of scanning 817 */ 818 @Override 819 public R visitIntersectionType(IntersectionTypeTree node, P p) { 820 return scan(node.getBounds(), p); 821 } 822 823 /** 824 * {@inheritDoc} This implementation scans the children in left to right order. 825 * 826 * @param node {@inheritDoc} 827 * @param p {@inheritDoc} 828 * @return the result of scanning 829 */ 830 @Override 831 public R visitTypeParameter(TypeParameterTree node, P p) { 832 R r = scan(node.getAnnotations(), p); 833 r = scanAndReduce(node.getBounds(), p, r); 834 return r; 835 } 836 837 /** 838 * {@inheritDoc} This implementation scans the children in left to right order. 839 * 840 * @param node {@inheritDoc} 841 * @param p {@inheritDoc} 842 * @return the result of scanning 843 */ 844 @Override 845 public R visitWildcard(WildcardTree node, P p) { 846 return scan(node.getBound(), p); 847 } 848 849 /** 850 * {@inheritDoc} This implementation scans the children in left to right order. 851 * 852 * @param node {@inheritDoc} 853 * @param p {@inheritDoc} 854 * @return the result of scanning 855 */ 856 @Override 857 public R visitModifiers(ModifiersTree node, P p) { 858 return scan(node.getAnnotations(), p); 859 } 860 861 /** 862 * {@inheritDoc} This implementation scans the children in left to right order. 863 * 864 * @param node {@inheritDoc} 865 * @param p {@inheritDoc} 866 * @return the result of scanning 867 */ 868 @Override 869 public R visitAnnotation(AnnotationTree node, P p) { 870 R r = scan(node.getAnnotationType(), p); 871 r = scanAndReduce(node.getArguments(), p, r); 872 return r; 873 } 874 875 /** 876 * {@inheritDoc} This implementation scans the children in left to right order. 877 * 878 * @param node {@inheritDoc} 879 * @param p {@inheritDoc} 880 * @return the result of scanning 881 */ 882 @Override 883 public R visitAnnotatedType(AnnotatedTypeTree node, P p) { 884 R r = scan(node.getAnnotations(), p); 885 r = scanAndReduce(node.getUnderlyingType(), p, r); 886 return r; 887 } 888 889 @Override 890 public R visitModule(ModuleTree node, P p) { 891 R r = scan(node.getAnnotations(), p); 892 r = scanAndReduce(node.getName(), p, r); 893 r = scanAndReduce(node.getDirectives(), p, r); 894 return r; 895 } 896 897 @Override 898 public R visitExports(ExportsTree node, P p) { 899 R r = scan(node.getPackageName(), p); 900 r = scanAndReduce(node.getModuleNames(), p, r); 901 return r; 902 } 903 904 @Override 905 public R visitOpens(OpensTree node, P p) { 906 R r = scan(node.getPackageName(), p); 907 r = scanAndReduce(node.getModuleNames(), p, r); 908 return r; 909 } 910 911 @Override 912 public R visitProvides(ProvidesTree node, P p) { 913 R r = scan(node.getServiceName(), p); 914 r = scanAndReduce(node.getImplementationNames(), p, r); 915 return r; 916 } 917 918 @Override 919 public R visitRequires(RequiresTree node, P p) { 920 return scan(node.getModuleName(), p); 921 } 922 923 @Override 924 public R visitUses(UsesTree node, P p) { 925 return scan(node.getServiceName(), p); 926 } 927 928 /** 929 * {@inheritDoc} This implementation returns {@code null}. 930 * 931 * @param node {@inheritDoc} 932 * @param p {@inheritDoc} 933 * @return the result of scanning 934 */ 935 @Override 936 public R visitOther(Tree node, P p) { 937 return null; 938 } 939 940 /** 941 * {@inheritDoc} This implementation returns {@code null}. 942 * 943 * @param node {@inheritDoc} 944 * @param p {@inheritDoc} 945 * @return the result of scanning 946 */ 947 @Override 948 public R visitErroneous(ErroneousTree node, P p) { 949 return null; 950 } 951 952 /** 953 * {@inheritDoc} This implementation returns {@code null}. 954 * 955 * @param node {@inheritDoc} 956 * @param p {@inheritDoc} 957 * @return the result of scanning 958 */ 959 @Override 960 public R visitYield(YieldTree node, P p) { 961 return scan(node.getValue(), p); 962 } 963 }