From caa045165ef9450969d4f3d986009a2f04f121b7 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 7 Mar 2022 15:55:06 -0800 Subject: [PATCH] Automatic code cleanup. PiperOrigin-RevId: 433061506 --- .../devtools/common/options/Converters.java | 14 +-- .../common/options/IsolatedOptionsData.java | 4 +- .../devtools/common/options/OptionsUsage.java | 107 +++++++++--------- 3 files changed, 63 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/google/devtools/common/options/Converters.java b/src/main/java/com/google/devtools/common/options/Converters.java index 8563e9cff816a6..56bc63c2a4b272 100644 --- a/src/main/java/com/google/devtools/common/options/Converters.java +++ b/src/main/java/com/google/devtools/common/options/Converters.java @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } @@ -625,7 +625,7 @@ public Map.Entry 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); @@ -633,7 +633,7 @@ public Map.Entry convert(String input) throws OptionsParsingExc 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); } } diff --git a/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java b/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java index 925409dc86f261..1c7c8ecd172e8a 100644 --- a/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java +++ b/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java @@ -247,8 +247,8 @@ static IsolatedOptionsData from(Collection> classes Constructor 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 optionDefinitions = getAllOptionDefinitionsForClass(parsedOptionsClass); diff --git a/src/main/java/com/google/devtools/common/options/OptionsUsage.java b/src/main/java/com/google/devtools/common/options/OptionsUsage.java index d036db4d6495dd..14ddc92e884c96 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsUsage.java +++ b/src/main/java/com/google/devtools/common/options/OptionsUsage.java @@ -51,59 +51,6 @@ static void getUsage(Class 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 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, @@ -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 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,