KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > LineNumberAdder


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;
21
22 import soot.*;
23 import java.util.*;
24 import soot.jimple.*;
25 import soot.tagkit.*;
26
27 public class LineNumberAdder extends SceneTransformer {
28
29     public LineNumberAdder( Singletons.Global g) {}
30     public static LineNumberAdder v() { return G.v().soot_jimple_toolkits_annotation_LineNumberAdder();}
31
32     public void internalTransform(String JavaDoc phaseName, Map opts){
33
34         Iterator it = Scene.v().getApplicationClasses().iterator();
35         while (it.hasNext()){
36             SootClass sc = (SootClass)it.next();
37             // make map of first line to each method
38
HashMap lineToMeth = new HashMap();
39             Iterator methIt = sc.getMethods().iterator();
40             while (methIt.hasNext()){
41                 SootMethod meth = (SootMethod)methIt.next();
42                 if (!meth.isConcrete()) continue;
43                 Body body = meth.retrieveActiveBody();
44                 Stmt s = (Stmt)body.getUnits().getFirst();
45                 while (s instanceof IdentityStmt){
46                     s = (Stmt)body.getUnits().getSuccOf(s);
47                 }
48                 if (s.hasTag("LineNumberTag")){
49                     LineNumberTag tag = (LineNumberTag)s.getTag("LineNumberTag");
50                     lineToMeth.put(new Integer JavaDoc(tag.getLineNumber()), meth);
51                 }
52             }
53             Iterator methIt2 = sc.getMethods().iterator();
54             while (methIt2.hasNext()){
55                 SootMethod meth = (SootMethod)methIt2.next();
56                 if (!meth.isConcrete()) continue;
57                 Body body = meth.retrieveActiveBody();
58                 Stmt s = (Stmt)body.getUnits().getFirst();
59                 while (s instanceof IdentityStmt){
60                     s = (Stmt)body.getUnits().getSuccOf(s);
61                 }
62                 if (s.hasTag("LineNumberTag")){
63                     LineNumberTag tag = (LineNumberTag)s.getTag("LineNumberTag");
64                     int line_num = tag.getLineNumber() - 1;
65                     // already taken
66
if (lineToMeth.containsKey(new Integer JavaDoc(line_num))){
67                         meth.addTag(new LineNumberTag(line_num + 1));
68                     }
69                     // still available - so use it for this meth
70
else {
71                         meth.addTag(new LineNumberTag(line_num));
72                     }
73                 }
74             }
75             
76         }
77     }
78 }
79
Popular Tags