Skip to content

Commit caa0451

Browse files
Googlercopybara-github
authored andcommitted
Automatic code cleanup.
PiperOrigin-RevId: 433061506
1 parent 3073f1b commit caa0451

File tree

3 files changed

+63
-62
lines changed

3 files changed

+63
-62
lines changed

src/main/java/com/google/devtools/common/options/Converters.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Integer convert(String input) throws OptionsParsingException {
8888
try {
8989
return Integer.decode(input);
9090
} catch (NumberFormatException e) {
91-
throw new OptionsParsingException("'" + input + "' is not an int");
91+
throw new OptionsParsingException("'" + input + "' is not an int", e);
9292
}
9393
}
9494

@@ -105,7 +105,7 @@ public Long convert(String input) throws OptionsParsingException {
105105
try {
106106
return Long.decode(input);
107107
} catch (NumberFormatException e) {
108-
throw new OptionsParsingException("'" + input + "' is not a long");
108+
throw new OptionsParsingException("'" + input + "' is not a long", e);
109109
}
110110
}
111111

@@ -122,7 +122,7 @@ public Double convert(String input) throws OptionsParsingException {
122122
try {
123123
return Double.parseDouble(input);
124124
} catch (NumberFormatException e) {
125-
throw new OptionsParsingException("'" + input + "' is not a double");
125+
throw new OptionsParsingException("'" + input + "' is not a double", e);
126126
}
127127
}
128128

@@ -323,7 +323,7 @@ public Level convert(String input) throws OptionsParsingException {
323323
int level = Integer.parseInt(input);
324324
return LEVELS.get(level);
325325
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
326-
throw new OptionsParsingException("Not a log level: " + input);
326+
throw new OptionsParsingException("Not a log level: " + input, e);
327327
}
328328
}
329329

@@ -420,7 +420,7 @@ public Integer convert(String input) throws OptionsParsingException {
420420
}
421421
return value;
422422
} catch (NumberFormatException e) {
423-
throw new OptionsParsingException("'" + input + "' is not an int");
423+
throw new OptionsParsingException("'" + input + "' is not an int", e);
424424
}
425425
}
426426

@@ -625,15 +625,15 @@ public Map.Entry<String, Integer> convert(String input) throws OptionsParsingExc
625625
try {
626626
return Maps.immutableEntry("", Integer.parseInt(input));
627627
} catch (NumberFormatException e) {
628-
throw new OptionsParsingException("'" + input + "' is not an int");
628+
throw new OptionsParsingException("'" + input + "' is not an int", e);
629629
}
630630
}
631631
String name = input.substring(0, pos);
632632
String value = input.substring(pos + 1);
633633
try {
634634
return Maps.immutableEntry(name, Integer.parseInt(value));
635635
} catch (NumberFormatException e) {
636-
throw new OptionsParsingException("'" + value + "' is not an int");
636+
throw new OptionsParsingException("'" + value + "' is not an int", e);
637637
}
638638
}
639639

src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ static IsolatedOptionsData from(Collection<Class<? extends OptionsBase>> classes
247247
Constructor<? extends OptionsBase> constructor = parsedOptionsClass.getConstructor();
248248
constructorBuilder.put(parsedOptionsClass, constructor);
249249
} catch (NoSuchMethodException e) {
250-
throw new IllegalArgumentException(parsedOptionsClass
251-
+ " lacks an accessible default constructor");
250+
throw new IllegalArgumentException(
251+
parsedOptionsClass + " lacks an accessible default constructor", e);
252252
}
253253
ImmutableList<OptionDefinition> optionDefinitions =
254254
getAllOptionDefinitionsForClass(parsedOptionsClass);

src/main/java/com/google/devtools/common/options/OptionsUsage.java

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,59 +51,6 @@ static void getUsage(Class<? extends OptionsBase> optionsClass, StringBuilder us
5151
}
5252
}
5353

