PsiElement (PsiElement start, PsiElement end) { if (end == null || start == end) { return start; } TextRange endRange = end.getTextRange(); PsiElement parent = start.getContext(); while (parent != null && !parent.getTextRange().contains(endRange)) { parent = parent.getContext(); } return parent; }