Object (@NotNull final DataProvider dataProvider) { // Try to detect multi-selection. PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataProvider); if (psiElements != null) { for (PsiElement elem : psiElements) { VirtualFile virtualFile = PsiUtilCore.getVirtualFile(elem); if (virtualFile != null) return virtualFile; } } VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataProvider); if (virtualFiles != null && virtualFiles.length == 1) { return virtualFiles[0]; } PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataProvider); if (psiFile != null) { return psiFile.getVirtualFile(); } PsiElement elem = CommonDataKeys.PSI_ELEMENT.getData(dataProvider); if (elem == null) { return null; } return PsiUtilCore.getVirtualFile(elem); }