private static @NotNull String suggestUniqueVariableName(@NotNull @NonNls String baseName,
                                                           PsiElement place,
                                                           boolean lookForward,
                                                           Predicate<? super PsiVariable> canBeReused,
                                                           @Nullable Predicate<String> additionalValidator) {
    int index = 0;
    PsiElement scope = PsiTreeUtil.getNonStrictParentOfType(place, PsiStatement.class, PsiCodeBlock.class, PsiMethod.class);
    NextName:
    while (true) {
      String name = baseName;
      if (index > 0) {
        name += index;
      }
      index++;
      if (additionalValidator != null && !additionalValidator.test(name)) {
        continue;
      }
      if (PsiUtil.isVariableNameUnique(name, place)) {
        if (lookForward) {
          final String name1 = name;
          PsiElement run = scope;
          while (run != null) {
            class CancelException extends RuntimeException {
            }
            try {
              run.accept(new JavaRecursiveElementWalkingVisitor() {
                @Override
                public void visitAnonymousClass(final @NotNull PsiAnonymousClass aClass) {
                }

                @Override public void visitVariable(@NotNull PsiVariable variable) {
                  if (name1.equals(variable.getName()) && !canBeReused.test(variable)) {
                    throw new CancelException();
                  }
                }
              });
            }
            catch (CancelException e) {
              continue NextName;
            }
            run = run.getNextSibling();
            if (scope instanceof PsiMethod) {//do not check next member for param name conflict
              break;
            }
          }

        }
        return name;
      }
    }
  }
private static @NotNull String suggestUniqueVariableName(@NotNull @NonNls String baseName,
                                                           PsiElement place,
                                                           boolean lookForward,
                                                           Predicate<? super PsiVariable> canBeReused,
                                                           @Nullable Predicate<String> additionalValidator)