Project (@NotNull DataProvider dataProvider) { Project project = CommonDataKeys.PROJECT.getData(dataProvider); if (project != null) return project; Editor editor = EDITOR.getData(dataProvider); project = editor != null ? editor.getProject() : null; if (project != null) return project; PsiFile file = CommonDataKeys.PSI_FILE.getData(dataProvider); if (file != null && file.isValid()) return file.getProject(); //todo remove this part, it can be too slow for such simple rule PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataProvider); if (element == null) { PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataProvider); if (psiElements != null && psiElements.length > 0) { element = psiElements[0]; } } if (element == null || !element.isValid()) return null; return element.getProject(); }