int (@NotNull ImportCandidateHolder other) { if (myImportElement != null && other.myImportElement == null) return -1; if (myImportElement == null && other.myImportElement != null) return 1; if (myAsName != null && other.myAsName == null) return -1; if (myAsName == null && other.myAsName != null) return 1; int comparedRelevance = Comparator .comparing(ImportCandidateHolder::getRelevance).reversed() .compare(this, other); if (comparedRelevance != 0) return comparedRelevance; QualifiedName myLocalPath = getPath(); QualifiedName otherPath = other.getPath(); if (myImportElement != null) { // both are not null here PyImportElement myElement = myImportElement.getElement(); PyImportElement otherElement = other.myImportElement.getElement(); if (myElement != null && otherElement != null) { myLocalPath = myElement.getImportedQName(); otherPath = otherElement.getImportedQName(); } } return Comparing.compare(myLocalPath, otherPath); }