protected static Pair<PsiElement, PsiElement> getElementRange(PsiElement parent, PsiElement element1, PsiElement element2) {
    if (PsiTreeUtil.isAncestor(element1, element2, false) || PsiTreeUtil.isAncestor(element2, element1, false)) {
      return Pair.create(parent, parent);
    }

    // find nearest children that are parents of elements
    while (element1 != null && element1.getParent() != parent) element1 = element1.getParent();
    while (element2 != null && element2.getParent() != parent) element2 = element2.getParent();
    if (element1 == null || element2 == null) return null;

    if (element1 != element2) {
      assert element1.getTextRange().getEndOffset() <= element2.getTextRange().getStartOffset() :
        element1.getTextRange() + "-" + element2.getTextRange() + element1 + element2;
    }

    return Pair.create(element1, element2);
  }
protected static Pair<PsiElement, PsiElement> getElementRange(PsiElement parent, PsiElement element1, PsiElement element2)