PsiElement () { Editor editor = getCompletionEditor(); int findTargetFlags = TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED; PsiElement element = TargetElementUtil.findTargetElement(editor, findTargetFlags); // if no references found in injected fragment, try outer document if (element == null && editor instanceof EditorWindow) { element = TargetElementUtil.findTargetElement(((EditorWindow)editor).getDelegate(), findTargetFlags); } if (element == null) { fail("element not found in file " + myFile.getName() + " at caret position offset " + myEditor.getCaretModel().getOffset() + "," + " psi structure:\n" + DebugUtil.psiToString(getFile(), false, true)); } return element; }