diff options
author | Luis Fernando Pino Duque <lpino@google.com> | 2016-02-24 13:43:37 +0000 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-02-16 22:16:06 -0800 |
commit | 54ef45a56a126b7493d3e0c272b0b6217b35ac98 (patch) | |
tree | bdf03046e2a72ad7c031c68f26d61591c6c0f7d0 | |
parent | c3f28aa9079eacd2b91ad1475e41f68b69e23c67 (diff) | |
download | desugar-54ef45a56a126b7493d3e0c272b0b6217b35ac98.tar.gz |
Refactoring of the OptionsParser implementation to allow overriding the value of an option with null.
Currently it returns the original default value if the new value is null.
--
MOS_MIGRATED_REVID=115442253
GitOrigin-RevId: dafdc2854bc74bb8bf09abe9932160dd4a5bb1fb
Change-Id: I152c25605889e0b5862231324f466991708580d1
-rw-r--r-- | java/com/google/devtools/common/options/OptionsParserImpl.java | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/java/com/google/devtools/common/options/OptionsParserImpl.java b/java/com/google/devtools/common/options/OptionsParserImpl.java index 48dac23..96fb496 100644 --- a/java/com/google/devtools/common/options/OptionsParserImpl.java +++ b/java/com/google/devtools/common/options/OptionsParserImpl.java @@ -244,7 +244,7 @@ class OptionsParserImpl { = LinkedHashMultimap.create(); private final List<String> warnings = Lists.newArrayList(); - + private boolean allowSingleDashLongOptions = false; /** @@ -261,7 +261,7 @@ class OptionsParserImpl { void setAllowSingleDashLongOptions(boolean allowSingleDashLongOptions) { this.allowSingleDashLongOptions = allowSingleDashLongOptions; } - + /** * The implementation of {@link OptionsBase#asMap}. */ @@ -468,11 +468,6 @@ class OptionsParserImpl { } } - private Object getValue(Field field) { - ParsedOptionEntry entry = parsedValues.get(field); - return entry == null ? null : entry.getValue(); - } - OptionValueDescription getOptionValueDescription(String name) { Field field = optionsData.getFieldFromName(name); if (field == null) { @@ -659,7 +654,7 @@ class OptionsParserImpl { sourceFunction.apply(originalName), expandedFrom == null); unparsedValues.add(unparsedOptionValueDescription); - if (option.allowMultiple()) { + if (option.allowMultiple()) { canonicalizeValues.put(field, unparsedOptionValueDescription); } else { canonicalizeValues.replaceValues(field, ImmutableList.of(unparsedOptionValueDescription)); @@ -754,9 +749,12 @@ class OptionsParserImpl { // Set the fields for (Field field : optionsData.getFieldsForClass(optionsClass)) { - Object value = getValue(field); - if (value == null) { + Object value; + ParsedOptionEntry entry = parsedValues.get(field); + if (entry == null) { value = optionsData.getDefaultValue(field); + } else { + value = entry.getValue(); } try { field.set(optionsInstance, value); @@ -814,4 +812,4 @@ class OptionsParserImpl { throw new AssertionError(e); } } -} +}
\ No newline at end of file |