private static @NotNull List<VirtualFile> collectJavaFiles(VirtualFile dir, Project project) {
    final List<VirtualFile> javaFiles = new ArrayList<>();
    ProjectFileIndex.getInstance(project).iterateContentUnderDirectory(dir, file -> {
      if (file.getName().endsWith(".java")) {
        javaFiles.add(file);
      }
      return true;
    });
    return javaFiles;
  }
private static @NotNull List<VirtualFile> collectJavaFiles(VirtualFile dir, Project project)