Skip to content

Commit dcef053

Browse files
Imports sort: amended (forgot to add type comparison if packages fully match)
1 parent ca76cee commit dcef053

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ public static int InsertImport(MemberModel member, bool fixScrolling)
43264326
// insert in alphabetical order
43274327
mImport = ASFileParserRegexes.Import.Match(txt);
43284328
if (mImport.Success &&
4329-
ComparePackages(mImport.Groups["package"].Value, fullPath) > 0)
4329+
CompareImports(mImport.Groups["package"].Value, fullPath) > 0)
43304330
{
43314331
line--;
43324332
break;
@@ -4428,21 +4428,22 @@ private static void AddLookupPosition()
44284428
}
44294429
}
44304430

4431-
private static Int32 ComparePackages(String package1, String package2)
4431+
private static Int32 CompareImports(String import1, String import2)
44324432
{
44334433
IComparer cmp = new CaseInsensitiveComparer();
4434-
String[] parts1 = package1.Split('.');
4435-
String[] parts2 = package2.Split('.');
4436-
int pkgLen1 = parts1.Length - 1;
4437-
int pkgLen2 = parts2.Length - 1;
4438-
int commonLen = (pkgLen1 <= pkgLen2) ? pkgLen1 : pkgLen2;
4439-
for (int i = 0; i < commonLen; ++i)
4434+
String[] parts1 = import1.Split('.');
4435+
String[] parts2 = import2.Split('.');
4436+
int len1 = parts1.Length;
4437+
int len2 = parts2.Length;
4438+
int minPackageLen = ((len1 <= len2) ? len1 : len2) - 1;
4439+
int i;
4440+
for (i = 0; i < minPackageLen; ++i)
44404441
{
44414442
int cmpResult = cmp.Compare(parts1[i], parts2[i]);
44424443
if (cmpResult != 0)
44434444
return cmpResult;
44444445
}
4445-
return pkgLen1 - pkgLen2;
4446+
return (len1 == len2) ? cmp.Compare(parts1[i], parts2[i]) : (len1 - len2);
44464447
}
44474448
#endregion
44484449
}

External/Plugins/CodeRefactor/Commands/OrganizeImports.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,17 @@ public Int32 Compare(MemberModel item1, MemberModel item2)
228228
IComparer cmp = new CaseInsensitiveComparer();
229229
String[] parts1 = item1.Type.Split('.');
230230
String[] parts2 = item2.Type.Split('.');
231-
int pkgLen1 = parts1.Length - 1;
232-
int pkgLen2 = parts2.Length - 1;
233-
int commonLen = (pkgLen1 <= pkgLen2) ? pkgLen1 : pkgLen2;
234-
for (int i = 0; i < commonLen; ++i)
231+
int len1 = parts1.Length;
232+
int len2 = parts2.Length;
233+
int minPackageLen = ((len1 <= len2) ? len1 : len2) - 1;
234+
int i;
235+
for (i = 0; i < minPackageLen; ++i)
235236
{
236237
int cmpResult = cmp.Compare(parts1[i], parts2[i]);
237238
if (cmpResult != 0)
238239
return cmpResult;
239240
}
240-
return pkgLen1 - pkgLen2;
241+
return (len1 == len2) ? cmp.Compare(parts1[i], parts2[i]) : (len1 - len2);
241242
}
242243
}
243244

0 commit comments

Comments
 (0)