Path: blob/master/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java
41175 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.*;2829/**30* A TreeVisitor that visits all the child tree nodes.31* To visit nodes of a particular type, just override the32* corresponding visitXYZ method.33* Inside your method, call super.visitXYZ to visit descendant34* nodes.35*36* <p>The default implementation of the visitXYZ methods will determine37* a result as follows:38* <ul>39* <li>If the node being visited has no children, the result will be {@code null}.40* <li>If the node being visited has one child, the result will be the41* result of calling {@code scan} with that child. The child may be a simple node42* or itself a list of nodes.43* <li>If the node being visited has more than one child, the result will44* be determined by calling {@code scan} with each child in turn, and then combining the45* result of each scan after the first with the cumulative result46* so far, as determined by the {@link #reduce} method. Each child may be either47* a simple node or a list of nodes. The default behavior of the {@code reduce}48* method is such that the result of the visitXYZ method will be the result of49* the last child scanned.50* </ul>51*52* <p>Here is an example to count the number of identifier nodes in a tree:53* <pre>54* class CountIdentifiers extends TreeScanner<Integer,Void> {55* {@literal @}Override56* public Integer visitIdentifier(IdentifierTree node, Void p) {57* return 1;58* }59* {@literal @}Override60* public Integer reduce(Integer r1, Integer r2) {61* return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);62* }63* }64* </pre>65*66* @param <R> the return type of this visitor's methods. Use {@link67* Void} for visitors that do not need to return results.68* @param <P> the type of the additional parameter to this visitor's69* methods. Use {@code Void} for visitors that do not need an70* additional parameter.71*72* @author Peter von der Ahé73* @author Jonathan Gibbons74* @since 1.675*/76public class TreeScanner<R,P> implements TreeVisitor<R,P> {77/**78* Constructs a {@code TreeScanner}.79*/80public TreeScanner() {}8182/**83* Scans a single node.84* @param tree the node to be scanned85* @param p a parameter value passed to the visit method86* @return the result value from the visit method87*/88public R scan(Tree tree, P p) {89return (tree == null) ? null : tree.accept(this, p);90}9192private R scanAndReduce(Tree node, P p, R r) {93return reduce(scan(node, p), r);94}9596/**97* Scans a sequence of nodes.98* @param nodes the nodes to be scanned99* @param p a parameter value to be passed to the visit method for each node100* @return the combined return value from the visit methods.101* The values are combined using the {@link #reduce reduce} method.102*/103public R scan(Iterable<? extends Tree> nodes, P p) {104R r = null;105if (nodes != null) {106boolean first = true;107for (Tree node : nodes) {108r = (first ? scan(node, p) : scanAndReduce(node, p, r));109first = false;110}111}112return r;113}114115private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) {116return reduce(scan(nodes, p), r);117}118119/**120* Reduces two results into a combined result.121* The default implementation is to return the first parameter.122* The general contract of the method is that it may take any action whatsoever.123* @param r1 the first of the values to be combined124* @param r2 the second of the values to be combined125* @return the result of combining the two parameters126*/127public R reduce(R r1, R r2) {128return r1;129}130131132/* ***************************************************************************133* Visitor methods134****************************************************************************/135136/**137* {@inheritDoc} This implementation scans the children in left to right order.138*139* @param node {@inheritDoc}140* @param p {@inheritDoc}141* @return the result of scanning142*/143@Override144public R visitCompilationUnit(CompilationUnitTree node, P p) {145R r = scan(node.getPackage(), p);146r = scanAndReduce(node.getImports(), p, r);147r = scanAndReduce(node.getTypeDecls(), p, r);148r = scanAndReduce(node.getModule(), p, r);149return r;150}151152/**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 scanning158*/159@Override160public R visitPackage(PackageTree node, P p) {161R r = scan(node.getAnnotations(), p);162r = scanAndReduce(node.getPackageName(), p, r);163return r;164}165166/**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 scanning172*/173@Override174public R visitImport(ImportTree node, P p) {175return scan(node.getQualifiedIdentifier(), p);176}177178/**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 scanning184*/185@SuppressWarnings("preview")186@Override187public R visitClass(ClassTree node, P p) {188R r = scan(node.getModifiers(), p);189r = scanAndReduce(node.getTypeParameters(), p, r);190r = scanAndReduce(node.getExtendsClause(), p, r);191r = scanAndReduce(node.getImplementsClause(), p, r);192r = scanAndReduce(node.getPermitsClause(), p, r);193r = scanAndReduce(node.getMembers(), p, r);194return r;195}196197/**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 scanning203*/204@Override205public R visitMethod(MethodTree node, P p) {206R r = scan(node.getModifiers(), p);207r = scanAndReduce(node.getReturnType(), p, r);208r = scanAndReduce(node.getTypeParameters(), p, r);209r = scanAndReduce(node.getParameters(), p, r);210r = scanAndReduce(node.getReceiverParameter(), p, r);211r = scanAndReduce(node.getThrows(), p, r);212r = scanAndReduce(node.getBody(), p, r);213r = scanAndReduce(node.getDefaultValue(), p, r);214return r;215}216217/**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 scanning223*/224@Override225public R visitVariable(VariableTree node, P p) {226R r = scan(node.getModifiers(), p);227r = scanAndReduce(node.getType(), p, r);228r = scanAndReduce(node.getNameExpression(), p, r);229r = scanAndReduce(node.getInitializer(), p, r);230return r;231}232233/**234* {@inheritDoc} This implementation returns {@code null}.235*236* @param node {@inheritDoc}237* @param p {@inheritDoc}238* @return the result of scanning239*/240@Override241public R visitEmptyStatement(EmptyStatementTree node, P p) {242return null;243}244245/**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 scanning251*/252@Override253public R visitBlock(BlockTree node, P p) {254return scan(node.getStatements(), p);255}256257/**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 scanning263*/264@Override265public R visitDoWhileLoop(DoWhileLoopTree node, P p) {266R r = scan(node.getStatement(), p);267r = scanAndReduce(node.getCondition(), p, r);268return r;269}270271/**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 scanning277*/278@Override279public R visitWhileLoop(WhileLoopTree node, P p) {280R r = scan(node.getCondition(), p);281r = scanAndReduce(node.getStatement(), p, r);282return r;283}284285/**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 scanning291*/292@Override293public R visitForLoop(ForLoopTree node, P p) {294R r = scan(node.getInitializer(), p);295r = scanAndReduce(node.getCondition(), p, r);296r = scanAndReduce(node.getUpdate(), p, r);297r = scanAndReduce(node.getStatement(), p, r);298return r;299}300301/**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 scanning307*/308@Override309public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {310R r = scan(node.getVariable(), p);311r = scanAndReduce(node.getExpression(), p, r);312r = scanAndReduce(node.getStatement(), p, r);313return r;314}315316/**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 scanning322*/323@Override324public R visitLabeledStatement(LabeledStatementTree node, P p) {325return scan(node.getStatement(), p);326}327328/**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 scanning334*/335@Override336public R visitSwitch(SwitchTree node, P p) {337R r = scan(node.getExpression(), p);338r = scanAndReduce(node.getCases(), p, r);339return r;340}341342/**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 scanning348*/349@Override350public R visitSwitchExpression(SwitchExpressionTree node, P p) {351R r = scan(node.getExpression(), p);352r = scanAndReduce(node.getCases(), p, r);353return r;354}355356/**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 scanning362*/363@Override364public R visitCase(CaseTree node, P p) {365R r = scan(node.getExpressions(), p);366if (node.getCaseKind() == CaseTree.CaseKind.RULE)367r = scanAndReduce(node.getBody(), p, r);368else369r = scanAndReduce(node.getStatements(), p, r);370return r;371}372373/**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 scanning379*/380@Override381public R visitSynchronized(SynchronizedTree node, P p) {382R r = scan(node.getExpression(), p);383r = scanAndReduce(node.getBlock(), p, r);384return r;385}386387/**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 scanning393*/394@Override395public R visitTry(TryTree node, P p) {396R r = scan(node.getResources(), p);397r = scanAndReduce(node.getBlock(), p, r);398r = scanAndReduce(node.getCatches(), p, r);399r = scanAndReduce(node.getFinallyBlock(), p, r);400return r;401}402403/**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 scanning409*/410@Override411public R visitCatch(CatchTree node, P p) {412R r = scan(node.getParameter(), p);413r = scanAndReduce(node.getBlock(), p, r);414return r;415}416417/**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 scanning423*/424@Override425public R visitConditionalExpression(ConditionalExpressionTree node, P p) {426R r = scan(node.getCondition(), p);427r = scanAndReduce(node.getTrueExpression(), p, r);428r = scanAndReduce(node.getFalseExpression(), p, r);429return r;430}431432/**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 scanning438*/439@Override440public R visitIf(IfTree node, P p) {441R r = scan(node.getCondition(), p);442r = scanAndReduce(node.getThenStatement(), p, r);443r = scanAndReduce(node.getElseStatement(), p, r);444return r;445}446447/**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 scanning453*/454@Override455public R visitExpressionStatement(ExpressionStatementTree node, P p) {456return scan(node.getExpression(), p);457}458459/**460* {@inheritDoc} This implementation returns {@code null}.461*462* @param node {@inheritDoc}463* @param p {@inheritDoc}464* @return the result of scanning465*/466@Override467public R visitBreak(BreakTree node, P p) {468return null;469}470471/**472* {@inheritDoc} This implementation returns {@code null}.473*474* @param node {@inheritDoc}475* @param p {@inheritDoc}476* @return the result of scanning477*/478@Override479public R visitContinue(ContinueTree node, P p) {480return null;481}482483/**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 scanning489*/490@Override491public R visitReturn(ReturnTree node, P p) {492return scan(node.getExpression(), p);493}494495/**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 scanning501*/502@Override503public R visitThrow(ThrowTree node, P p) {504return scan(node.getExpression(), p);505}506507/**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 scanning513*/514@Override515public R visitAssert(AssertTree node, P p) {516R r = scan(node.getCondition(), p);517r = scanAndReduce(node.getDetail(), p, r);518return r;519}520521/**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 scanning527*/528@Override529public R visitMethodInvocation(MethodInvocationTree node, P p) {530R r = scan(node.getTypeArguments(), p);531r = scanAndReduce(node.getMethodSelect(), p, r);532r = scanAndReduce(node.getArguments(), p, r);533return r;534}535536/**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 scanning542*/543@Override544public R visitNewClass(NewClassTree node, P p) {545R r = scan(node.getEnclosingExpression(), p);546r = scanAndReduce(node.getIdentifier(), p, r);547r = scanAndReduce(node.getTypeArguments(), p, r);548r = scanAndReduce(node.getArguments(), p, r);549r = scanAndReduce(node.getClassBody(), p, r);550return r;551}552553/**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 scanning559*/560@Override561public R visitNewArray(NewArrayTree node, P p) {562R r = scan(node.getType(), p);563r = scanAndReduce(node.getDimensions(), p, r);564r = scanAndReduce(node.getInitializers(), p, r);565r = scanAndReduce(node.getAnnotations(), p, r);566for (Iterable< ? extends Tree> dimAnno : node.getDimAnnotations()) {567r = scanAndReduce(dimAnno, p, r);568}569return r;570}571572/**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 scanning578*/579@Override580public R visitLambdaExpression(LambdaExpressionTree node, P p) {581R r = scan(node.getParameters(), p);582r = scanAndReduce(node.getBody(), p, r);583return r;584}585586/**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 scanning592*/593@Override594public R visitParenthesized(ParenthesizedTree node, P p) {595return scan(node.getExpression(), p);596}597598/**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 scanning604*/605@Override606public R visitAssignment(AssignmentTree node, P p) {607R r = scan(node.getVariable(), p);608r = scanAndReduce(node.getExpression(), p, r);609return r;610}611612/**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 scanning618*/619@Override620public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {621R r = scan(node.getVariable(), p);622r = scanAndReduce(node.getExpression(), p, r);623return r;624}625626/**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 scanning632*/633@Override634public R visitUnary(UnaryTree node, P p) {635return scan(node.getExpression(), p);636}637638/**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 scanning644*/645@Override646public R visitBinary(BinaryTree node, P p) {647R r = scan(node.getLeftOperand(), p);648r = scanAndReduce(node.getRightOperand(), p, r);649return r;650}651652/**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 scanning658*/659@Override660public R visitTypeCast(TypeCastTree node, P p) {661R r = scan(node.getType(), p);662r = scanAndReduce(node.getExpression(), p, r);663return r;664}665666/**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 scanning672*/673@Override674public R visitInstanceOf(InstanceOfTree node, P p) {675R r = scan(node.getExpression(), p);676if (node.getPattern() != null) {677r = scanAndReduce(node.getPattern(), p, r);678} else {679r = scanAndReduce(node.getType(), p, r);680}681return r;682}683684/**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 scanning690* @since 14691*/692@Override693public R visitBindingPattern(BindingPatternTree node, P p) {694return scan(node.getVariable(), p);695}696697/**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 scanning703*/704@Override705public R visitArrayAccess(ArrayAccessTree node, P p) {706R r = scan(node.getExpression(), p);707r = scanAndReduce(node.getIndex(), p, r);708return r;709}710711/**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 scanning717*/718@Override719public R visitMemberSelect(MemberSelectTree node, P p) {720return scan(node.getExpression(), p);721}722723/**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 scanning729*/730@Override731public R visitMemberReference(MemberReferenceTree node, P p) {732R r = scan(node.getQualifierExpression(), p);733r = scanAndReduce(node.getTypeArguments(), p, r);734return r;735}736737/**738* {@inheritDoc} This implementation returns {@code null}.739*740* @param node {@inheritDoc}741* @param p {@inheritDoc}742* @return the result of scanning743*/744@Override745public R visitIdentifier(IdentifierTree node, P p) {746return null;747}748749/**750* {@inheritDoc} This implementation returns {@code null}.751*752* @param node {@inheritDoc}753* @param p {@inheritDoc}754* @return the result of scanning755*/756@Override757public R visitLiteral(LiteralTree node, P p) {758return null;759}760761/**762* {@inheritDoc} This implementation returns {@code null}.763*764* @param node {@inheritDoc}765* @param p {@inheritDoc}766* @return the result of scanning767*/768@Override769public R visitPrimitiveType(PrimitiveTypeTree node, P p) {770return null;771}772773/**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 scanning779*/780@Override781public R visitArrayType(ArrayTypeTree node, P p) {782return scan(node.getType(), p);783}784785/**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 scanning791*/792@Override793public R visitParameterizedType(ParameterizedTypeTree node, P p) {794R r = scan(node.getType(), p);795r = scanAndReduce(node.getTypeArguments(), p, r);796return r;797}798799/**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 scanning805*/806@Override807public R visitUnionType(UnionTypeTree node, P p) {808return scan(node.getTypeAlternatives(), p);809}810811/**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 scanning817*/818@Override819public R visitIntersectionType(IntersectionTypeTree node, P p) {820return scan(node.getBounds(), p);821}822823/**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 scanning829*/830@Override831public R visitTypeParameter(TypeParameterTree node, P p) {832R r = scan(node.getAnnotations(), p);833r = scanAndReduce(node.getBounds(), p, r);834return r;835}836837/**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 scanning843*/844@Override845public R visitWildcard(WildcardTree node, P p) {846return scan(node.getBound(), p);847}848849/**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 scanning855*/856@Override857public R visitModifiers(ModifiersTree node, P p) {858return scan(node.getAnnotations(), p);859}860861/**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 scanning867*/868@Override869public R visitAnnotation(AnnotationTree node, P p) {870R r = scan(node.getAnnotationType(), p);871r = scanAndReduce(node.getArguments(), p, r);872return r;873}874875/**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 scanning881*/882@Override883public R visitAnnotatedType(AnnotatedTypeTree node, P p) {884R r = scan(node.getAnnotations(), p);885r = scanAndReduce(node.getUnderlyingType(), p, r);886return r;887}888889@Override890public R visitModule(ModuleTree node, P p) {891R r = scan(node.getAnnotations(), p);892r = scanAndReduce(node.getName(), p, r);893r = scanAndReduce(node.getDirectives(), p, r);894return r;895}896897@Override898public R visitExports(ExportsTree node, P p) {899R r = scan(node.getPackageName(), p);900r = scanAndReduce(node.getModuleNames(), p, r);901return r;902}903904@Override905public R visitOpens(OpensTree node, P p) {906R r = scan(node.getPackageName(), p);907r = scanAndReduce(node.getModuleNames(), p, r);908return r;909}910911@Override912public R visitProvides(ProvidesTree node, P p) {913R r = scan(node.getServiceName(), p);914r = scanAndReduce(node.getImplementationNames(), p, r);915return r;916}917918@Override919public R visitRequires(RequiresTree node, P p) {920return scan(node.getModuleName(), p);921}922923@Override924public R visitUses(UsesTree node, P p) {925return scan(node.getServiceName(), p);926}927928/**929* {@inheritDoc} This implementation returns {@code null}.930*931* @param node {@inheritDoc}932* @param p {@inheritDoc}933* @return the result of scanning934*/935@Override936public R visitOther(Tree node, P p) {937return null;938}939940/**941* {@inheritDoc} This implementation returns {@code null}.942*943* @param node {@inheritDoc}944* @param p {@inheritDoc}945* @return the result of scanning946*/947@Override948public R visitErroneous(ErroneousTree node, P p) {949return null;950}951952/**953* {@inheritDoc} This implementation scans the children in left to right order.954*955* @param node {@inheritDoc}956* @param p {@inheritDoc}957* @return the result of scanning958*/959@Override960public R visitYield(YieldTree node, P p) {961return scan(node.getValue(), p);962}963}964965966