user1919581
user1919581

Reputation: 511

How to get the current file name in plugin action class

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?

Upvotes: 3

Views: 1621

Answers (1)

yole
yole

Reputation: 97168

  public class MyAction extends AnAction {
    public void actionPerformed(AnActionEvent e) {
      VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
      String fileName = vFile != null ? vFile.getName() : null;
    } 
  }

Upvotes: 10

Related Questions