private static <T extends PsiElement> Map<T, FileStatus> calculateStatuses(List<? extends T> elements,
                                                                             List<? extends T> oldElements,
                                                                             Map<T, FileStatus> result, PsiFilter<? super T> filter) {
    for (T element : elements) {
      T e = null;
      for (T oldElement : oldElements) {
        if (filter.areEquivalent(element, oldElement)) {
          e = oldElement;
          break;
        }
      }
      if (e != null) {
        oldElements.remove(e);
        if (!element.getText().equals(e.getText())) {
          result.put(element, FileStatus.MODIFIED);
        }
      }
      else {
        result.put(element, FileStatus.ADDED);
      }
    }

    for (T oldElement : oldElements) {
      result.put(oldElement, FileStatus.DELETED);
    }

    return result;
  }
private static <T extends PsiElement> Map<T, FileStatus> calculateStatuses(List<? extends T> elements,
                                                                             List<? extends T> oldElements,
                                                                             Map<T, FileStatus> result, PsiFilter<? super T> filter)