INRIA SPOON nested methods and nested methodcalls

116 Views Asked by At

I am trying to use SPOON developed by INRIA to retrieve all the methods in a program as well as all the method calls. I am able to do so for normal methods, however, I am not able to retrieve nested methods and I am not able to retrieve nested method calls either.

Here is a fragment of code that I am parsing, In this case, I would like spoon to collect the method run() which is nested without the main, I would also like to retrieve the call from run to the constructor of the class ElbowLiner, could you please give me directions on how to achieve this. I used getAll(true) to retrieve everything including the nested method calls but it did not work, I was not able to retrieve run() in the code fragment below and I was not able to retrieve the method call either from run() to the constructor of ElbowLiner

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            // Create the two text areas
            TextAreaFigure ta = new TextAreaFigure();
            ta.setBounds(new Point2D.Double(10,10),new Point2D.Double(100,100));

            TextAreaFigure tb = new TextAreaFigure();
            tb.setBounds(new Point2D.Double(210,110),new Point2D.Double(300,200));

            // Create an elbow connection
            ConnectionFigure cf = new LineConnectionFigure();
            cf.setLiner(new ElbowLiner());

            // Connect the figures
            cf.setStartConnector(ta.findConnector(Geom.center(ta.getBounds()), cf));
            cf.setEndConnector(tb.findConnector(Geom.center(tb.getBounds()), cf));

            // Add all figures to a drawing
            Drawing drawing = new DefaultDrawing();
            drawing.add(ta);
            drawing.add(tb);
            drawing.add(cf);

            // Show the drawing
            JFrame f = new JFrame("My Drawing");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(400,300);

            DrawingView view = new DefaultDrawingView();
            view.setDrawing(drawing);
            f.getContentPane().add(view.getComponent());

            f.setVisible(true);
        }
    });
}
1

There are 1 best solutions below

0
On

The easiest way in Spoon to retrieve all methods from a model is to use a processor of CtMethod you can try a code like this one:

public class MyProcessForMethods extends AbstractProcessor<CtMethod> {
   public void process(CtMethod myMethod) {
      System.out.println(mymethod.getSimpleName());
   }
}

and to use it:

Launcher launcher = new Launcher();
launcher.addInputResource("/path/to/your/source");
launcher.addProcessor(new MyProcessForMethods());
launcher.run();

The method process() will be called each time a new CtMethod is find in the model: then it will process as well method nested from inner types and normal methods.

Don't hesitate to open an issue on Spoon Github repository and to provide more insight on how you're using Spoon right now.