1. /*
  2. * @(#)DeclarationVisitors.java 1.4 04/07/13
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.mirror.util;
  8. /**
  9. * Utilities to create specialized <tt>DeclarationVisitor</tt> instances.
  10. *
  11. * @author Joseph D. Darcy
  12. * @author Scott Seligman
  13. * @version 1.4 04/07/13
  14. * @since 1.5
  15. */
  16. public class DeclarationVisitors {
  17. private DeclarationVisitors(){} // do not instantiate.
  18. /**
  19. * A visitor that has no side effects and keeps no state.
  20. */
  21. public static final DeclarationVisitor NO_OP = new SimpleDeclarationVisitor();
  22. /**
  23. * Return a <tt>DeclarationVisitor</tt> that will scan the
  24. * declaration structure, visiting declarations contained in
  25. * another declaration. For example, when visiting a class, the
  26. * fields, methods, constructors, etc. of the class are also
  27. * visited. The order in which the contained declarations are scanned is
  28. * not specified.
  29. *
  30. * <p>The <tt>pre</tt> and <tt>post</tt>
  31. * <tt>DeclarationVisitor</tt> parameters specify,
  32. * respectively, the processing the scanner will do before or
  33. * after visiting the contained declarations. If only one of pre
  34. * and post processing is needed, use {@link
  35. * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the
  36. * other parameter.
  37. *
  38. * @param pre visitor representing processing to do before
  39. * visiting contained declarations.
  40. *
  41. * @param post visitor representing processing to do after
  42. * visiting contained declarations.
  43. */
  44. public static DeclarationVisitor getDeclarationScanner(DeclarationVisitor pre,
  45. DeclarationVisitor post) {
  46. return new DeclarationScanner(pre, post);
  47. }
  48. /**
  49. * Return a <tt>DeclarationVisitor</tt> that will scan the
  50. * declaration structure, visiting declarations contained in
  51. * another declaration in source code order. For example, when
  52. * visiting a class, the fields, methods, constructors, etc. of
  53. * the class are also visited. The order in which the contained
  54. * declarations are visited is as close to source code order as
  55. * possible; declaration mirrors created from class files instead
  56. * of source code will not have source position information.
  57. *
  58. * <p>The <tt>pre</tt> and <tt>post</tt>
  59. * <tt>DeclarationVisitor</tt> parameters specify,
  60. * respectively, the processing the scanner will do before or
  61. * after visiting the contained declarations. If only one of pre
  62. * and post processing is needed, use {@link
  63. * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the other parameter.
  64. *
  65. * @param pre visitor representing processing to do before
  66. * visiting contained declarations.
  67. *
  68. * @param post visitor representing processing to do after
  69. * visiting contained declarations.
  70. */
  71. public static DeclarationVisitor getSourceOrderDeclarationScanner(DeclarationVisitor pre,
  72. DeclarationVisitor post) {
  73. return new SourceOrderDeclScanner(pre, post);
  74. }
  75. }