6 Replies Latest reply: May 26, 2010 12:49 PM by DarrylBurke RSS

    java-soot issue - jimple line numbers??

      Hello everybody,

      I am trying to write a piece of java code that will convert a java class to jimple, print the jimple code along withe the line numbers and then give the line numbers for lines with "virtual invoke".

      The code that I have written so far looks like below:
      import soot.*;
      import java.util.*;
      import soot.util.*;
      import soot.jimple.Stmt;
      import soot.tagkit.LineNumberTag;
      import soot.baf.*;
      import java.io.*;
      public class GetStmts4 extends BodyTransformer implements RetInst
          private static GetStmts4 instance = new GetStmts4();
          private GetStmts4() {};
          public static GetStmts4 v()
           return instance;
          public static void main(String args[])
              PackManager.v().getPack("jtp").add(new Transform ("jtp.annotexample",GetStmts4.v()));
          protected void internalTransform(Body b, String phaseName, Map options)
           int linenum = 0;
           int count = 0;
           int array[] = new int[20];
           PatchingChain units = b.getUnits();
           Iterator unitsIt = units.iterator();
                Unit unit = (Unit)unitsIt.next();
                LineNumberTag tag = (LineNumberTag) unit.getTag("LineNumberTag");
                RetInst rt = (RetInst)unit;
                int index = rt.getIndex();  // to get the index of the jimple lines ???
                System.out.println("Index is :" + index);
                if (tag != null)
      //the following piece of code gives me the line number but its in the java source code....i need the line numbers of jimple code.
                     System.out.println("java line number:"+tag.getLineNumber());
                     //System.out.println("tag name:"+tag.getName());
                     String string = unit.toString();
                          System.out.println("line number with virtualinvoke:"+tag.getLineNumber());
                          array[count] = tag.getLineNumber();
                          System.out.println("the " +count+ " element in array is : " +array[count]);
           for(int k = 1;k <= count; k++)
      So I am getting the following error message:
      GetStmts4.java:9: GetStmts4 is not abstract and does not override abstract method setIndex(int) in soot.baf.RetInst
      public class GetStmts4 extends BodyTransformer implements RetInst