String (final PsiElement insertedElement, final int offsetInFile, ElementPattern<Character> prefixStartTrim) { if(insertedElement == null) return ""; final Document document = insertedElement.getContainingFile().getViewProvider().getDocument(); assert document != null; LOG.assertTrue(!PsiDocumentManager.getInstance(insertedElement.getProject()).isUncommited(document), "Uncommitted"); final String prefix = CompletionUtil.findReferencePrefix(insertedElement, offsetInFile); if (prefix != null) return prefix; if (insertedElement.getTextRange().equals(insertedElement.getContainingFile().getTextRange()) || insertedElement instanceof PsiComment) { return CompletionUtil.findJavaIdentifierPrefix(insertedElement, offsetInFile); } return findPrefixDefault(insertedElement, offsetInFile, prefixStartTrim); }