Question

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?

Était-ce utile?

La solution

  public class MyAction extends AnAction {
    public void actionPerformed(AnActionEvent e) {
      VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
      String fileName = vFile != null ? vFile.getName() : null;
    } 
  }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top