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}
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}
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 @Override
345 @Deprecated(forRemoval=true, since="12")
346 @SuppressWarnings("removal")
347 public R visitSwitchExpression(SwitchExpressionTree node, P p) {
348 R r = scan(node.getExpression(), p);
349 r = scanAndReduce(node.getCases(), p, r);
350 return r;
351 }
352
353 /**
354 * {@inheritDoc} This implementation scans the children in left to right order.
355 *
356 * @param node {@inheritDoc}
357 * @param p {@inheritDoc}
358 * @return the result of scanning
359 */
360 @Override
361 @SuppressWarnings("removal")
362 public R visitCase(CaseTree node, P p) {
363 R r = scan(node.getExpressions(), p);
364 if (node.getCaseKind() == CaseKind.RULE)
365 r = scanAndReduce(node.getBody(), p, r);
366 else
367 r = scanAndReduce(node.getStatements(), p, r);
368 return r;
369 }
370
371 /**
372 * {@inheritDoc} This implementation scans the children in left to right order.
373 *
374 * @param node {@inheritDoc}
375 * @param p {@inheritDoc}
376 * @return the result of scanning
377 */
378 @Override
379 public R visitSynchronized(SynchronizedTree node, P p) {
380 R r = scan(node.getExpression(), p);
381 r = scanAndReduce(node.getBlock(), p, r);
382 return r;
383 }
384
385 /**
386 * {@inheritDoc} This implementation scans the children in left to right order.
445 /**
446 * {@inheritDoc} This implementation scans the children in left to right order.
447 *
448 * @param node {@inheritDoc}
449 * @param p {@inheritDoc}
450 * @return the result of scanning
451 */
452 @Override
453 public R visitExpressionStatement(ExpressionStatementTree node, P p) {
454 return scan(node.getExpression(), p);
455 }
456
457 /**
458 * {@inheritDoc} This implementation returns {@code null}.
459 *
460 * @param node {@inheritDoc}
461 * @param p {@inheritDoc}
462 * @return the result of scanning
463 */
464 @Override
465 @SuppressWarnings("removal")
466 public R visitBreak(BreakTree node, P p) {
467 return scan(node.getValue(), p);
468 }
469
470 /**
471 * {@inheritDoc} This implementation returns {@code null}.
472 *
473 * @param node {@inheritDoc}
474 * @param p {@inheritDoc}
475 * @return the result of scanning
476 */
477 @Override
478 public R visitContinue(ContinueTree node, P p) {
479 return null;
480 }
481
482 /**
483 * {@inheritDoc} This implementation scans the children in left to right order.
484 *
485 * @param node {@inheritDoc}
486 * @param p {@inheritDoc}
487 * @return the result of scanning
|