@Nullable
  private static <T> T findOccurrence(@Nullable PsiElement start,
                                      @NotNull PsiLocalVariable variable,
                                      @NotNull Function<? super PsiElement, ? extends PsiElement> advance,
                                      @NotNull BiFunction<? super PsiElement, ? super PsiLocalVariable, ? extends T> search) {
    PsiElement candidate = advance.apply(start);
    T result = search.apply(candidate, variable);
    if (result != null) {
      return result;
    }
    if (canRemoveDeclaration(variable)) {
      for (; candidate != null; candidate = advance.apply(candidate)) {
        result = search.apply(candidate, variable);
        if (result != null) {
          return result;
        }
        if (variableIsUsed(variable, candidate)) {
          break;
        }
      }
    }
    return null;
  }
@Nullable
  private static <T> T findOccurrence(@Nullable PsiElement start,
                                      @NotNull PsiLocalVariable variable,
                                      @NotNull Function<? super PsiElement, ? extends PsiElement> advance,
                                      @NotNull BiFunction<? super PsiElement, ? super PsiLocalVariable, ? extends T> search)