COMPARATOR property

  1. @Deprecated('This kind of syntactic equality is rarely useful')
Comparator<ImportDirective> COMPARATOR
getter/setter pair

Implementation

@Deprecated('This kind of syntactic equality is rarely useful')
static Comparator<ImportDirective> COMPARATOR =
    (ImportDirective import1, ImportDirective import2) {
  //
  // uri
  //
  StringLiteral uri1 = import1.uri;
  StringLiteral uri2 = import2.uri;
  String? uriStr1 = uri1.stringValue;
  String? uriStr2 = uri2.stringValue;
  if (uriStr1 != null || uriStr2 != null) {
    if (uriStr1 == null) {
      return -1;
    } else if (uriStr2 == null) {
      return 1;
    } else {
      int compare = uriStr1.compareTo(uriStr2);
      if (compare != 0) {
        return compare;
      }
    }
  }
  //
  // as
  //
  SimpleIdentifier? prefix1 = import1.prefix;
  SimpleIdentifier? prefix2 = import2.prefix;
  String? prefixStr1 = prefix1?.name;
  String? prefixStr2 = prefix2?.name;
  if (prefixStr1 != null || prefixStr2 != null) {
    if (prefixStr1 == null) {
      return -1;
    } else if (prefixStr2 == null) {
      return 1;
    } else {
      int compare = prefixStr1.compareTo(prefixStr2);
      if (compare != 0) {
        return compare;
      }
    }
  }
  //
  // hides and shows
  //
  NodeList<Combinator> combinators1 = import1.combinators;
  List<String> allHides1 = <String>[];
  List<String> allShows1 = <String>[];
  int length1 = combinators1.length;
  for (int i = 0; i < length1; i++) {
    Combinator combinator = combinators1[i];
    if (combinator is HideCombinator) {
      NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
      int hideLength = hides.length;
      for (int j = 0; j < hideLength; j++) {
        SimpleIdentifier simpleIdentifier = hides[j];
        allHides1.add(simpleIdentifier.name);
      }
    } else {
      NodeList<SimpleIdentifier> shows =
          (combinator as ShowCombinator).shownNames;
      int showLength = shows.length;
      for (int j = 0; j < showLength; j++) {
        SimpleIdentifier simpleIdentifier = shows[j];
        allShows1.add(simpleIdentifier.name);
      }
    }
  }
  NodeList<Combinator> combinators2 = import2.combinators;
  List<String> allHides2 = <String>[];
  List<String> allShows2 = <String>[];
  int length2 = combinators2.length;
  for (int i = 0; i < length2; i++) {
    Combinator combinator = combinators2[i];
    if (combinator is HideCombinator) {
      NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
      int hideLength = hides.length;
      for (int j = 0; j < hideLength; j++) {
        SimpleIdentifier simpleIdentifier = hides[j];
        allHides2.add(simpleIdentifier.name);
      }
    } else {
      NodeList<SimpleIdentifier> shows =
          (combinator as ShowCombinator).shownNames;
      int showLength = shows.length;
      for (int j = 0; j < showLength; j++) {
        SimpleIdentifier simpleIdentifier = shows[j];
        allShows2.add(simpleIdentifier.name);
      }
    }
  }
  // test lengths of combinator lists first
  if (allHides1.length != allHides2.length) {
    return allHides1.length - allHides2.length;
  }
  if (allShows1.length != allShows2.length) {
    return allShows1.length - allShows2.length;
  }
  // next ensure that the lists are equivalent
  if (!allHides1.toSet().containsAll(allHides2)) {
    return -1;
  }
  if (!allShows1.toSet().containsAll(allShows2)) {
    return -1;
  }
  return 0;
};