KickJava   Java API By Example, From Geeks To Geeks.

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


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 library 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 library 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 Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile.visitor;
22
23 import proguard.classfile.*;
24
25 /**
26  * This <code>ClassVisitor</code> delegates its visits to program classes to
27  * another given <code>ClassVisitor</code>, but only when the class version
28  * number of the visited program class lies in a given range.
29  *
30  * @author Eric Lafortune
31  */

32 public class ClassVersionFilter implements ClassVisitor
33 {
34     private int minimumClassVersion;
35     private int maximumClassVersion;
36     private ClassVisitor classVisitor;
37
38
39     /**
40      * Creates a new ClassVersionFilter.
41      * @param minimumClassVersion the minimum class version number.
42      * @param maximumClassVersion the maximum class version number.
43      * @param classVisitor the <code>ClassVisitor</code> to which visits
44      * will be delegated.
45      */

46     public ClassVersionFilter(int minimumClassVersion,
47                               int maximumClassVersion,
48                               ClassVisitor classVisitor)
49     {
50         this.minimumClassVersion = minimumClassVersion;
51         this.maximumClassVersion = maximumClassVersion;
52         this.classVisitor = classVisitor;
53     }
54
55
56     // Implementations for ClassVisitor.
57

58     public void visitProgramClass(ProgramClass programClass)
59     {
60         if (programClass.u4version >= minimumClassVersion &&
61             programClass.u4version <= maximumClassVersion)
62         {
63             classVisitor.visitProgramClass(programClass);
64         }
65     }
66
67
68     public void visitLibraryClass(LibraryClass libraryClass)
69     {
70         // Library classes don't have version numbers.
71
}
72 }
73
Popular Tags