Path: blob/master/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java
66647 views
/*1* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.source.util;2627import com.sun.source.tree.*;28import jdk.internal.javac.PreviewFeature;2930/**31* A TreeVisitor that visits all the child tree nodes.32* To visit nodes of a particular type, just override the33* corresponding visitXYZ method.34* Inside your method, call super.visitXYZ to visit descendant35* nodes.36*37* <p>Here is an example to count the number of identifier nodes in a tree:38* <pre>39* class CountIdentifiers extends TreeScanner<Integer,Void> {40* {@literal @}Override41* public Integer visitIdentifier(IdentifierTree node, Void p) {42* return 1;43* }44* {@literal @}Override45* public Integer reduce(Integer r1, Integer r2) {46* return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);47* }48* }49* </pre>50*51* @implSpec52* <p>The default implementation of the visitXYZ methods will determine53* a result as follows:54* <ul>55* <li>If the node being visited has no children, the result will be {@code null}.56* <li>If the node being visited has one child, the result will be the57* result of calling {@code scan} with that child. The child may be a simple node58* or itself a list of nodes.59* <li>If the node being visited has more than one child, the result will60* be determined by calling {@code scan} with each child in turn, and then combining the61* result of each scan after the first with the cumulative result62* so far, as determined by the {@link #reduce} method. Each child may be either63* a simple node or a list of nodes. The default behavior of the {@code reduce}64* method is such that the result of the visitXYZ method will be the result of65* the last child scanned.66* </ul>67*68* @param <R> the return type of this visitor's methods. Use {@link69* Void} for visitors that do not need to return results.70* @param <P> the type of the additional parameter to this visitor's71* methods. Use {@code Void} for visitors that do not need an72* additional parameter.73*74* @author Peter von der Ahé75* @author Jonathan Gibbons76* @since 1.677*/78public class TreeScanner<R,P> implements TreeVisitor<R,P> {79/**80* Constructs a {@code TreeScanner}.81*/82public TreeScanner() {}8384/**85* Scans a single node.86* @param tree the node to be scanned87* @param p a parameter value passed to the visit method88* @return the result value from the visit method89*/90public R scan(Tree tree, P p) {91return (tree == null) ? null : tree.accept(this, p);92}9394private R scanAndReduce(Tree node, P p, R r) {95return reduce(scan(node, p), r);96}9798/**99* Scans a sequence of nodes.100* @param nodes the nodes to be scanned101* @param p a parameter value to be passed to the visit method for each node102* @return the combined return value from the visit methods.103* The values are combined using the {@link #reduce reduce} method.104*/105public R scan(Iterable<? extends Tree> nodes, P p) {106R r = null;107if (nodes != null) {108boolean first = true;109for (Tree node : nodes) {110r = (first ? scan(node, p) : scanAndReduce(node, p, r));111first = false;112}113}114return r;115}116117private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) {118return reduce(scan(nodes, p), r);119}120121/**122* Reduces two results into a combined result.123* The default implementation is to return the first parameter.124* The general contract of the method is that it may take any action whatsoever.125* @param r1 the first of the values to be combined126* @param r2 the second of the values to be combined127* @return the result of combining the two parameters128*/129public R reduce(R r1, R r2) {130return r1;131}132133134/* ***************************************************************************135* Visitor methods136****************************************************************************/137138/**139* {@inheritDoc}140*141* @implSpec This implementation scans the children in left to right order.142*143* @param node {@inheritDoc}144* @param p {@inheritDoc}145* @return the result of scanning146*/147@Override148public R visitCompilationUnit(CompilationUnitTree node, P p) {149R r = scan(node.getPackage(), p);150r = scanAndReduce(node.getImports(), p, r);151r = scanAndReduce(node.getTypeDecls(), p, r);152r = scanAndReduce(node.getModule(), p, r);153return r;154}155156/**157* {@inheritDoc}158*159* @implSpec This implementation scans the children in left to right order.160*161* @param node {@inheritDoc}162* @param p {@inheritDoc}163* @return the result of scanning164*/165@Override166public R visitPackage(PackageTree node, P p) {167R r = scan(node.getAnnotations(), p);168r = scanAndReduce(node.getPackageName(), p, r);169return r;170}171172/**173* {@inheritDoc}174*175* @implSpec This implementation scans the children in left to right order.176*177* @param node {@inheritDoc}178* @param p {@inheritDoc}179* @return the result of scanning180*/181@Override182public R visitImport(ImportTree node, P p) {183return scan(node.getQualifiedIdentifier(), p);184}185186/**187* {@inheritDoc}188*189* @implSpec This implementation scans the children in left to right order.190*191* @param node {@inheritDoc}192* @param p {@inheritDoc}193* @return the result of scanning194*/195@Override196public R visitClass(ClassTree node, P p) {197R r = scan(node.getModifiers(), p);198r = scanAndReduce(node.getTypeParameters(), p, r);199r = scanAndReduce(node.getExtendsClause(), p, r);200r = scanAndReduce(node.getImplementsClause(), p, r);201r = scanAndReduce(node.getPermitsClause(), p, r);202r = scanAndReduce(node.getMembers(), p, r);203return r;204}205206/**207* {@inheritDoc}208*209* @implSpec This implementation scans the children in left to right order.210*211* @param node {@inheritDoc}212* @param p {@inheritDoc}213* @return the result of scanning214*/215@Override216public R visitMethod(MethodTree node, P p) {217R r = scan(node.getModifiers(), p);218r = scanAndReduce(node.getReturnType(), p, r);219r = scanAndReduce(node.getTypeParameters(), p, r);220r = scanAndReduce(node.getParameters(), p, r);221r = scanAndReduce(node.getReceiverParameter(), p, r);222r = scanAndReduce(node.getThrows(), p, r);223r = scanAndReduce(node.getBody(), p, r);224r = scanAndReduce(node.getDefaultValue(), p, r);225return r;226}227228/**229* {@inheritDoc}230*231* @implSpec This implementation scans the children in left to right order.232*233* @param node {@inheritDoc}234* @param p {@inheritDoc}235* @return the result of scanning236*/237@Override238public R visitVariable(VariableTree node, P p) {239R r = scan(node.getModifiers(), p);240r = scanAndReduce(node.getType(), p, r);241r = scanAndReduce(node.getNameExpression(), p, r);242r = scanAndReduce(node.getInitializer(), p, r);243return r;244}245246/**247* {@inheritDoc}248*249* @implSpec This implementation returns {@code null}.250*251* @param node {@inheritDoc}252* @param p {@inheritDoc}253* @return the result of scanning254*/255@Override256public R visitEmptyStatement(EmptyStatementTree node, P p) {257return null;258}259260/**261* {@inheritDoc}262*263* @implSpec This implementation scans the children in left to right order.264*265* @param node {@inheritDoc}266* @param p {@inheritDoc}267* @return the result of scanning268*/269@Override270public R visitBlock(BlockTree node, P p) {271return scan(node.getStatements(), p);272}273274/**275* {@inheritDoc}276*277* @implSpec This implementation scans the children in left to right order.278*279* @param node {@inheritDoc}280* @param p {@inheritDoc}281* @return the result of scanning282*/283@Override284public R visitDoWhileLoop(DoWhileLoopTree node, P p) {285R r = scan(node.getStatement(), p);286r = scanAndReduce(node.getCondition(), p, r);287return r;288}289290/**291* {@inheritDoc}292*293* @implSpec This implementation scans the children in left to right order.294*295* @param node {@inheritDoc}296* @param p {@inheritDoc}297* @return the result of scanning298*/299@Override300public R visitWhileLoop(WhileLoopTree node, P p) {301R r = scan(node.getCondition(), p);302r = scanAndReduce(node.getStatement(), p, r);303return r;304}305306/**307* {@inheritDoc}308*309* @implSpec This implementation scans the children in left to right order.310*311* @param node {@inheritDoc}312* @param p {@inheritDoc}313* @return the result of scanning314*/315@Override316public R visitForLoop(ForLoopTree node, P p) {317R r = scan(node.getInitializer(), p);318r = scanAndReduce(node.getCondition(), p, r);319r = scanAndReduce(node.getUpdate(), p, r);320r = scanAndReduce(node.getStatement(), p, r);321return r;322}323324/**325* {@inheritDoc}326*327* @implSpec This implementation scans the children in left to right order.328*329* @param node {@inheritDoc}330* @param p {@inheritDoc}331* @return the result of scanning332*/333@Override334public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {335R r = scan(node.getVariable(), p);336r = scanAndReduce(node.getExpression(), p, r);337r = scanAndReduce(node.getStatement(), p, r);338return r;339}340341/**342* {@inheritDoc}343*344* @implSpec This implementation scans the children in left to right order.345*346* @param node {@inheritDoc}347* @param p {@inheritDoc}348* @return the result of scanning349*/350@Override351public R visitLabeledStatement(LabeledStatementTree node, P p) {352return scan(node.getStatement(), p);353}354355/**356* {@inheritDoc}357*358* @implSpec This implementation scans the children in left to right order.359*360* @param node {@inheritDoc}361* @param p {@inheritDoc}362* @return the result of scanning363*/364@Override365public R visitSwitch(SwitchTree node, P p) {366R r = scan(node.getExpression(), p);367r = scanAndReduce(node.getCases(), p, r);368return r;369}370371/**372* {@inheritDoc}373*374* @implSpec This implementation scans the children in left to right order.375*376* @param node {@inheritDoc}377* @param p {@inheritDoc}378* @return the result of scanning379*/380@Override381public R visitSwitchExpression(SwitchExpressionTree node, P p) {382R r = scan(node.getExpression(), p);383r = scanAndReduce(node.getCases(), p, r);384return r;385}386387/**388* {@inheritDoc}389*390* @implSpec This implementation scans the children in left to right order.391*392* @param node {@inheritDoc}393* @param p {@inheritDoc}394* @return the result of scanning395*/396@Override397public R visitCase(CaseTree node, P p) {398R r = scan(node.getExpressions(), p);399if (node.getCaseKind() == CaseTree.CaseKind.RULE)400r = scanAndReduce(node.getBody(), p, r);401else402r = scanAndReduce(node.getStatements(), p, r);403return r;404}405406/**407* {@inheritDoc}408*409* @implSpec This implementation scans the children in left to right order.410*411* @param node {@inheritDoc}412* @param p {@inheritDoc}413* @return the result of scanning414*/415@Override416public R visitSynchronized(SynchronizedTree node, P p) {417R r = scan(node.getExpression(), p);418r = scanAndReduce(node.getBlock(), p, r);419return r;420}421422/**423* {@inheritDoc}424*425* @implSpec This implementation scans the children in left to right order.426*427* @param node {@inheritDoc}428* @param p {@inheritDoc}429* @return the result of scanning430*/431@Override432public R visitTry(TryTree node, P p) {433R r = scan(node.getResources(), p);434r = scanAndReduce(node.getBlock(), p, r);435r = scanAndReduce(node.getCatches(), p, r);436r = scanAndReduce(node.getFinallyBlock(), p, r);437return r;438}439440/**441* {@inheritDoc}442*443* @implSpec This implementation scans the children in left to right order.444*445* @param node {@inheritDoc}446* @param p {@inheritDoc}447* @return the result of scanning448*/449@Override450public R visitCatch(CatchTree node, P p) {451R r = scan(node.getParameter(), p);452r = scanAndReduce(node.getBlock(), p, r);453return r;454}455456/**457* {@inheritDoc}458*459* @implSpec This implementation scans the children in left to right order.460*461* @param node {@inheritDoc}462* @param p {@inheritDoc}463* @return the result of scanning464*/465@Override466public R visitConditionalExpression(ConditionalExpressionTree node, P p) {467R r = scan(node.getCondition(), p);468r = scanAndReduce(node.getTrueExpression(), p, r);469r = scanAndReduce(node.getFalseExpression(), p, r);470return r;471}472473/**474* {@inheritDoc}475*476* @implSpec This implementation scans the children in left to right order.477*478* @param node {@inheritDoc}479* @param p {@inheritDoc}480* @return the result of scanning481*/482@Override483public R visitIf(IfTree node, P p) {484R r = scan(node.getCondition(), p);485r = scanAndReduce(node.getThenStatement(), p, r);486r = scanAndReduce(node.getElseStatement(), p, r);487return r;488}489490/**491* {@inheritDoc}492*493* @implSpec This implementation scans the children in left to right order.494*495* @param node {@inheritDoc}496* @param p {@inheritDoc}497* @return the result of scanning498*/499@Override500public R visitExpressionStatement(ExpressionStatementTree node, P p) {501return scan(node.getExpression(), p);502}503504/**505* {@inheritDoc}506*507* @implSpec This implementation returns {@code null}.508*509* @param node {@inheritDoc}510* @param p {@inheritDoc}511* @return the result of scanning512*/513@Override514public R visitBreak(BreakTree node, P p) {515return null;516}517518/**519* {@inheritDoc}520*521* @implSpec This implementation returns {@code null}.522*523* @param node {@inheritDoc}524* @param p {@inheritDoc}525* @return the result of scanning526*/527@Override528public R visitContinue(ContinueTree node, P p) {529return null;530}531532/**533* {@inheritDoc}534*535* @implSpec This implementation scans the children in left to right order.536*537* @param node {@inheritDoc}538* @param p {@inheritDoc}539* @return the result of scanning540*/541@Override542public R visitReturn(ReturnTree node, P p) {543return scan(node.getExpression(), p);544}545546/**547* {@inheritDoc}548*549* @implSpec This implementation scans the children in left to right order.550*551* @param node {@inheritDoc}552* @param p {@inheritDoc}553* @return the result of scanning554*/555@Override556public R visitThrow(ThrowTree node, P p) {557return scan(node.getExpression(), p);558}559560/**561* {@inheritDoc}562*563* @implSpec This implementation scans the children in left to right order.564*565* @param node {@inheritDoc}566* @param p {@inheritDoc}567* @return the result of scanning568*/569@Override570public R visitAssert(AssertTree node, P p) {571R r = scan(node.getCondition(), p);572r = scanAndReduce(node.getDetail(), p, r);573return r;574}575576/**577* {@inheritDoc}578*579* @implSpec This implementation scans the children in left to right order.580*581* @param node {@inheritDoc}582* @param p {@inheritDoc}583* @return the result of scanning584*/585@Override586public R visitMethodInvocation(MethodInvocationTree node, P p) {587R r = scan(node.getTypeArguments(), p);588r = scanAndReduce(node.getMethodSelect(), p, r);589r = scanAndReduce(node.getArguments(), p, r);590return r;591}592593/**594* {@inheritDoc}595*596* @implSpec This implementation scans the children in left to right order.597*598* @param node {@inheritDoc}599* @param p {@inheritDoc}600* @return the result of scanning601*/602@Override603public R visitNewClass(NewClassTree node, P p) {604R r = scan(node.getEnclosingExpression(), p);605r = scanAndReduce(node.getIdentifier(), p, r);606r = scanAndReduce(node.getTypeArguments(), p, r);607r = scanAndReduce(node.getArguments(), p, r);608r = scanAndReduce(node.getClassBody(), p, r);609return r;610}611612/**613* {@inheritDoc}614*615* @implSpec This implementation scans the children in left to right order.616*617* @param node {@inheritDoc}618* @param p {@inheritDoc}619* @return the result of scanning620*/621@Override622public R visitNewArray(NewArrayTree node, P p) {623R r = scan(node.getType(), p);624r = scanAndReduce(node.getDimensions(), p, r);625r = scanAndReduce(node.getInitializers(), p, r);626r = scanAndReduce(node.getAnnotations(), p, r);627for (Iterable< ? extends Tree> dimAnno : node.getDimAnnotations()) {628r = scanAndReduce(dimAnno, p, r);629}630return r;631}632633/**634* {@inheritDoc}635*636* @implSpec This implementation scans the children in left to right order.637*638* @param node {@inheritDoc}639* @param p {@inheritDoc}640* @return the result of scanning641*/642@Override643public R visitLambdaExpression(LambdaExpressionTree node, P p) {644R r = scan(node.getParameters(), p);645r = scanAndReduce(node.getBody(), p, r);646return r;647}648649/**650* {@inheritDoc}651*652* @implSpec This implementation scans the children in left to right order.653*654* @param node {@inheritDoc}655* @param p {@inheritDoc}656* @return the result of scanning657*/658@Override659public R visitParenthesized(ParenthesizedTree node, P p) {660return scan(node.getExpression(), p);661}662663/**664* {@inheritDoc}665*666* @implSpec This implementation scans the children in left to right order.667*668* @param node {@inheritDoc}669* @param p {@inheritDoc}670* @return the result of scanning671*/672@Override673public R visitAssignment(AssignmentTree node, P p) {674R r = scan(node.getVariable(), p);675r = scanAndReduce(node.getExpression(), p, r);676return r;677}678679/**680* {@inheritDoc}681*682* @implSpec This implementation scans the children in left to right order.683*684* @param node {@inheritDoc}685* @param p {@inheritDoc}686* @return the result of scanning687*/688@Override689public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {690R r = scan(node.getVariable(), p);691r = scanAndReduce(node.getExpression(), p, r);692return r;693}694695/**696* {@inheritDoc}697*698* @implSpec This implementation scans the children in left to right order.699*700* @param node {@inheritDoc}701* @param p {@inheritDoc}702* @return the result of scanning703*/704@Override705public R visitUnary(UnaryTree node, P p) {706return scan(node.getExpression(), p);707}708709/**710* {@inheritDoc}711*712* @implSpec This implementation scans the children in left to right order.713*714* @param node {@inheritDoc}715* @param p {@inheritDoc}716* @return the result of scanning717*/718@Override719public R visitBinary(BinaryTree node, P p) {720R r = scan(node.getLeftOperand(), p);721r = scanAndReduce(node.getRightOperand(), p, r);722return r;723}724725/**726* {@inheritDoc}727*728* @implSpec This implementation scans the children in left to right order.729*730* @param node {@inheritDoc}731* @param p {@inheritDoc}732* @return the result of scanning733*/734@Override735public R visitTypeCast(TypeCastTree node, P p) {736R r = scan(node.getType(), p);737r = scanAndReduce(node.getExpression(), p, r);738return r;739}740741/**742* {@inheritDoc}743*744* @implSpec This implementation scans the children in left to right order.745*746* @param node {@inheritDoc}747* @param p {@inheritDoc}748* @return the result of scanning749*/750@Override751public R visitInstanceOf(InstanceOfTree node, P p) {752R r = scan(node.getExpression(), p);753if (node.getPattern() != null) {754r = scanAndReduce(node.getPattern(), p, r);755} else {756r = scanAndReduce(node.getType(), p, r);757}758return r;759}760761/**762* {@inheritDoc}763*764* @implSpec This implementation scans the children in left to right order.765*766* @param node {@inheritDoc}767* @param p {@inheritDoc}768* @return the result of scanning769* @since 14770*/771@Override772public R visitBindingPattern(BindingPatternTree node, P p) {773return scan(node.getVariable(), p);774}775776/**777* {@inheritDoc}778*779* @implSpec This implementation returns {@code null}.780*781* @param node {@inheritDoc}782* @param p {@inheritDoc}783* @return the result of scanning784* @since 17785*/786@Override787@PreviewFeature(feature=PreviewFeature.Feature.SWITCH_PATTERN_MATCHING, reflective=true)788public R visitDefaultCaseLabel(DefaultCaseLabelTree node, P p) {789return null;790}791792/**793* {@inheritDoc}794*795* @implSpec This implementation scans the children in left to right order.796*797* @param node {@inheritDoc}798* @param p {@inheritDoc}799* @return the result of scanning800*/801@Override802public R visitArrayAccess(ArrayAccessTree node, P p) {803R r = scan(node.getExpression(), p);804r = scanAndReduce(node.getIndex(), p, r);805return r;806}807808/**809* {@inheritDoc}810*811* @implSpec This implementation scans the children in left to right order.812*813* @param node {@inheritDoc}814* @param p {@inheritDoc}815* @return the result of scanning816*/817@Override818public R visitMemberSelect(MemberSelectTree node, P p) {819return scan(node.getExpression(), p);820}821822/**823* {@inheritDoc}824*825* @implSpec This implementation scans the children in left to right order.826*827* @param node {@inheritDoc}828* @param p {@inheritDoc}829* @return the result of scanning830* @since 17831*/832@Override833@PreviewFeature(feature=PreviewFeature.Feature.SWITCH_PATTERN_MATCHING, reflective=true)834public R visitParenthesizedPattern(ParenthesizedPatternTree node, P p) {835return scan(node.getPattern(), p);836}837838/**839* {@inheritDoc}840*841* @implSpec This implementation scans the children in left to right order.842*843* @param node {@inheritDoc}844* @param p {@inheritDoc}845* @return the result of scanning846* @since 17847*/848@Override849@PreviewFeature(feature=PreviewFeature.Feature.SWITCH_PATTERN_MATCHING, reflective=true)850public R visitGuardedPattern(GuardedPatternTree node, P p) {851R r = scan(node.getPattern(), p);852return scanAndReduce(node.getExpression(), p, r);853}854855/**856* {@inheritDoc}857*858* @implSpec This implementation scans the children in left to right order.859*860* @param node {@inheritDoc}861* @param p {@inheritDoc}862* @return the result of scanning863*/864@Override865public R visitMemberReference(MemberReferenceTree node, P p) {866R r = scan(node.getQualifierExpression(), p);867r = scanAndReduce(node.getTypeArguments(), p, r);868return r;869}870871/**872* {@inheritDoc}873*874* @implSpec This implementation returns {@code null}.875*876* @param node {@inheritDoc}877* @param p {@inheritDoc}878* @return the result of scanning879*/880@Override881public R visitIdentifier(IdentifierTree node, P p) {882return null;883}884885/**886* {@inheritDoc}887*888* @implSpec This implementation returns {@code null}.889*890* @param node {@inheritDoc}891* @param p {@inheritDoc}892* @return the result of scanning893*/894@Override895public R visitLiteral(LiteralTree node, P p) {896return null;897}898899/**900* {@inheritDoc}901*902* @implSpec This implementation returns {@code null}.903*904* @param node {@inheritDoc}905* @param p {@inheritDoc}906* @return the result of scanning907*/908@Override909public R visitPrimitiveType(PrimitiveTypeTree node, P p) {910return null;911}912913/**914* {@inheritDoc}915*916* @implSpec This implementation scans the children in left to right order.917*918* @param node {@inheritDoc}919* @param p {@inheritDoc}920* @return the result of scanning921*/922@Override923public R visitArrayType(ArrayTypeTree node, P p) {924return scan(node.getType(), p);925}926927/**928* {@inheritDoc}929*930* @implSpec This implementation scans the children in left to right order.931*932* @param node {@inheritDoc}933* @param p {@inheritDoc}934* @return the result of scanning935*/936@Override937public R visitParameterizedType(ParameterizedTypeTree node, P p) {938R r = scan(node.getType(), p);939r = scanAndReduce(node.getTypeArguments(), p, r);940return r;941}942943/**944* {@inheritDoc}945*946* @implSpec This implementation scans the children in left to right order.947*948* @param node {@inheritDoc}949* @param p {@inheritDoc}950* @return the result of scanning951*/952@Override953public R visitUnionType(UnionTypeTree node, P p) {954return scan(node.getTypeAlternatives(), p);955}956957/**958* {@inheritDoc}959*960* @implSpec This implementation scans the children in left to right order.961*962* @param node {@inheritDoc}963* @param p {@inheritDoc}964* @return the result of scanning965*/966@Override967public R visitIntersectionType(IntersectionTypeTree node, P p) {968return scan(node.getBounds(), p);969}970971/**972* {@inheritDoc}973*974* @implSpec This implementation scans the children in left to right order.975*976* @param node {@inheritDoc}977* @param p {@inheritDoc}978* @return the result of scanning979*/980@Override981public R visitTypeParameter(TypeParameterTree node, P p) {982R r = scan(node.getAnnotations(), p);983r = scanAndReduce(node.getBounds(), p, r);984return r;985}986987/**988* {@inheritDoc}989*990* @implSpec This implementation scans the children in left to right order.991*992* @param node {@inheritDoc}993* @param p {@inheritDoc}994* @return the result of scanning995*/996@Override997public R visitWildcard(WildcardTree node, P p) {998return scan(node.getBound(), p);999}10001001/**1002* {@inheritDoc}1003*1004* @implSpec This implementation scans the children in left to right order.1005*1006* @param node {@inheritDoc}1007* @param p {@inheritDoc}1008* @return the result of scanning1009*/1010@Override1011public R visitModifiers(ModifiersTree node, P p) {1012return scan(node.getAnnotations(), p);1013}10141015/**1016* {@inheritDoc}1017*1018* @implSpec This implementation scans the children in left to right order.1019*1020* @param node {@inheritDoc}1021* @param p {@inheritDoc}1022* @return the result of scanning1023*/1024@Override1025public R visitAnnotation(AnnotationTree node, P p) {1026R r = scan(node.getAnnotationType(), p);1027r = scanAndReduce(node.getArguments(), p, r);1028return r;1029}10301031/**1032* {@inheritDoc}1033*1034* @implSpec This implementation scans the children in left to right order.1035*1036* @param node {@inheritDoc}1037* @param p {@inheritDoc}1038* @return the result of scanning1039*/1040@Override1041public R visitAnnotatedType(AnnotatedTypeTree node, P p) {1042R r = scan(node.getAnnotations(), p);1043r = scanAndReduce(node.getUnderlyingType(), p, r);1044return r;1045}10461047/**1048* {@inheritDoc}1049*1050* @implSpec This implementation scans the children in left to right order.1051*1052* @param node {@inheritDoc}1053* @param p {@inheritDoc}1054* @return the result of scanning1055*/1056@Override1057public R visitModule(ModuleTree node, P p) {1058R r = scan(node.getAnnotations(), p);1059r = scanAndReduce(node.getName(), p, r);1060r = scanAndReduce(node.getDirectives(), p, r);1061return r;1062}10631064/**1065* {@inheritDoc}1066*1067* @implSpec This implementation scans the children in left to right order.1068*1069* @param node {@inheritDoc}1070* @param p {@inheritDoc}1071* @return the result of scanning1072*/1073@Override1074public R visitExports(ExportsTree node, P p) {1075R r = scan(node.getPackageName(), p);1076r = scanAndReduce(node.getModuleNames(), p, r);1077return r;1078}10791080/**1081* {@inheritDoc}1082*1083* @implSpec This implementation scans the children in left to right order.1084*1085* @param node {@inheritDoc}1086* @param p {@inheritDoc}1087* @return the result of scanning1088*/1089@Override1090public R visitOpens(OpensTree node, P p) {1091R r = scan(node.getPackageName(), p);1092r = scanAndReduce(node.getModuleNames(), p, r);1093return r;1094}10951096/**1097* {@inheritDoc}1098*1099* @implSpec This implementation scans the children in left to right order.1100*1101* @param node {@inheritDoc}1102* @param p {@inheritDoc}1103* @return the result of scanning1104*/1105@Override1106public R visitProvides(ProvidesTree node, P p) {1107R r = scan(node.getServiceName(), p);1108r = scanAndReduce(node.getImplementationNames(), p, r);1109return r;1110}11111112/**1113* {@inheritDoc}1114*1115* @implSpec This implementation scans the children in left to right order.1116*1117* @param node {@inheritDoc}1118* @param p {@inheritDoc}1119* @return the result of scanning1120*/1121@Override1122public R visitRequires(RequiresTree node, P p) {1123return scan(node.getModuleName(), p);1124}11251126/**1127* {@inheritDoc}1128*1129* @implSpec This implementation scans the children in left to right order.1130*1131* @param node {@inheritDoc}1132* @param p {@inheritDoc}1133* @return the result of scanning1134*/1135@Override1136public R visitUses(UsesTree node, P p) {1137return scan(node.getServiceName(), p);1138}11391140/**1141* {@inheritDoc}1142*1143* @implSpec This implementation returns {@code null}.1144*1145* @param node {@inheritDoc}1146* @param p {@inheritDoc}1147* @return the result of scanning1148*/1149@Override1150public R visitOther(Tree node, P p) {1151return null;1152}11531154/**1155* {@inheritDoc}1156*1157* @implSpec This implementation returns {@code null}.1158*1159* @param node {@inheritDoc}1160* @param p {@inheritDoc}1161* @return the result of scanning1162*/1163@Override1164public R visitErroneous(ErroneousTree node, P p) {1165return null;1166}11671168/**1169* {@inheritDoc}1170*1171* @implSpec This implementation scans the children in left to right order.1172*1173* @param node {@inheritDoc}1174* @param p {@inheritDoc}1175* @return the result of scanning1176*/1177@Override1178public R visitYield(YieldTree node, P p) {1179return scan(node.getValue(), p);1180}1181}118211831184