find the current class
Hi,
i have an action which extends AnAction class, i want to find the current class in action performed.
I tried
final PsiElement element =e.getData(DataKeys.PSI_ELEMENT); and also
final PsiElement element =(PsiElement)dataContext.getData(DataConstants.PSI_ELEMENT);
both of these gives null. How can i find the current class
请先登录再写评论。
Jetbrains have a lot of useful articles on their confluence page that are worth looking at, for instance here are a few ways to achieve what you're after - http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview#IntelliJIDEAArchitecturalOverview-PsiFiles
For your code to work, the focus (or Cursor) has to be in the Editor. If not, you would get NULL.
Following code will give you the class name :
Or if you want the actual path to the file, then use the following code :
You can also get the Virtual File directly by :