private static void processReference(final CompletionResultSet result,
                                       final int startOffset,
                                       final PairConsumer<? super PsiReference, ? super CompletionResultSet> consumer,
                                       final PsiReference reference) {
    PsiElement element = reference.getElement();
    final int offsetInElement = startOffset - element.getTextRange().getStartOffset();
    if (!ReferenceRange.containsOffsetInElement(reference, offsetInElement)) {
      return;
    }

    TextRange range = reference.getRangeInElement();
    try {
      final String prefix = element.getText().substring(range.getStartOffset(), offsetInElement);
      consumer.consume(reference, result.withPrefixMatcher(prefix));
    }
    catch (StringIndexOutOfBoundsException e) {
      LOG.error("Reference=" + reference +
                "; element=" + element + " of " + element.getClass() +
                "; range=" + range +
                "; offset=" + offsetInElement,
                e);
    }
  }
private static void processReference(final CompletionResultSet result,
                                       final int startOffset,
                                       final PairConsumer<? super PsiReference, ? super CompletionResultSet> consumer,
                                       final PsiReference reference)