TextRange (@NotNull Object occurrence) { if (occurrence instanceof PsiElement) { return ((PsiElement)occurrence).getTextRange(); } else if (occurrence instanceof UsageInfo) { Segment segment = ((UsageInfo)occurrence).getSegment(); assert segment != null; return TextRange.create(segment); } else { //assert occurrence instanceof Target; //noinspection unchecked return ((Target)occurrence).getTextRange(); } }