PsiElement (final Editor editor, final Project project) { int offset = editor.getCaretModel().getOffset(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return null; PsiElement element = file.findElementAt(offset); if (element == null) element = file; return element; }