mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Add ResourceLookup.sortFilesByRelevance(...), bug 251161.
This commit is contained in:
parent
868e29ac4f
commit
db8d239e76
1 changed files with 32 additions and 0 deletions
|
@ -11,6 +11,9 @@
|
||||||
package org.eclipse.cdt.internal.core.resources;
|
package org.eclipse.cdt.internal.core.resources;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -114,6 +117,35 @@ public class ResourceLookup {
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts files by relevance for CDT, by the criteria listed below. The most relevant files
|
||||||
|
* is listed first.
|
||||||
|
* <br> Accessible files
|
||||||
|
* <br> Files of preferred project
|
||||||
|
* <br> Files of CDT projects
|
||||||
|
* <br> Files on a source root of a CDT project
|
||||||
|
*/
|
||||||
|
public static void sortFilesByRelevance(IFile[] filesToSort, final IProject preferredProject) {
|
||||||
|
Collections.sort(Arrays.asList(filesToSort), new Comparator<IFile>() {
|
||||||
|
public int compare(IFile f1, IFile f2) {
|
||||||
|
boolean a1= f1.isAccessible();
|
||||||
|
boolean a2= f2.isAccessible();
|
||||||
|
if (a1 != a2)
|
||||||
|
return a1 ? -1 : 1;
|
||||||
|
|
||||||
|
int r1= FileRelevance.getRelevance(f1, preferredProject);
|
||||||
|
int r2= FileRelevance.getRelevance(f2, preferredProject);
|
||||||
|
|
||||||
|
if (r1 > r2)
|
||||||
|
return -1;
|
||||||
|
if (r1 < r2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return f1.getFullPath().toString().compareTo(f2.getFullPath().toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For testing, only.
|
* For testing, only.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue