private static void processMethodsDuplicates(PsiMethod method) {
    Project project = method.getProject();
    final Runnable runnable = () -> {
      if (!method.isValid()) return;
      PsiClass containingClass = method.getContainingClass();
      if (containingClass != null) {

        final List<Match> duplicates = MethodDuplicatesHandler.hasDuplicates(containingClass, method);
        for (Iterator<Match> iterator = duplicates.iterator(); iterator.hasNext(); ) {
          Match match = iterator.next();
          final PsiElement matchStart = match.getMatchStart();
          if (PsiTreeUtil.isAncestor(method, matchStart, false)) {
            iterator.remove();
            break;
          }
        }
        if (!duplicates.isEmpty()) {
          MethodDuplicatesHandler.replaceDuplicate(project, Collections.singletonMap(method, duplicates), Collections.singleton(method));
        }
      }
    };
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(runnable),
                                                                      JavaRefactoringBundle.message("replace.method.code.duplicates.title"), true, project);
  }
private static void processMethodsDuplicates(PsiMethod method)