2

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?

1

1 Answer 1

1

Try ITypeRoot#codeSelect() instead.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm not familiar with the Class#method() notation. Could you please clarify? Where in @Reyan's code should this call go?
'#' is just a variant of '.' In this case, it just means to call codeSelect() on an object of type ITypeRoot. Thus I replaced "root.getElementAt(offset)" with "root.codeSelect(offset, length)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.