PsiElement (Editor editor, PsiFile file) { PsiElement element = null; Document doc = editor.getDocument(); PsiFile a_file = file; if (a_file == null) { Project project = editor.getProject(); if (project != null) a_file = PsiDocumentManager.getInstance(project).getPsiFile(doc); } if (a_file != null) element = a_file.findElementAt(editor.getCaretModel().getOffset()); return element; }