【问题标题】:INRIA SPOON INNER METHODS CALLING CONSTRUCTORSINRIA SPOON 调用构造函数的内部方法
【发布时间】:2019-01-15 23:01:03
【问题描述】:

我正在尝试将调用从方法 run() 提取到构造函数。这是我要解析的代码

        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);
        }
    });
}

这是我用来提取从方法 run() 到构造函数的调用的代码。我遇到的问题是最后一行: String constructorClassName= cons.getExecutable().getDeclaringType().toString();返回错误的类名,而不是得到“jhot.draw.TextAreaFigure()”作为我得到“jhot.mini.samples.TextAreaFigure()”的名称。我正在解析的文件位于“jhot.mini.samples”下,而构造函数在“jhot.draw.TextAreaFigure()”中声明。我不确定这是勺子中的错误,还是我使用错误的 API 来检索构造函数调用。

   for(CtMethod<?> method :clazz.getMethods()) {
    List<CtConstructorCall> ctNewClasses = method.getElements(new TypeFilter<CtConstructorCall>(CtConstructorCall.class));

    for( CtConstructorCall myclass: ctNewClasses) {
        //CONSTRUCTOR 

        if(myclass instanceof CtConstructorCall<?>) {
            System.out.println("yes");
            List<CtMethod> methoddeclared = myclass.getElements(new TypeFilter<CtMethod>(CtMethod.class)); 
            for(CtMethod<?> meth: methoddeclared) {
                 methodinside=meth.getSignature(); 
                 methodinsideclass=clazz.getQualifiedName(); 

                String mymethod=methodinsideclass+"."+methodinside; 



                ResultSet methodsinside = st.executeQuery("SELECT methods.* from methods where methods.fullmethod='"+mymethod+"'"); 
                //while(callingmethodsrefined.next()){
                if(methodsinside.next()) {
                     MethodIDINSIDE = methodsinside.getString("id"); 
                     CLASSNAMEINSIDE = methodsinside.getString("classname"); 
                     CLASSIDINSIDE = methodsinside.getString("classid"); 

                    //System.out.println("CALLEE METHOD ID: "+ CALLEEID);
                }

                        List<CtConstructorCall> constructors = meth.getElements(new TypeFilter<CtConstructorCall>(CtConstructorCall.class)); 
                        for(CtConstructorCall<?> cons: constructors) {  



                            String constructorClassName=    cons.getExecutable().getDeclaringType().toString(); 




                }
                        }
                    }

        }

【问题讨论】:

    标签: methods call inria-spoon


    【解决方案1】:

    我不确定这是否是勺子中的错误,或者我是否使用了错误的 API 来检索构造函数调用。

    我是 Spoon 的贡献者之一。在我看来,您使用的是正确的 API,但我不确定,因为您的示例在这里看起来有点乱。 我认为如果您在Spoon Github repository 上打开一个问题并指定:

    1. 您正在从事的项目(如果它是开源的)
    2. 如何启动 Spoon(Spoon 的版本、参数等)
    3. 你到底有什么期望

    然后我们可以进行调查以确切检查那里发生的情况。谢谢!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2018-08-20
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    相关资源
    最近更新 更多