@Override
  public void collectRefElements(final PsiElement element,
                                 final RenameProcessor renameProcessor,
                                 @NotNull final String newName,
                                 final Collection<? super PsiElement> elementsToInvert) {
    collectRefsToInvert(element, elementsToInvert);

    if (element instanceof PsiMethod) {
      final Collection<PsiMethod> overriders = OverridingMethodsSearch.search((PsiMethod)element).findAll();
      if (renameProcessor != null) {
        for (PsiMethod overrider : overriders) {
          renameProcessor.addElement(overrider, newName);
        }
      }

      Collection<PsiMethod> allMethods = new HashSet<>(overriders);
      allMethods.add((PsiMethod)element);

      for (PsiMethod method : allMethods) {
        method.accept(new JavaRecursiveElementWalkingVisitor() {
          @Override public void visitReturnStatement(@NotNull PsiReturnStatement statement) {
            final PsiExpression returnValue = statement.getReturnValue();
            if (returnValue != null && PsiTypes.booleanType().equals(returnValue.getType())) {
              elementsToInvert.add(returnValue);
            }
          }

          @Override
          public void visitClass(@NotNull PsiClass aClass) {}

          @Override
          public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) {}
        });
      }
    }
    else if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod method) {
      int index = method.getParameterList().getParameterIndex((PsiParameter)element);
      assert index >= 0;
      final Query<PsiReference> methodQuery = MethodReferencesSearch.search(method);
      final Collection<PsiReference> methodRefs = methodQuery.findAll();
      for (PsiReference ref : methodRefs) {
        PsiElement parent = ref.getElement().getParent();
        if (parent instanceof PsiAnonymousClass) {
          parent = parent.getParent();
        }
        if (parent instanceof PsiCall call) {
          final PsiReferenceExpression methodExpression = call instanceof PsiMethodCallExpression ?
                                                          ((PsiMethodCallExpression)call).getMethodExpression() :
                                                          null;
          final PsiExpressionList argumentList = call.getArgumentList();
          if (argumentList != null) {
            final PsiExpression[] args = argumentList.getExpressions();
            if (index < args.length) {
              if (methodExpression == null ||
                  canInvertReferenceElement(methodExpression,
                                            args[index] instanceof PsiReferenceExpression &&
                                            ((PsiReferenceExpression)args[index]).resolve() == element)) {
                elementsToInvert.add(args[index]);
              }
            }
          }
        }
      }

      final Collection<PsiMethod> overriders = OverridingMethodsSearch.search(method).findAll();
      for (PsiMethod overrider : overriders) {
        final PsiParameter overriderParameter = overrider.getParameterList().getParameters()[index];
        if (renameProcessor != null) {
          renameProcessor.addElement(overriderParameter, newName);
        }
        collectRefsToInvert(overriderParameter, elementsToInvert);
      }
    }
  }
@Override
  public void collectRefElements(final PsiElement element,
                                 final RenameProcessor renameProcessor,
                                 @NotNull final String newName,
                                 final Collection<? super PsiElement> elementsToInvert)