PsiElement (final Project project) { if (project == null) return null; Editor selectedEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (selectedEditor == null) return null; Document document = selectedEditor.getDocument(); return PsiDocumentManager.getInstance(project).getPsiFile(document); }