Methods INRIA内部方法调用构造函数
我试图从run()方法提取对构造函数的调用。下面是我试图解析的代码Methods INRIA内部方法调用构造函数,methods,call,inria-spoon,Methods,Call,Inria Spoon,我试图从run()方法提取对构造函数的调用。下面是我试图解析的代码 SwingUtilities.invokeLater(new Runnable() { public void run() { // Create the two text areas TextAreaFigure ta = new TextAreaFigure(); ta.setBounds(new Point2D.Dou
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()中声明的。我不确定这是spoon中的一个bug,还是我使用了错误的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();
}
}
}
}
for(CtMethod:clazz.getMethods()){
List ctNewClasses=method.getElements(新类型过滤器(CtConstructorCall.class));
对于(CTConstructor调用myclass:CTNewClass){
//建造师
if(CtConstructorCall的myclass实例){
System.out.println(“是”);
List methoddeclared=myclass.getElements(新类型过滤器(CtMethod.class));
对于(CtMethod meth:methoddeclared){
methodinside=meth.getSignature();
methodinsideclass=clazz.getQualifiedName();
字符串mymethod=methodinsideclass+““+methodinside;
ResultSet methodsinside=st.executeQuery(“从方法中选择方法。*,其中methods.fullmethod='“+mymethod+””);
//while(callingmethodsrefined.next()){
if(methodsinside.next()){
MethodIDINSIDE=methodsinside.getString(“id”);
classnameinide=methodsinside.getString(“classname”);
ClassInSide=methodsinside.getString(“classid”);
//System.out.println(“被调用方方法ID:+CALLEEID”);
}
列表构造函数=meth.getElements(新的类型过滤器(CtConstructorCall.class));
对于(ctconstructorcallcons:constructors){
字符串构造函数ClassName=cons.getExecutable().getDeclaringType().toString();
}
}
}
}
我不确定这是spoon中的一个bug,还是我使用了错误的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();
}
}
}
}
我是Spoon的贡献者之一。在我看来,您使用的API是正确的,但我不确定,因为您的示例在这里看起来有点混乱。
我认为如果您在上打开一个问题并指定:
然后我们可以调查到底发生了什么。谢谢!谢谢你的回复,我刚刚在github存储库中发布了一个问题,你在下面向我指出了这个问题