public static boolean isJarAttached(@NotNull Location location,
                                      final PsiDirectory[] directories,
                                      final String... fqns) {
    final Project project = location.getProject();
    if (DumbService.isDumb(project)) return false; //disable creation of junit/testng package configurations in dumb mode
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final Module locationModule = location.getModule();
    VirtualFile locationVirtualFile = location.getVirtualFile();
    String arg2 = locationVirtualFile != null ? locationVirtualFile.getPath() : null;
    if (locationModule != null && !Objects.equals(project.getBasePath(), arg2)) {
      for (String fqn : fqns) {
        if (facade.findClass(fqn, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(locationModule, true)) != null) return true;
      }
    }
    else {
      for (PsiDirectory directory : directories) {
        final Module module = ModuleUtilCore.findModuleForFile(directory.getVirtualFile(), project);
        if (module != null) {
          GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, true);
          for (String fqn : fqns) {
            if (facade.findClass(fqn, scope) != null) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
public static boolean isJarAttached(@NotNull Location location,
                                      final PsiDirectory[] directories,
                                      final String... fqns)