< prev index next >

src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java

Print this page
rev 51258 : imported patch switch.diff


   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}


 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 visitCase(CaseTree node, P p) {


 345         R r = scan(node.getExpression(), p);


















 346         r = scanAndReduce(node.getStatements(), 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 visitSynchronized(SynchronizedTree node, P p) {
 359         R r = scan(node.getExpression(), p);
 360         r = scanAndReduce(node.getBlock(), p, r);
 361         return r;
 362     }
 363 
 364     /**
 365      * {@inheritDoc} This implementation scans the children in left to right order.


 424     /**
 425      * {@inheritDoc} This implementation scans the children in left to right order.
 426      *
 427      * @param node  {@inheritDoc}
 428      * @param p  {@inheritDoc}
 429      * @return the result of scanning
 430      */
 431     @Override
 432     public R visitExpressionStatement(ExpressionStatementTree node, P p) {
 433         return scan(node.getExpression(), p);
 434     }
 435 
 436     /**
 437      * {@inheritDoc} This implementation returns {@code null}.
 438      *
 439      * @param node  {@inheritDoc}
 440      * @param p  {@inheritDoc}
 441      * @return the result of scanning
 442      */
 443     @Override

 444     public R visitBreak(BreakTree node, P p) {
 445         return null;
 446     }
 447 
 448     /**
 449      * {@inheritDoc} This implementation returns {@code null}.
 450      *
 451      * @param node  {@inheritDoc}
 452      * @param p  {@inheritDoc}
 453      * @return the result of scanning
 454      */
 455     @Override
 456     public R visitContinue(ContinueTree node, P p) {
 457         return null;
 458     }
 459 
 460     /**
 461      * {@inheritDoc} This implementation scans the children in left to right order.
 462      *
 463      * @param node  {@inheritDoc}
 464      * @param p  {@inheritDoc}
 465      * @return the result of scanning




   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 import com.sun.source.tree.CaseTree.CaseKind;
  30 
  31 /**
  32  * A TreeVisitor that visits all the child tree nodes.
  33  * To visit nodes of a particular type, just override the
  34  * corresponding visitXYZ method.
  35  * Inside your method, call super.visitXYZ to visit descendant
  36  * nodes.
  37  *
  38  * <p>The default implementation of the visitXYZ methods will determine
  39  * a result as follows:
  40  * <ul>
  41  * <li>If the node being visited has no children, the result will be {@code null}.
  42  * <li>If the node being visited has one child, the result will be the
  43  * result of calling {@code scan} on that child. The child may be a simple node
  44  * or itself a list of nodes.
  45  * <li> If the node being visited has more than one child, the result will
  46  * be determined by calling {@code scan} each child in turn, and then combining the
  47  * result of each scan after the first with the cumulative result
  48  * so far, as determined by the {@link #reduce} method. Each child may be either
  49  * a simple node of a list of nodes. The default behavior of the {@code reduce}


 323     /**
 324      * {@inheritDoc} This implementation scans the children in left to right order.
 325      *
 326      * @param node  {@inheritDoc}
 327      * @param p  {@inheritDoc}
 328      * @return the result of scanning
 329      */
 330     @Override
 331     public R visitSwitch(SwitchTree node, P p) {
 332         R r = scan(node.getExpression(), p);
 333         r = scanAndReduce(node.getCases(), p, r);
 334         return r;
 335     }
 336 
 337     /**
 338      * {@inheritDoc} This implementation scans the children in left to right order.
 339      *
 340      * @param node  {@inheritDoc}
 341      * @param p  {@inheritDoc}
 342      * @return the result of scanning
 343      *
 344      * @deprecated
 345      * This method is modeling switch expressions,
 346      * which are part of a preview feature and may be removed
 347      * if the preview feature is removed.
 348      */
 349     @Override
 350     @Deprecated(forRemoval=true, since="12")
 351     @SuppressWarnings("removal")
 352     public R visitSwitchExpression(SwitchExpressionTree node, P p) {
 353         R r = scan(node.getExpression(), p);
 354         r = scanAndReduce(node.getCases(), p, r);
 355         return r;
 356     }
 357 
 358     /**
 359      * {@inheritDoc} This implementation scans the children in left to right order.
 360      *
 361      * @param node  {@inheritDoc}
 362      * @param p  {@inheritDoc}
 363      * @return the result of scanning
 364      */
 365     @Override
 366     @SuppressWarnings("removal")
 367     public R visitCase(CaseTree node, P p) {
 368         R r = scan(node.getExpressions(), p);
 369         if (node.getCaseKind() == CaseKind.RULE)
 370             r = scanAndReduce(node.getBody(), p, r);
 371         else
 372             r = scanAndReduce(node.getStatements(), p, r);
 373         return r;
 374     }
 375 
 376     /**
 377      * {@inheritDoc} This implementation scans the children in left to right order.
 378      *
 379      * @param node  {@inheritDoc}
 380      * @param p  {@inheritDoc}
 381      * @return the result of scanning
 382      */
 383     @Override
 384     public R visitSynchronized(SynchronizedTree node, P p) {
 385         R r = scan(node.getExpression(), p);
 386         r = scanAndReduce(node.getBlock(), p, r);
 387         return r;
 388     }
 389 
 390     /**
 391      * {@inheritDoc} This implementation scans the children in left to right order.


 450     /**
 451      * {@inheritDoc} This implementation scans the children in left to right order.
 452      *
 453      * @param node  {@inheritDoc}
 454      * @param p  {@inheritDoc}
 455      * @return the result of scanning
 456      */
 457     @Override
 458     public R visitExpressionStatement(ExpressionStatementTree node, P p) {
 459         return scan(node.getExpression(), p);
 460     }
 461 
 462     /**
 463      * {@inheritDoc} This implementation returns {@code null}.
 464      *
 465      * @param node  {@inheritDoc}
 466      * @param p  {@inheritDoc}
 467      * @return the result of scanning
 468      */
 469     @Override
 470     @SuppressWarnings("removal")
 471     public R visitBreak(BreakTree node, P p) {
 472         return scan(node.getValue(), p);
 473     }
 474 
 475     /**
 476      * {@inheritDoc} This implementation returns {@code null}.
 477      *
 478      * @param node  {@inheritDoc}
 479      * @param p  {@inheritDoc}
 480      * @return the result of scanning
 481      */
 482     @Override
 483     public R visitContinue(ContinueTree node, P p) {
 484         return null;
 485     }
 486 
 487     /**
 488      * {@inheritDoc} This implementation scans the children in left to right order.
 489      *
 490      * @param node  {@inheritDoc}
 491      * @param p  {@inheritDoc}
 492      * @return the result of scanning


< prev index next >