54-
/**
55-
* Paragraph-fill the specified input text, indenting lines to 'indent' and
56-
* wrapping lines at 'width'. Returns the formatted result.
57-
*/
58-
static String paragraphFill(String in, int indent, int width) {
59-
String indentString = " ".repeat(indent);
60-
StringBuilder out = new StringBuilder();
61-
String sep = "";
62-
for (String paragraph : NEWLINE_SPLITTER.split(in)) {
63-
// TODO(ccalvarin) break iterators expect hyphenated words to be line-breakable, which looks
64-
// funny for --flag
65-
BreakIterator boundary = BreakIterator.getLineInstance(); // (factory)
66-
boundary.setText(paragraph);
67-
out.append(sep).append(indentString);
68-
int cursor = indent;
69-
for (int start = boundary.first(), end = boundary.next();
70-
end != BreakIterator.DONE;
71-
start = end, end = boundary.next()) {
72-
String word =
73-
paragraph.substring(start, end); // (may include trailing space)
74-
if (word.length() + cursor > width) {
75-
out.append('\n').append(indentString);
76-
cursor = indent;
77-
}
78-
out.append(word);
79-
cursor += word.length();
80-
}
81-
sep = "\n";
82-
}
83-
return out.toString();
84-
}
85-
86-
/**
87-
* Returns the expansion for an option, if any, regardless of if the expansion is from a function
88-
* or is statically declared in the annotation.
89-
*/
90-
private static @Nullable ImmutableList<String> getExpansionIfKnown(
91-
OptionDefinition optionDefinition, OptionsData optionsData) {
92-
Preconditions.checkNotNull(optionDefinition);
93-
return optionsData.getEvaluatedExpansion(optionDefinition);
94-
}
95-
96-
// Placeholder tag "UNKNOWN" is ignored.
97-
private static boolean shouldEffectTagBeListed(OptionEffectTag effectTag) {
98-
return !effectTag.equals(OptionEffectTag.UNKNOWN);
99-
}
100-
101-
// Tags that only apply to undocumented options are excluded.
102-
private static boolean shouldMetadataTagBeListed(OptionMetadataTag metadataTag) {
103-
return !metadataTag.equals(OptionMetadataTag.HIDDEN)
104-
&& !metadataTag.equals(OptionMetadataTag.INTERNAL);
105-
}
106-
10754
/** Appends the usage message for a single option-field message to 'usage'. */
10855
static void getUsage(
10956
OptionDefinition optionDefinition,
@@ -190,6 +137,60 @@ static void getUsage(
190137
}
191138
}
192139

140+
/**
141+
* Paragraph-fill the specified input text, indenting lines to 'indent' and
142+
* wrapping lines at 'width'. Returns the formatted result.
143+
*/
144+
static String paragraphFill(String in, int indent, int width) {
145+
String indentString = " ".repeat(indent);
146+
StringBuilder out = new StringBuilder();
147+
String sep = "";
148+
for (String paragraph : NEWLINE_SPLITTER.split(in)) {
149+
// TODO(ccalvarin) break iterators expect hyphenated words to be line-breakable, which looks
150+
// funny for --flag
151+
BreakIterator boundary = BreakIterator.getLineInstance(); // (factory)
152+
boundary.setText(paragraph);
153+
out.append(sep).append(indentString);
154+
int cursor = indent;
155+
for (int start = boundary.first(), end = boundary.next();
156+
end != BreakIterator.DONE;
157+
start = end, end = boundary.next()) {
158+
String word =
159+
paragraph.substring(start, end); // (may include trailing space)
160+
if (word.length() + cursor > width) {
161+
out.append('\n').append(indentString);
162+
cursor = indent;
163+
}
164+
out.append(word);
165+
cursor += word.length();
166+
}
167+
sep = "\n";
168+
}
169+
return out.toString();
170+
}
171+
172+
/**
173+
* Returns the expansion for an option, if any, regardless of if the expansion is from a function
174+
* or is statically declared in the annotation.
175+
*/
176+
@Nullable
177+
private static ImmutableList<String> getExpansionIfKnown(
178+
OptionDefinition optionDefinition, OptionsData optionsData) {
179+
Preconditions.checkNotNull(optionDefinition);
180+
return optionsData.getEvaluatedExpansion(optionDefinition);
181+
}
182+
183+
// Placeholder tag "UNKNOWN" is ignored.
184+
private static boolean shouldEffectTagBeListed(OptionEffectTag effectTag) {
185+
return !effectTag.equals(OptionEffectTag.UNKNOWN);
186+
}
187+
188+
// Tags that only apply to undocumented options are excluded.
189+
private static boolean shouldMetadataTagBeListed(OptionMetadataTag metadataTag) {
190+
return !metadataTag.equals(OptionMetadataTag.HIDDEN)
191+
&& !metadataTag.equals(OptionMetadataTag.INTERNAL);
192+
}
193+
193194
/** Append the usage message for a single option-field message to 'usage'. */
194195
static void getUsageHtml(
195196
OptionDefinition optionDefinition,

0 commit comments

Comments
 (0)