KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > methods > UnreachableMethodsTagger


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package soot.jimple.toolkits.annotation.methods;
21 import soot.*;
22 import java.util.*;
23 import soot.toolkits.graph.*;
24 import soot.toolkits.scalar.*;
25 import soot.tagkit.*;
26 import soot.jimple.*;
27 import soot.util.queue.*;
28
29 /** A scene transformer that adds tags to unused methods. */
30 public class UnreachableMethodsTagger extends SceneTransformer
31 {
32     public UnreachableMethodsTagger(Singletons.Global g){}
33     public static UnreachableMethodsTagger v() { return G.v().soot_jimple_toolkits_annotation_methods_UnreachableMethodsTagger();}
34
35     protected void internalTransform(String JavaDoc phaseName, Map options){
36
37         // make list of all unreachable methods
38
ArrayList methodList = new ArrayList();
39         
40         Iterator getClassesIt = Scene.v().getApplicationClasses().iterator();
41         while (getClassesIt.hasNext()) {
42             SootClass appClass = (SootClass)getClassesIt.next();
43             
44             Iterator getMethodsIt = appClass.getMethods().iterator();
45             while (getMethodsIt.hasNext()) {
46                 SootMethod method = (SootMethod)getMethodsIt.next();
47                 //System.out.println("adding method: "+method);
48
if (!Scene.v().getReachableMethods().contains(method)){
49                     methodList.add(method);
50                 }
51             }
52         }
53         
54         // tag unused methods
55
Iterator unusedIt = methodList.iterator();
56         while (unusedIt.hasNext()) {
57             SootMethod unusedMethod = (SootMethod)unusedIt.next();
58             unusedMethod.addTag(new StringTag("Method "+unusedMethod.getName()+" is not reachable!", "Unreachable Methods"));
59             unusedMethod.addTag(new ColorTag(255,0,0,true, "Unreachable Methods"));
60             //System.out.println("tagged method: "+unusedMethod);
61

62         }
63     }
64
65 }
66
67
68
Popular Tags