Extend import grouping functionality to allow groups to be specified.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6676 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -327,12 +327,21 @@ public class ImportSet
|
|||||||
* ordering and spacing. Within each group, sorting is alphabetical.
|
* ordering and spacing. Within each group, sorting is alphabetical.
|
||||||
*/
|
*/
|
||||||
public List<List<String>> toGroups ()
|
public List<List<String>> toGroups ()
|
||||||
|
{
|
||||||
|
return toGroups(IMPORT_GROUPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the set of imports to groups of class names, according to the provided groups.
|
||||||
|
* Within each group, sorting is alphabetical.
|
||||||
|
*/
|
||||||
|
public List<List<String>> toGroups (final List<String> groups)
|
||||||
{
|
{
|
||||||
List<String> list = Lists.newArrayList(_imports);
|
List<String> list = Lists.newArrayList(_imports);
|
||||||
Collections.sort(list, new Comparator<String>() {
|
Collections.sort(list, new Comparator<String>() {
|
||||||
public int compare (String class1, String class2) {
|
public int compare (String class1, String class2) {
|
||||||
return ComparisonChain.start()
|
return ComparisonChain.start()
|
||||||
.compare(findImportGroup(class1), findImportGroup(class2))
|
.compare(findImportGroup(class1, groups), findImportGroup(class2, groups))
|
||||||
.compare(class1, class2)
|
.compare(class1, class2)
|
||||||
.result();
|
.result();
|
||||||
}
|
}
|
||||||
@@ -341,7 +350,7 @@ public class ImportSet
|
|||||||
List<String> current = null;
|
List<String> current = null;
|
||||||
int lastGroup = -1;
|
int lastGroup = -1;
|
||||||
for (String imp : list) {
|
for (String imp : list) {
|
||||||
int group = findImportGroup(imp);
|
int group = findImportGroup(imp, groups);
|
||||||
if (group != lastGroup) {
|
if (group != lastGroup) {
|
||||||
if (current == null || !current.isEmpty()) {
|
if (current == null || !current.isEmpty()) {
|
||||||
result.add(current = Lists.<String>newArrayList());
|
result.add(current = Lists.<String>newArrayList());
|
||||||
@@ -401,10 +410,10 @@ public class ImportSet
|
|||||||
return Pattern.compile(pattern.toString());
|
return Pattern.compile(pattern.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int findImportGroup (String imp)
|
protected static int findImportGroup (String imp, List<String> groups)
|
||||||
{
|
{
|
||||||
String longest = null;
|
String longest = null;
|
||||||
for (String prefix : IMPORT_GROUPS) {
|
for (String prefix : groups) {
|
||||||
if (!imp.startsWith(prefix)) {
|
if (!imp.startsWith(prefix)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -412,7 +421,7 @@ public class ImportSet
|
|||||||
longest = prefix;
|
longest = prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return IMPORT_GROUPS.indexOf(longest);
|
return groups.indexOf(longest);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HashSet<String> _imports = Sets.newHashSet();
|
protected HashSet<String> _imports = Sets.newHashSet();
|
||||||
|
|||||||
Reference in New Issue
Block a user