String (@Nullable TextRange range, @Nullable PsiElement psiElement) { if (psiElement == null || !psiElement.isValid()) return ""; String ref = psiElement.getText(); if (range != null) { final TextRange elementRange = psiElement.getTextRange(); if (elementRange != null) { range = range.shiftRight(-elementRange.getStartOffset()); if (range.getStartOffset() >= 0 && ref.length() > range.getLength()) { ref = range.substring(ref); } } } ref = ref.replace('\n', ' ').trim(); ref = StringUtil.first(ref, 100, true); return ref.trim().replaceAll("\\s+", " "); }