Parsing INRIA SPOON嵌套方法和嵌套方法调用
我试图使用INRIA开发的SPOON检索程序中的所有方法以及所有方法调用。对于普通方法,我可以这样做,但是,我不能检索嵌套方法,也不能检索嵌套方法调用 这是我正在解析的一段代码,在本例中,我想收集嵌套在没有main的情况下的run()方法,我还想检索run对类ElbowLiner的构造函数的调用,你能告诉我如何实现这一点吗。我使用getAll(true)检索所有内容,包括嵌套的方法调用,但它不起作用,我无法检索下面代码片段中的run(),也无法检索从run()到ElbowLiner构造函数的方法调用Parsing INRIA SPOON嵌套方法和嵌套方法调用,parsing,methods,function-call,inria-spoon,Parsing,Methods,Function Call,Inria Spoon,我试图使用INRIA开发的SPOON检索程序中的所有方法以及所有方法调用。对于普通方法,我可以这样做,但是,我不能检索嵌套方法,也不能检索嵌套方法调用 这是我正在解析的一段代码,在本例中,我想收集嵌套在没有main的情况下的run()方法,我还想检索run对类ElbowLiner的构造函数的调用,你能告诉我如何实现这一点吗。我使用getAll(true)检索所有内容,包括嵌套的方法调用,但它不起作用,我无法检索下面代码片段中的run(),也无法检索从run()到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);
}
});
}
在Spoon中,从模型检索所有方法的最简单方法是使用
CtMethod
处理器。您可以尝试以下代码:
public class MyProcessForMethods extends AbstractProcessor<CtMethod> {
public void process(CtMethod myMethod) {
System.out.println(mymethod.getSimpleName());
}
}
每次在模型中找到新的CtMethod
时,都将调用方法process()
:然后它将处理嵌套在内部类型和普通方法中的方法
不要犹豫,打开一个关于Spoon Github存储库的问题,并提供更多关于您现在如何使用Spoon的见解
Launcher launcher = new Launcher();
launcher.addInputResource("/path/to/your/source");
launcher.addProcessor(new MyProcessForMethods());
launcher.run();