PsiElement (@NotNull PsiElement scope, @NotNull TextRange range) { PsiElement psiElement = scope.findElementAt(range.getStartOffset()); while (psiElement != null && !psiElement.getTextRange().contains(range)) { if (psiElement == scope) return null; psiElement = psiElement.getParent(); } return psiElement; }