PsiElement (@NotNull PsiElement start, @NotNull PsiElement end) { if (PsiTreeUtil.isAncestor(start, end, true)) { PsiElement o = start.getFirstChild(); while (o != null && o.getParent() != end.getParent()) { PsiElement first = o.getFirstChild(); if (first == null) return o; o = first; } return o; } return start; }