protected boolean isReferenceAtCaret(PsiElement selectedElement, PsiReference ref, int offset) {
    return isReferenceAtCaret(selectedElement, ref) && 
           checkRangeContainsOffset(offset, ref.getRangeInElement(), ref.getElement());
  }
protected boolean isReferenceAtCaret(PsiElement selectedElement, PsiReference ref, int offset)