1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +02:00

Fixed ordering of includes - A.h should be shorted before A_a.h

This commit is contained in:
Sergey Prigogin 2013-07-26 20:21:17 -07:00
parent 82490d5bd6
commit 0fda1c9c85

View file

@ -10,9 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.includes;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import com.ibm.icu.text.Collator;
public class IncludeInfo implements Comparable<IncludeInfo> {
@ -94,18 +91,37 @@ public class IncludeInfo implements Comparable<IncludeInfo> {
@Override
public int compareTo(IncludeInfo other) {
if (isSystem != other.isSystem) {
if (isSystem != other.isSystem)
return isSystem ? -1 : 1;
}
IPath path1 = Path.fromOSString(name);
IPath path2 = Path.fromOSString(other.name);
int length1 = path1.segmentCount();
int length2 = path2.segmentCount();
int length1 = name.length();
int length2 = other.name.length();
for (int i = 0; i < length1 && i < length2; i++) {
int c = COLLATOR.compare(path1.segment(i), path2.segment(i));
if (c != 0)
return c;
char c1 = name.charAt(i);
char c2 = other.name.charAt(i);
int o1 = order(c1);
int o2 = order(c2);
if (o1 != o2)
return o1 - o2;
if (o1 == 0) {
int c = COLLATOR.compare(String.valueOf(c1), String.valueOf(c2));
if (c != 0)
return c;
}
}
return length1 - length2;
}
private int order(char c) {
switch (c) {
case '/':
return -3;
case '\\':
return -2;
case '.':
return -1;
default:
return 0;
}
}
}