001 /*
002 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package com.sun.mirror.util;
027
028 /**
029 * Utilities to create specialized <tt>DeclarationVisitor</tt> instances.
030 *
031 * @author Joseph D. Darcy
032 * @author Scott Seligman
033 * @since 1.5
034 */
035 public class DeclarationVisitors {
036 private DeclarationVisitors(){} // do not instantiate.
037
038 /**
039 * A visitor that has no side effects and keeps no state.
040 */
041 public static final DeclarationVisitor NO_OP = new SimpleDeclarationVisitor();
042
043 /**
044 * Return a <tt>DeclarationVisitor</tt> that will scan the
045 * declaration structure, visiting declarations contained in
046 * another declaration. For example, when visiting a class, the
047 * fields, methods, constructors, etc. of the class are also
048 * visited. The order in which the contained declarations are scanned is
049 * not specified.
050 *
051 * <p>The <tt>pre</tt> and <tt>post</tt>
052 * <tt>DeclarationVisitor</tt> parameters specify,
053 * respectively, the processing the scanner will do before or
054 * after visiting the contained declarations. If only one of pre
055 * and post processing is needed, use {@link
056 * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the
057 * other parameter.
058 *
059 * @param pre visitor representing processing to do before
060 * visiting contained declarations.
061 *
062 * @param post visitor representing processing to do after
063 * visiting contained declarations.
064 */
065 public static DeclarationVisitor getDeclarationScanner(DeclarationVisitor pre,
066 DeclarationVisitor post) {
067 return new DeclarationScanner(pre, post);
068 }
069
070 /**
071 * Return a <tt>DeclarationVisitor</tt> that will scan the
072 * declaration structure, visiting declarations contained in
073 * another declaration in source code order. For example, when
074 * visiting a class, the fields, methods, constructors, etc. of
075 * the class are also visited. The order in which the contained
076 * declarations are visited is as close to source code order as
077 * possible; declaration mirrors created from class files instead
078 * of source code will not have source position information.
079 *
080 * <p>The <tt>pre</tt> and <tt>post</tt>
081 * <tt>DeclarationVisitor</tt> parameters specify,
082 * respectively, the processing the scanner will do before or
083 * after visiting the contained declarations. If only one of pre
084 * and post processing is needed, use {@link
085 * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the other parameter.
086 *
087 * @param pre visitor representing processing to do before
088 * visiting contained declarations.
089 *
090 * @param post visitor representing processing to do after
091 * visiting contained declarations.
092 */
093 public static DeclarationVisitor getSourceOrderDeclarationScanner(DeclarationVisitor pre,
094 DeclarationVisitor post) {
095 return new SourceOrderDeclScanner(pre, post);
096 }
097 }