/**
   * @param matchList a List of SearchMatch
   * @param status the status to report errors.
   * @return a SearchResultGroup[], grouped by SearchMatch#getResource()
   */
  public static SearchResultGroup[] groupByCu(
      List<SearchMatch> matchList, RefactoringStatus status) {
    Map<IResource, List<SearchMatch>> grouped = new HashMap<IResource, List<SearchMatch>>();
    boolean hasPotentialMatches = false;
    boolean hasNonCuMatches = false;

    for (SearchMatch searchMatch : matchList) {
      if (searchMatch.getAccuracy() == SearchMatch.A_INACCURATE) hasPotentialMatches = true;
      if (!grouped.containsKey(searchMatch.getResource()))
        grouped.put(searchMatch.getResource(), new ArrayList<SearchMatch>(1));
      grouped.get(searchMatch.getResource()).add(searchMatch);
    }

    for (Iterator<IResource> iter = grouped.keySet().iterator(); iter.hasNext(); ) {
      IResource resource = iter.next();
      IModelElement element = DLTKCore.create(resource);
      if (!(element instanceof ISourceModule)) {
        iter.remove();
        hasNonCuMatches = true;
      }
    }

    SearchResultGroup[] result = new SearchResultGroup[grouped.keySet().size()];
    int i = 0;
    for (IResource resource : grouped.keySet()) {
      List<SearchMatch> searchMatches = grouped.get(resource);
      SearchMatch[] matchArray = searchMatches.toArray(new SearchMatch[searchMatches.size()]);
      result[i] = new SearchResultGroup(resource, matchArray);
      i++;
    }
    addStatusErrors(status, hasPotentialMatches, hasNonCuMatches);
    return result;
  }
 public void acceptSearchMatch(SearchMatch match) {
   if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
     hasPotentialMatches = true;
   }
   if (fLastResource != match.getResource()) {
     fLastResource = match.getResource();
     resources.add(fLastResource);
   }
 }