Supplier<PsiElement> (@NotNull PsiElement element, @NotNull PsiElement scope) { return new Supplier<>() { PsiElement e = element; @Nullable @Override public PsiElement get() { if (e == null || e == scope) return null; PsiElement prev = e.getPrevSibling(); if (prev != null) { return e = PsiTreeUtil.getDeepestLast(prev); } else { PsiElement parent = e.getParent(); return e = parent == scope || parent instanceof PsiFile ? null : parent; } } }; }