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?

Was it helpful?

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;
    } 
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top