PsiElement (@NotNull PsiFile file, int offset, boolean searchInInjectedFragment) { PsiElement element = null; if (searchInInjectedFragment && !InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) { PsiDocumentManager documentManager = PsiDocumentManager.getInstance(file.getProject()); Document document = documentManager.getDocument(file); if (document != null && !documentManager.isCommitted(document)) { LOGGER.error("Trying to access to injected template context on uncommited document, offset = " + offset, CoreAttachmentFactory.createAttachment(file.getVirtualFile())); } else { element = InjectedLanguageManager.getInstance(file.getProject()).findInjectedElementAt(file, offset); } } if (element == null) { element = PsiUtilCore.getElementAtOffset(file, offset); } return element; }