Skip to content

Commit

Permalink
De-static some bits on ImportSet.
Browse files Browse the repository at this point in the history
Statics can't be overridden. This class shouldn't have to know
about all threerings projects everywhere.
  • Loading branch information
Ray J. Greenwell committed Oct 29, 2014
1 parent c00610a commit 8c72823
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions tools/src/main/java/com/threerings/presents/tools/ImportSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,35 @@ public String toString ()
return StringUtil.toString(_imports);
}

/**
* Find the index of the best import group to use for the specified import.
*/
protected int findImportGroup (String imp)
{
int bestGroup = -1;
int bestPrefixLength = -1;
int ii = -1;
for (String prefix : getImportGroups()) {
ii++;
if (!imp.startsWith(prefix)) {
continue;
}
if (prefix.length() > bestPrefixLength) {
bestPrefixLength = prefix.length();
bestGroup = ii;
}
}
return bestGroup;
}

/**
* Return an iterable over the import prefixes that should be grouped together.
*/
protected Iterable<String> getImportGroups ()
{
return IMPORT_GROUPS;
}

/**
* Create a real regular expression from the dumbed down input.
* @param input the dumbed down wildcard expression
Expand Down Expand Up @@ -405,20 +434,6 @@ protected static Pattern makePattern (String input)
return Pattern.compile(pattern.toString());
}

protected static int findImportGroup (String imp)
{
String longest = null;
for (String prefix : IMPORT_GROUPS) {
if (!imp.startsWith(prefix)) {
continue;
}
if (longest == null || prefix.length() > longest.length()) {
longest = prefix;
}
}
return IMPORT_GROUPS.indexOf(longest);
}

protected HashSet<String> _imports = Sets.newHashSet();
protected List<String> _pushed = Lists.newArrayList();

Expand Down

0 comments on commit 8c72823

Please sign in to comment.