docs: @SuppressWarnings({"unchecked", "checkstyle:cyclomaticcomplexity", "checkstyle:nestedifdepth"})
  	private List<ElementDescription> findElements(Object[] selection, IProgressService progress)
  			throws InvocationTargetException, InterruptedException {
  		final List<ElementDescription> descs = new ArrayList<>();
  		progress.busyCursorWhile(monitor -> {
  			try {
  				monitor.beginTask(
  						MessageFormat.format(Messages.AbstractSarlScriptInteractiveSelector_0, getElementsLabel()),
  						selection.length);
  				for (final Object element : selection) {
  					final URI fileURI = getResourceURIForValidEObject(element);
  					if (fileURI != null) {
  						for (final Pair<IStorage, IProject> storage: this.storage2UriMapper.getStorages(fileURI)) {
  							descs.add(new ElementDescription(
  									storage.getSecond().getName(),
  									getQualifiedNameFor((ET) element),
  									element));
  							break;
  						}
  					} else {
  						final LinkedList<Object> stack = new LinkedList<>();
  						stack.add(element);
  						final Class<ET> validElementType = getValidEObjectType();
  						while (!stack.isEmpty()) {
  							final Object current = stack.removeFirst();
  							if (current instanceof IFile) {
  								final IFile file = (IFile) current;
  								if (isValidResource(file)) {
  									final ResourceSet resourceSet = this.resourceSetProvider.get(file.getProject());
  									final URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
  									if (resourceURI != null) {
  										try {
  											final Resource resource = resourceSet.getResource(resourceURI, true);
  											if (resource != null) {
  												final String projectName = file.getProject().getName();
  												for (final EObject content : resource.getContents()) {
  													if (content instanceof SarlScript) {
  														final List<ET> types = EcoreUtil2.getAllContentsOfType(content, validElementType);
  														for (final ET elt : types) {
  															if (isSelectableElement(elt)) {
  																descs.add(new ElementDescription(
  																		projectName,
  																		getQualifiedNameFor(elt),
  																		elt));
  															}
  														}
  													}
  												}
  											}
  										} catch (Throwable exception) {
  											// The exception is ignore because it is assumed it is caused by a
  											// file from which a Xtext resource cannot be extracted.
  										}
  									}
  								}
  							} else if (current instanceof IFolder) {
  								final IFolder folder = (IFolder) current;
  								if (isValidResource(folder)) {
  									try {
  										stack.addAll(Arrays.asList(folder.members(0)));
  									} catch (CoreException exception) {
  										// Ignore the failing resources
  									}
  								}
  							} else if (current instanceof IType) {
  								final IType type = (IType) current;
  								final String qn = type.getFullyQualifiedName();
  								final IJavaProject project = type.getJavaProject();
  								if (this.jdt.isSubClassOf(this.jdt.toTypeFinder(project), qn, Agent.class.getName())) {
  									descs.add(new ElementDescription(project.getElementName(), qn, type));
  								}
  							} else if (current instanceof IPackageFragment) {
  								final IPackageFragment fragment = (IPackageFragment) current;
  								stack.addAll(Arrays.asList(fragment.getNonJavaResources()));
  								for (final Object child : fragment.getChildren()) {
  									stack.add(child);
  								}
  							} else if (current instanceof IPackageFragmentRoot) {
  								final IPackageFragmentRoot fragment = (IPackageFragmentRoot) current;
  								stack.addAll(Arrays.asList(fragment.getNonJavaResources()));
  								for (final Object child : fragment.getChildren()) {
  									stack.add(child);
  								}
  							} else if (current instanceof IJavaProject) {
  								stack.addAll(Arrays.asList(((IJavaProject) current).getNonJavaResources()));
  							}
  						}
  					}
  					monitor.worked(1);
  				}
  			} catch (JavaModelException exception) {
  				throw new InvocationTargetException(exception);
  			}
  		});
  		return descs;
  	}