简体   繁体   中英

Get selected Java Element from editor in eclipse

I am working on an eclipse plugin, and I need to get the selected element from the active editor. I have already figured out (one way) to do this. Here are the key lines:

ITypeRoot root = EditorUtility.getEditorInputJavaElement(activeJavaEditor, false);
selectedElement = root.getElementAt(offset);

(This is similar to the answer the question Eclipse plugin : Get the enclosing class and member name )

But the problem that I'm having is that this will only return declared methods, types, fields, etc, and never invoked ones. For example, given this code in the active editor:

public void foo() {
    ClassA.run();
}

even if the caret is positioned over "ClassA" or "run," my code still returns the method "foo." Does anyone know how to also get invoked methods?

尝试改用ITypeRoot#codeSelect()。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM