1 /*
   2  * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.mirror.util;
  27 
  28 /**
  29  * Utilities to create specialized <tt>DeclarationVisitor</tt> instances.
  30  *
  31  * @author Joseph D. Darcy
  32  * @author Scott Seligman
  33  * @since 1.5
  34  */
  35 public class DeclarationVisitors {
  36     private DeclarationVisitors(){} // do not instantiate.
  37 
  38     /**
  39      * A visitor that has no side effects and keeps no state.
  40      */
  41     public static final DeclarationVisitor NO_OP = new SimpleDeclarationVisitor();
  42 
  43     /**
  44      * Return a <tt>DeclarationVisitor</tt> that will scan the
  45      * declaration structure, visiting declarations contained in
  46      * another declaration.  For example, when visiting a class, the
  47      * fields, methods, constructors, etc. of the class are also
  48      * visited.  The order in which the contained declarations are scanned is
  49      * not specified.
  50      *
  51      * <p>The <tt>pre</tt> and <tt>post</tt>
  52      * <tt>DeclarationVisitor</tt> parameters specify,
  53      * respectively, the processing the scanner will do before or
  54      * after visiting the contained declarations.  If only one of pre
  55      * and post processing is needed, use {@link
  56      * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the
  57      * other parameter.
  58      *
  59      * @param pre visitor representing processing to do before
  60      * visiting contained declarations.
  61      *
  62      * @param post visitor representing processing to do after
  63      * visiting contained declarations.
  64      */
  65     public static DeclarationVisitor getDeclarationScanner(DeclarationVisitor pre,
  66                                                            DeclarationVisitor post) {
  67         return new DeclarationScanner(pre, post);
  68     }
  69 
  70     /**
  71      * Return a <tt>DeclarationVisitor</tt> that will scan the
  72      * declaration structure, visiting declarations contained in
  73      * another declaration in source code order.  For example, when
  74      * visiting a class, the fields, methods, constructors, etc. of
  75      * the class are also visited.  The order in which the contained
  76      * declarations are visited is as close to source code order as
  77      * possible; declaration mirrors created from class files instead
  78      * of source code will not have source position information.
  79      *
  80      * <p>The <tt>pre</tt> and <tt>post</tt>
  81      * <tt>DeclarationVisitor</tt> parameters specify,
  82      * respectively, the processing the scanner will do before or
  83      * after visiting the contained declarations.  If only one of pre
  84      * and post processing is needed, use {@link
  85      * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the other parameter.
  86      *
  87      * @param pre visitor representing processing to do before
  88      * visiting contained declarations.
  89      *
  90      * @param post visitor representing processing to do after
  91      * visiting contained declarations.
  92      */
  93     public static DeclarationVisitor getSourceOrderDeclarationScanner(DeclarationVisitor pre,
  94                                                                       DeclarationVisitor post) {
  95         return new SourceOrderDeclScanner(pre, post);
  96     }
  97 }