public static boolean treeWalkUp(@NotNull PsiElement entrance,
                                   @Nullable PsiElement maxScope,
                                   @NotNull PairProcessor<? super PsiElement, ? super PsiElement> eachScopeAndLastParent) {
    PsiElement prevParent = null;
    PsiElement scope = entrance;

    while (scope != null) {
      if (!eachScopeAndLastParent.process(scope, prevParent)) return false;

      if (scope == maxScope) break;
      prevParent = scope;
      scope = prevParent.getContext();
    }

    return true;
  }
public static boolean treeWalkUp(@NotNull PsiElement entrance,
                                   @Nullable PsiElement maxScope,
                                   @NotNull PairProcessor<? super PsiElement, ? super PsiElement> eachScopeAndLastParent)