KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > visitor > ClassHierarchyTraveler


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile.visitor;
22
23 import proguard.classfile.*;
24
25
26 /**
27  * This <code>ClassVisitor</code> lets a given <code>ClassVisitor</code>
28  * optionally travel to the visited class, its superclass, its interfaces, and
29  * its subclasses.
30  *
31  * @author Eric Lafortune
32  */

33 public class ClassHierarchyTraveler implements ClassVisitor
34 {
35     private boolean visitThisClass;
36     private boolean visitSuperClass;
37     private boolean visitInterfaces;
38     private boolean visitSubclasses;
39
40     private ClassVisitor classVisitor;
41
42
43     /**
44      * Creates a new ClassHierarchyTraveler.
45      * @param visitThisClass specifies whether to visit the originally visited
46      * classes.
47      * @param visitSuperClass specifies whether to visit the super classes of
48      * the visited classes.
49      * @param visitInterfaces specifies whether to visit the interfaces of
50      * the visited classes.
51      * @param visitSubclasses specifies whether to visit the subclasses of
52      * the visited classes.
53      * @param classVisitor the <code>ClassVisitor</code> to
54      * which visits will be delegated.
55      */

56     public ClassHierarchyTraveler(boolean visitThisClass,
57                                   boolean visitSuperClass,
58                                   boolean visitInterfaces,
59                                   boolean visitSubclasses,
60                                   ClassVisitor classVisitor)
61     {
62         this.visitThisClass = visitThisClass;
63         this.visitSuperClass = visitSuperClass;
64         this.visitInterfaces = visitInterfaces;
65         this.visitSubclasses = visitSubclasses;
66
67         this.classVisitor = classVisitor;
68     }
69
70
71     // Implementations for ClassVisitor.
72

73     public void visitProgramClass(ProgramClass programClass)
74     {
75         programClass.hierarchyAccept(visitThisClass,
76                                      visitSuperClass,
77                                      visitInterfaces,
78                                      visitSubclasses,
79                                      classVisitor);
80     }
81
82
83     public void visitLibraryClass(LibraryClass libraryClass)
84     {
85         libraryClass.hierarchyAccept(visitThisClass,
86                                      visitSuperClass,
87                                      visitInterfaces,
88                                      visitSubclasses,
89                                      classVisitor);
90     }
91 }
92
Popular Tags