docs: @SuppressWarnings("checkstyle:npathcomplexity")
  	protected void collectProjectFoldersFromDirectory(Collection<File> folders, File directory,
  			Set<String> directoriesVisited, boolean nestedProjects, IProgressMonitor monitor) {
  		if (monitor.isCanceled()) {
  			return;
  		}
  		monitor.subTask(NLS.bind(
  				Messages.SARLProjectConfigurator_0,
  				directory.getPath()));
  
  		final File[] contents = directory.listFiles();
  		if (contents == null) {
  			return;
  		}
  
  		Set<String> visited = directoriesVisited;
  		if (visited == null) {
  			visited = new HashSet<>();
  			try {
  				visited.add(directory.getCanonicalPath());
  			} catch (IOException exception) {
  				StatusManager.getManager().handle(
  						StatusUtil.newStatus(IStatus.ERROR, exception
  								.getLocalizedMessage(), exception));
  			}
  		}
  
  		final Set<File> subdirectories = new LinkedHashSet<>();
  
  		for (final File file : contents) {
  			if (file.isDirectory()) {
  				subdirectories.add(file);
  			} else if (file.getName().endsWith(this.fileExtension)) {
  				// Found a SARL file.
  				final File rootFile = getProjectFolderForSourceFolder(file.getParentFile());
  				if (rootFile != null) {
  					folders.add(rootFile);
  					return;
  				}
  			}
  		}
  
  		for (final File subdir : subdirectories) {
  			try {
  				final String canonicalPath = subdir.getCanonicalPath();
  				if (!visited.add(canonicalPath)) {
  					// already been here --> do not recurse
  					continue;
  				}
  			} catch (IOException exception) {
  				StatusManager.getManager().handle(
  						StatusUtil.newStatus(IStatus.ERROR, exception
  								.getLocalizedMessage(), exception));
  
  			}
  			collectProjectFoldersFromDirectory(folders, subdir, visited, nestedProjects, monitor);
  		}
  	}