In the IntelliJ IDEA plugin action class, I want to get the Java class file name which user is currently viewing. How would I get that?

In IntelliJ IDEA, if we click Analyse -> Inspect Code, it will show a window to choose scope, in that it will show the current file name also. Similar to that view, I want to get the current file name in plugin action class. How could I do that?

有帮助吗?

解决方案

  public class MyAction extends AnAction {
    public void actionPerformed(AnActionEvent e) {
      VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
      String fileName = vFile != null ? vFile.getName() : null;
    } 
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top