Skip to content

Commit

Permalink
Re-format comments in TargetSuggester.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 644353610
Change-Id: I8afb2286f2a781bbadbb7dc7d7ffaf934f7596e6
  • Loading branch information
MarkDacek authored and Copybara-Service committed Jun 18, 2024
1 parent c94c1c3 commit 9368c60
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,24 @@ private TargetSuggester() {}
* Given a nonexistent target and the targets in its package, suggest what the user may have
* intended based on lexicographic closeness to the possibilities.
*
* <p>This will be pretty printed in the following form No suggested targets -> "". Suggested
* target "a" -> "a". Suggested targets "a", "b", "c" -> "a, b, or c".
* <p>This will be pretty printed in the following forms:
*
* <p>No suggested targets -> "".
*
* <p>Suggested target "a" -> "a".
*
* <p>Suggested targets "a", "b" -> "a, or b"
*
* <p>Suggested targets "a", "b", "c" -> "a, b, or c".
*/
static String suggestTargets(String input, Set<String> words) {
ImmutableList<String> suggestedTargets = suggestedTargets(input, words);
return prettyPrintTargets(suggestedTargets);
}

/**
* Given a requested target and a Set of targets in the same package, return a list of strings
* closest based on edit distance.
* Given a requested target and a Set of targets in the same package, return a list of the targets
* closest to the requested target based on edit distance.
*
* <p>If any strings are identical minus capitalization changes, they will be returned. If any
* other strings are exactly 1 character off, they will be returned. Otherwise, the 10 nearest
Expand Down Expand Up @@ -115,7 +122,7 @@ private static ImmutableList<String> getSuggestedTargets(

/**
* Create a pretty-printable String for a list. Joiner doesn't currently support multiple
* separators so this is a custom roll for now. Returns a comma-delimited list with " or " before
* separators so this is a custom roll for now. Returns a comma-delimited list with ", or " before
* the last element.
*/
@VisibleForTesting
Expand All @@ -126,9 +133,7 @@ public static String prettyPrintTargets(ImmutableList<String> targets) {
} else if (targets.size() == 1) {
targetString = targets.get(0);
} else {

String firstPart = Joiner.on(", ").join(targets.subList(0, targets.size() - 1));

targetString = Joiner.on(", or ").join(firstPart, Iterables.getLast(targets));
}
return " (did you mean " + targetString + "?)";
Expand Down

0 comments on commit 9368c60

Please sign in to comment.