Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 433061506
  • Loading branch information
Googler authored and copybara-github committed Mar 7, 2022
1 parent 3073f1b commit caa0451
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/google/devtools/common/options/Converters.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Integer convert(String input) throws OptionsParsingException {
try {
return Integer.decode(input);
} catch (NumberFormatException e) {
throw new OptionsParsingException("'" + input + "' is not an int");
throw new OptionsParsingException("'" + input + "' is not an int", e);
}
}

Expand All @@ -105,7 +105,7 @@ public Long convert(String input) throws OptionsParsingException {
try {
return Long.decode(input);
} catch (NumberFormatException e) {
throw new OptionsParsingException("'" + input + "' is not a long");
throw new OptionsParsingException("'" + input + "' is not a long", e);
}
}

Expand All @@ -122,7 +122,7 @@ public Double convert(String input) throws OptionsParsingException {
try {
return Double.parseDouble(input);
} catch (NumberFormatException e) {
throw new OptionsParsingException("'" + input + "' is not a double");
throw new OptionsParsingException("'" + input + "' is not a double", e);
}
}

Expand Down Expand Up @@ -323,7 +323,7 @@ public Level convert(String input) throws OptionsParsingException {
int level = Integer.parseInt(input);
return LEVELS.get(level);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
throw new OptionsParsingException("Not a log level: " + input);
throw new OptionsParsingException("Not a log level: " + input, e);
}
}

Expand Down Expand Up @@ -420,7 +420,7 @@ public Integer convert(String input) throws OptionsParsingException {
}
return value;
} catch (NumberFormatException e) {
throw new OptionsParsingException("'" + input + "' is not an int");
throw new OptionsParsingException("'" + input + "' is not an int", e);
}
}

Expand Down Expand Up @@ -625,15 +625,15 @@ public Map.Entry<String, Integer> convert(String input) throws OptionsParsingExc
try {
return Maps.immutableEntry("", Integer.parseInt(input));
} catch (NumberFormatException e) {
throw new OptionsParsingException("'" + input + "' is not an int");
throw new OptionsParsingException("'" + input + "' is not an int", e);
}
}
String name = input.substring(0, pos);
String value = input.substring(pos + 1);
try {
return Maps.immutableEntry(name, Integer.parseInt(value));
} catch (NumberFormatException e) {
throw new OptionsParsingException("'" + value + "' is not an int");
throw new OptionsParsingException("'" + value + "' is not an int", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ static IsolatedOptionsData from(Collection<Class<? extends OptionsBase>> classes
Constructor<? extends OptionsBase> constructor = parsedOptionsClass.getConstructor();
constructorBuilder.put(parsedOptionsClass, constructor);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(parsedOptionsClass
+ " lacks an accessible default constructor");
throw new IllegalArgumentException(
parsedOptionsClass + " lacks an accessible default constructor", e);
}
ImmutableList<OptionDefinition> optionDefinitions =
getAllOptionDefinitionsForClass(parsedOptionsClass);
Expand Down
107 changes: 54 additions & 53 deletions src/main/java/com/google/devtools/common/options/OptionsUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,6 @@ static void getUsage(Class<? extends OptionsBase> optionsClass, StringBuilder us
}
}

/**
* Paragraph-fill the specified input text, indenting lines to 'indent' and
* wrapping lines at 'width'. Returns the formatted result.
*/
static String paragraphFill(String in, int indent, int width) {
String indentString = " ".repeat(indent);
StringBuilder out = new StringBuilder();
String sep = "";
for (String paragraph : NEWLINE_SPLITTER.split(in)) {
// TODO(ccalvarin) break iterators expect hyphenated words to be line-breakable, which looks
// funny for --flag
BreakIterator boundary = BreakIterator.getLineInstance(); // (factory)
boundary.setText(paragraph);
out.append(sep).append(indentString);
int cursor = indent;
for (int start = boundary.first(), end = boundary.next();
end != BreakIterator.DONE;
start = end, end = boundary.next()) {
String word =
paragraph.substring(start, end); // (may include trailing space)
if (word.length() + cursor > width) {
out.append('\n').append(indentString);
cursor = indent;
}
out.append(word);
cursor += word.length();
}
sep = "\n";
}
return out.toString();
}

/**
* Returns the expansion for an option, if any, regardless of if the expansion is from a function
* or is statically declared in the annotation.
*/
private static @Nullable ImmutableList<String> getExpansionIfKnown(
OptionDefinition optionDefinition, OptionsData optionsData) {
Preconditions.checkNotNull(optionDefinition);
return optionsData.getEvaluatedExpansion(optionDefinition);
}

// Placeholder tag "UNKNOWN" is ignored.
private static boolean shouldEffectTagBeListed(OptionEffectTag effectTag) {
return !effectTag.equals(OptionEffectTag.UNKNOWN);
}

// Tags that only apply to undocumented options are excluded.
private static boolean shouldMetadataTagBeListed(OptionMetadataTag metadataTag) {
return !metadataTag.equals(OptionMetadataTag.HIDDEN)
&& !metadataTag.equals(OptionMetadataTag.INTERNAL);
}

/** Appends the usage message for a single option-field message to 'usage'. */
static void getUsage(
OptionDefinition optionDefinition,
Expand Down Expand Up @@ -190,6 +137,60 @@ static void getUsage(
}
}

/**
* Paragraph-fill the specified input text, indenting lines to 'indent' and
* wrapping lines at 'width'. Returns the formatted result.
*/
static String paragraphFill(String in, int indent, int width) {
String indentString = " ".repeat(indent);
StringBuilder out = new StringBuilder();
String sep = "";
for (String paragraph : NEWLINE_SPLITTER.split(in)) {
// TODO(ccalvarin) break iterators expect hyphenated words to be line-breakable, which looks
// funny for --flag
BreakIterator boundary = BreakIterator.getLineInstance(); // (factory)
boundary.setText(paragraph);
out.append(sep).append(indentString);
int cursor = indent;
for (int start = boundary.first(), end = boundary.next();
end != BreakIterator.DONE;
start = end, end = boundary.next()) {
String word =
paragraph.substring(start, end); // (may include trailing space)
if (word.length() + cursor > width) {
out.append('\n').append(indentString);
cursor = indent;
}
out.append(word);
cursor += word.length();
}
sep = "\n";
}
return out.toString();
}

/**
* Returns the expansion for an option, if any, regardless of if the expansion is from a function
* or is statically declared in the annotation.
*/
@Nullable
private static ImmutableList<String> getExpansionIfKnown(
OptionDefinition optionDefinition, OptionsData optionsData) {
Preconditions.checkNotNull(optionDefinition);
return optionsData.getEvaluatedExpansion(optionDefinition);
}

// Placeholder tag "UNKNOWN" is ignored.
private static boolean shouldEffectTagBeListed(OptionEffectTag effectTag) {
return !effectTag.equals(OptionEffectTag.UNKNOWN);
}

// Tags that only apply to undocumented options are excluded.
private static boolean shouldMetadataTagBeListed(OptionMetadataTag metadataTag) {
return !metadataTag.equals(OptionMetadataTag.HIDDEN)
&& !metadataTag.equals(OptionMetadataTag.INTERNAL);
}

/** Append the usage message for a single option-field message to 'usage'. */
static void getUsageHtml(
OptionDefinition optionDefinition,
Expand Down

0 comments on commit caa0451

Please sign in to comment.