Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone built a program slicer in Java?

Tags:

java

slice

I have to build a program slicer in java to slice source code based on a slicing criterion. I see there are a very few libraries out there for this purpose. Notwithstanding, I would like to try this myself. I have read some publications on the topic that include the use of a dependence graph to work out the data and control dependencies in a program. A slicing algorithm can then be used in conjunction with a slicing criterion to generate slices of the java program. Has anyone done this type of thing before? If so, could you perhaps point me in the right direction to get started with this? I have searched and search and cannot figure out where to start, what APIs exist (if any).

An Example would be:

public class Foo {
   public void fooBar() {
      int x = 10;
      int y = 12; 
      String s = "";
      for(int j=0; j<10; j++) {
         s += x;
         x++;
         y += 3;
      }
      System.out.println("y value " + y);
   }
}

If a slicing criterion (13, y) is choosen, where 13 is the last line in the above code, then the result will be

public class Foo {
   public void fooBar() {
      int y = 12;
      for(int j=0; j<10; j++) {
         y += 3;
      }
   }
}

The slicing criterion returns all of the statements that may affect variable 'y' at line 13.

like image 730
Joeblackdev Avatar asked Jun 04 '11 18:06

Joeblackdev


1 Answers

There is very less work in this area. You can reuse code of some open source utility like checkstyle or yasca. Then you can apply your own implementation logic for the slicing.

like image 149
Kamahire Avatar answered Oct 21 '22 06:10

Kamahire