finding out the current class being edited

I need to get the current class and method where the caret is, in the file the user is editing. Is there an easier solution than getting the caret's position (line, column), the classes of the file and then finding out in what class the caret is?

Thank you for any help,
Diana

3 comments
Comment actions Permalink

If you need this when the user invokes some action, you can get the information from the AnActionEvent class. Something like this:


Bas

0
Comment actions Permalink

Thank you very much for the fast reply. It gives me a point to start.
Still, I don't have an AnActionEvent. What I would actually need is to know when the user changes the method/class he is editing in the current file and the current class/method that is being edited.
Given that I could not find to register a listener for such an event, I thought that a solution might be to register a listener for the caret and to look then for the rest. If someone knows a better solution, I would appreciate it.

Thanks,
Diana

0
Comment actions Permalink

I don't know if this work but did you try;

DataManager.getInstance().getDataContext().getData(DataConstants.PSI_ELEMENT)

With some luck this should return the current PsiElement in the editor.

0

Please sign in to leave a comment.