Hunter

Hunter is a tool that facilitates code reuse by finding relevant methods in large code bases and automatically synthesizing any necessary wrapper code. Since Hunter internally uses advanced program synthesis technology, it can automatically reuse existing methods even when code adaptation is necessary. We have implemented Hunter as an Eclipse plug-in and it is available on Eclipse marketplace.

Overview

The inputs to Hunter system include

For example, consider a Bresenham line drawing algorithm, which selects a vector of points on the raster to approximate a straight line, and is commonly used to draw lines on a computer screen. The method signature and a natural language description are
public class BresenhamLine {
    //@ Bresenham's line drawing algorithm
    public static void drawLine(MyPoint pt, Vector<MyPoint> res) {
        
    }
}
Note that MyPoint in the signature is a customized reference type, which has the following defintion
 public class MyPoint {
    int x;
    int y;
    // getters, setters
    // hashcode, equals ...
}
As a consequence, this MyPoint does not belong to the type hierarchy of all Point types in the corpus, e.g. java.awt.Point, etc. Thus, in a MyPoint context, it requires type conversion if we want to reuse code written using java.awt.Point. This task can be automatically finished by Hunter.

To validate the code that Hunter would synthesize, we provide a simple test suite to test the functionality of drawLine method
public class TestBresenhamLine {
    @Test
    public void test1() {
        Vector<MyPoint> v1 = new Vector<>();
        v1.add(new MyPoint(0, 0)); v1.add(new MyPoint(1, 1));
        v1.add(new MyPoint(2, 1)); v1.add(new MyPoint(3, 2));
        v1.add(new MyPoint(4, 2)); v1.add(new MyPoint(5, 3));
        Vector<MyPoint> res = new Vector<>();
        BresenhamLine.drawLine(new MyPoint(5, 3), res);
        assertEquals(v1, res);
    }
}
After saving all files and ensuring no compilation error (except missing the return statement), put cursor back into the desired method. Now we have two approaches to run the Hunter system A progress bar will pop up and shows the working progress. Once the entire reuse procedure is finished, Hunter will automatically insert the code snippet into the method body, as well as resolve all its dependencies. For brevity, here shows a simplified version of the code snippet
public class BresenhamLine {
    //@ Bresenham's line drawing algorithm
    public static void drawLine(MyPoint pt, Vector<MyPoint> res) {
        int v1 = pt.getX(); int v2 = pt.getY();
        Point[] v3 = external.bresenham(0, 0, v1, v2);
        for (Point v4 : v3) {
            int v5 = v4.getX(); int v6 = v4.getY();
            MyPoint v7 = new MyPoint(v5, v6);
            res.add(v7);
        }
    }
}

To get more information on installation and configuration, or to get more examples, please refer to Hunter User Manual.

Demo Video

YouTube link: Hunter Demo

Technical Report

Hunter: Next-Generation Code Reuse for Java. Yuepeng Wang, Yu Feng, Ruben Martins, Arati Kaushik, Isil Dillig and Steven P. Reiss

Dataset

To reproduce the result in our technical report, you need to download the dataset that contains 40 benchmarks, and import them into Eclipse.