public static void optimizeDependencies(@NotNull PsiJavaModule currentModule, @NotNull PsiJavaModule selectedDependency) {
    Map<PsiJavaModule, PsiRequiresStatement> requires = new HashMap<>();
    for (PsiRequiresStatement require : currentModule.getRequires()) {
      PsiJavaModule resolvedModule = require.resolve();
      if (resolvedModule != null) {
        requires.put(resolvedModule, require);
      }
    }

    Set<PsiJavaModule> redundant = new HashSet<>();
    for (PsiJavaModule module : requires.keySet()) {
      if (module.getName().equals(selectedDependency.getName())) continue;
      if (reads(selectedDependency, module)) redundant.add(module);
    }

    for (PsiJavaModule module : redundant) {
      requires.get(module).delete();
    }
  }
public static void optimizeDependencies(@NotNull PsiJavaModule currentModule, @NotNull PsiJavaModule selectedDependency)