KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > optimize > OptimizationInfoMemberFilter


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.optimize;
22
23 import proguard.classfile.util.*;
24 import proguard.classfile.visitor.MemberVisitor;
25 import proguard.classfile.*;
26 import proguard.optimize.info.*;
27
28 /**
29  * This <code>MemberVisitor</code> delegates its visits to another given
30  * <code>MemberVisitor</code>, but only when the visited member has optimization
31  * info.
32  *
33  * @see FieldOptimizationInfo
34  * @see MethodOptimizationInfo
35  * @author Eric Lafortune
36  */

37 public class OptimizationInfoMemberFilter
38 implements MemberVisitor
39 {
40     private MemberVisitor memberVisitor;
41
42
43     /**
44      * Creates a new OptimizationInfoMemberFilter.
45      * @param memberVisitor the <code>MemberVisitor</code> to which visits will
46      * be delegated.
47      */

48     public OptimizationInfoMemberFilter(MemberVisitor memberVisitor)
49     {
50         this.memberVisitor = memberVisitor;
51     }
52
53
54     // Implementations for MemberVisitor.
55

56
57     public void visitProgramField(ProgramClass programClass, ProgramField programField)
58     {
59         // Does the field have optimization info?
60
if (FieldOptimizationInfo.getFieldOptimizationInfo(programField) != null)
61         {
62             memberVisitor.visitProgramField(programClass, programField);
63         }
64     }
65
66
67     public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
68     {
69         // Does the field have optimization info?
70
if (FieldOptimizationInfo.getFieldOptimizationInfo(libraryField) != null)
71         {
72             memberVisitor.visitLibraryField(libraryClass, libraryField);
73         }
74     }
75
76
77     public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
78     {
79         // Does the method have optimization info?
80
if (MethodOptimizationInfo.getMethodOptimizationInfo(programMethod) != null)
81         {
82             memberVisitor.visitProgramMethod(programClass, programMethod);
83         }
84     }
85
86
87     public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
88     {
89         // Does the method have optimization info?
90
if (MethodOptimizationInfo.getMethodOptimizationInfo(libraryMethod) != null)
91         {
92             memberVisitor.visitLibraryMethod(libraryClass, libraryMethod);
93         }
94     }
95 }
96
Popular Tags