prefer shorter names when sorting import candidate list

This commit is contained in:
Dmitry Jemerov
2011-03-23 20:34:01 +01:00
parent 559db4c388
commit 630ae204da
@@ -138,7 +138,18 @@ class ImportCandidateHolder implements Comparable {
public int compareTo(Object o) {
ImportCandidateHolder rhs = (ImportCandidateHolder) o;
return rhs.getRelevance() - getRelevance();
int lRelevance = getRelevance();
int rRelevance = rhs.getRelevance();
if (rRelevance != lRelevance) {
return rRelevance - lRelevance;
}
// prefer shorter paths
if (myPath != null && rhs.myPath != null) {
int lDots = StringUtil.isEmpty(myPath) ? -1 : StringUtil.countChars(myPath, '.');
int rDots = StringUtil.isEmpty(rhs.myPath) ? -1 : StringUtil.countChars(rhs.myPath, '.');
return lDots - rDots;
}
return 0;
}
int getRelevance() {