我正在使用eclipse插件,并且需要从活动编辑器中获取选定的元素。我已经想出了(单向)做到这一点。下面是关键线路:从eclipse中的编辑器获取选定的Java元素
ITypeRoot root = EditorUtility.getEditorInputJavaElement(activeJavaEditor, false);
selectedElement = root.getElementAt(offset);
(这是类似的回答这个问题Eclipse plugin : Get the enclosing class and member name)
但是我遇到的问题是,这将只返回声明的方法,类型,字段等,而且从未调用过。例如,考虑到活动的编辑器的代码:“foo”的
public void foo() {
ClassA.run();
}
即使如果光标定位在“ClassA的”或“跑,”我的代码仍返回方法有谁知道如何也得到调用方法?
此线程可能会帮助你:http://stackoverflow.com/questions/10453617/how-can-i-get-the-selected-code-in-eclipse/ – Alex