001: /*
002: * @(#)DeclarationVisitors.java 1.4 04/07/13
003: *
004: * Copyright (c) 2004, Sun Microsystems, Inc.
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: * * Neither the name of the Sun Microsystems, Inc. nor the names of
016: * its contributors may be used to endorse or promote products derived from
017: * this software without specific prior written permission.
018: *
019: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
020: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
021: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
022: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
023: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
024: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
025: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
026: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
027: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
028: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: */
031:
032: package com.sun.mirror.util;
033:
034: /**
035: * Utilities to create specialized <tt>DeclarationVisitor</tt> instances.
036: *
037: * @author Joseph D. Darcy
038: * @author Scott Seligman
039: * @version 1.4 04/07/13
040: * @since 1.5
041: */
042: public class DeclarationVisitors {
043: private DeclarationVisitors() {
044: } // do not instantiate.
045:
046: /**
047: * A visitor that has no side effects and keeps no state.
048: */
049: public static final DeclarationVisitor NO_OP = new SimpleDeclarationVisitor();
050:
051: /**
052: * Return a <tt>DeclarationVisitor</tt> that will scan the
053: * declaration structure, visiting declarations contained in
054: * another declaration. For example, when visiting a class, the
055: * fields, methods, constructors, etc. of the class are also
056: * visited. The order in which the contained declarations are scanned is
057: * not specified.
058: *
059: * <p>The <tt>pre</tt> and <tt>post</tt>
060: * <tt>DeclarationVisitor</tt> parameters specify,
061: * respectively, the processing the scanner will do before or
062: * after visiting the contained declarations. If only one of pre
063: * and post processing is needed, use {@link
064: * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the
065: * other parameter.
066: *
067: * @param pre visitor representing processing to do before
068: * visiting contained declarations.
069: *
070: * @param post visitor representing processing to do after
071: * visiting contained declarations.
072: */
073: public static DeclarationVisitor getDeclarationScanner(
074: DeclarationVisitor pre, DeclarationVisitor post) {
075: return new DeclarationScanner(pre, post);
076: }
077:
078: /**
079: * Return a <tt>DeclarationVisitor</tt> that will scan the
080: * declaration structure, visiting declarations contained in
081: * another declaration in source code order. For example, when
082: * visiting a class, the fields, methods, constructors, etc. of
083: * the class are also visited. The order in which the contained
084: * declarations are visited is as close to source code order as
085: * possible; declaration mirrors created from class files instead
086: * of source code will not have source position information.
087: *
088: * <p>The <tt>pre</tt> and <tt>post</tt>
089: * <tt>DeclarationVisitor</tt> parameters specify,
090: * respectively, the processing the scanner will do before or
091: * after visiting the contained declarations. If only one of pre
092: * and post processing is needed, use {@link
093: * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the other parameter.
094: *
095: * @param pre visitor representing processing to do before
096: * visiting contained declarations.
097: *
098: * @param post visitor representing processing to do after
099: * visiting contained declarations.
100: */
101: public static DeclarationVisitor getSourceOrderDeclarationScanner(
102: DeclarationVisitor pre, DeclarationVisitor post) {
103: return new SourceOrderDeclScanner(pre, post);
104: }
105: }
|