diff options
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java | 25 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java | 21 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/common/options/OptionsParser.java | 14 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/common/options/OptionsParserImpl.java | 190 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/common/options/OptionsProvider.java | 24 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/common/options/ParsedOptionDescription.java (renamed from src/main/java/com/google/devtools/common/options/UnparsedOptionValueDescription.java) | 4 |
6 files changed, 137 insertions, 141 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java b/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java index 56f4d961be..bae41d869f 100644 --- a/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java +++ b/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java @@ -20,7 +20,7 @@ import com.google.devtools.common.options.Converter; import com.google.devtools.common.options.Converters; import com.google.devtools.common.options.OptionsParsingException; import com.google.devtools.common.options.OptionsProvider; -import com.google.devtools.common.options.UnparsedOptionValueDescription; +import com.google.devtools.common.options.ParsedOptionDescription; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -34,9 +34,9 @@ public final class OptionsUtils { * Returns a string representation of the non-hidden specified options; option values are * shell-escaped. */ - public static String asShellEscapedString(Iterable<UnparsedOptionValueDescription> optionsList) { + public static String asShellEscapedString(Iterable<ParsedOptionDescription> optionsList) { StringBuilder result = new StringBuilder(); - for (UnparsedOptionValueDescription option : optionsList) { + for (ParsedOptionDescription option : optionsList) { if (option.isHidden()) { continue; } @@ -69,16 +69,16 @@ public final class OptionsUtils { * specified options; option values are shell-escaped. */ public static String asShellEscapedString(OptionsProvider options) { - return asShellEscapedString(options.asListOfUnparsedOptions()); + return asShellEscapedString(options.asCompleteListOfParsedOptions()); } /** * Return a representation of the non-hidden specified options, as a list of string. No escaping * is done. */ - public static List<String> asArgumentList(Iterable<UnparsedOptionValueDescription> optionsList) { + public static List<String> asArgumentList(Iterable<ParsedOptionDescription> optionsList) { ImmutableList.Builder<String> builder = ImmutableList.builder(); - for (UnparsedOptionValueDescription option : optionsList) { + for (ParsedOptionDescription option : optionsList) { if (option.isHidden()) { continue; } @@ -107,16 +107,15 @@ public final class OptionsUtils { * is done. */ public static List<String> asArgumentList(OptionsProvider options) { - return asArgumentList(options.asListOfUnparsedOptions()); + return asArgumentList(options.asCompleteListOfParsedOptions()); } /** - * Returns a string representation of the non-hidden explicitly or implicitly - * specified options, filtering out any sensitive options; option values are - * shell-escaped. + * Returns a string representation of the non-hidden explicitly or implicitly specified options, + * filtering out any sensitive options; option values are shell-escaped. */ - public static String asFilteredShellEscapedString(OptionsProvider options, - Iterable<UnparsedOptionValueDescription> optionsList) { + public static String asFilteredShellEscapedString( + OptionsProvider options, Iterable<ParsedOptionDescription> optionsList) { return asShellEscapedString(optionsList); } @@ -126,7 +125,7 @@ public final class OptionsUtils { * shell-escaped. */ public static String asFilteredShellEscapedString(OptionsProvider options) { - return asFilteredShellEscapedString(options, options.asListOfUnparsedOptions()); + return asFilteredShellEscapedString(options, options.asCompleteListOfParsedOptions()); } /** diff --git a/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java b/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java index 59d1a418b5..4285f33fb1 100644 --- a/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java +++ b/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java @@ -232,7 +232,7 @@ public final class InvocationPolicyEnforcer { String.format("Disallow_Values on expansion flags like %s is not allowed.", flagName)); } - private static ImmutableList<UnparsedOptionValueDescription> getExpansionsFromFlagPolicy( + private static ImmutableList<ParsedOptionDescription> getExpansionsFromFlagPolicy( FlagPolicy expansionPolicy, OptionDescription optionDescription, OptionsParser parser) throws OptionsParsingException { if (!optionDescription.isExpansion()) { @@ -248,7 +248,7 @@ public final class InvocationPolicyEnforcer { optionDescription.getOptionDefinition().getOptionName(), expansionPolicy.getFlagName())); - ImmutableList.Builder<UnparsedOptionValueDescription> resultsBuilder = ImmutableList.builder(); + ImmutableList.Builder<ParsedOptionDescription> resultsBuilder = ImmutableList.builder(); switch (expansionPolicy.getOperationCase()) { case SET_VALUE: { @@ -327,10 +327,10 @@ public final class InvocationPolicyEnforcer { return expandedPolicies; } - ImmutableList<UnparsedOptionValueDescription> expansions = + ImmutableList<ParsedOptionDescription> expansions = getExpansionsFromFlagPolicy(originalPolicy, originalOptionDescription, parser); - ImmutableList.Builder<UnparsedOptionValueDescription> subflagBuilder = ImmutableList.builder(); - ImmutableList<UnparsedOptionValueDescription> subflags = + ImmutableList.Builder<ParsedOptionDescription> subflagBuilder = ImmutableList.builder(); + ImmutableList<ParsedOptionDescription> subflags = subflagBuilder .addAll(originalOptionDescription.getImplicitRequirements()) .addAll(expansions) @@ -342,7 +342,7 @@ public final class InvocationPolicyEnforcer { // only really useful for understanding the invocation policy itself. Most of the time, // invocation policy does not change, so this can be a log level fine. List<String> subflagNames = new ArrayList<>(subflags.size()); - for (UnparsedOptionValueDescription subflag : subflags) { + for (ParsedOptionDescription subflag : subflags) { subflagNames.add("--" + subflag.getOptionDefinition().getOptionName()); } @@ -360,13 +360,13 @@ public final class InvocationPolicyEnforcer { // Repeated flags are special, and could set multiple times in an expansion, with the user // expecting both values to be valid. Collect these separately. - Multimap<OptionDefinition, UnparsedOptionValueDescription> repeatableSubflagsInSetValues = + Multimap<OptionDefinition, ParsedOptionDescription> repeatableSubflagsInSetValues = ArrayListMultimap.create(); // Create a flag policy for the child that looks like the parent's policy "transferred" to its // child. Note that this only makes sense for SetValue, when setting an expansion flag, or // UseDefault, when preventing it from being set. - for (UnparsedOptionValueDescription currentSubflag : subflags) { + for (ParsedOptionDescription currentSubflag : subflags) { if (currentSubflag.getOptionDefinition().allowsMultiple() && originalPolicy.getOperationCase().equals(OperationCase.SET_VALUE)) { repeatableSubflagsInSetValues.put(currentSubflag.getOptionDefinition(), currentSubflag); @@ -384,8 +384,7 @@ public final class InvocationPolicyEnforcer { for (OptionDefinition repeatableFlag : repeatableSubflagsInSetValues.keySet()) { int numValues = repeatableSubflagsInSetValues.get(repeatableFlag).size(); ArrayList<String> newValues = new ArrayList<>(numValues); - for (UnparsedOptionValueDescription setValue : - repeatableSubflagsInSetValues.get(repeatableFlag)) { + for (ParsedOptionDescription setValue : repeatableSubflagsInSetValues.get(repeatableFlag)) { newValues.add(setValue.getUnconvertedValue()); } expandedPolicies.add(getSetValueSubflagAsPolicy(repeatableFlag, newValues, originalPolicy)); @@ -444,7 +443,7 @@ public final class InvocationPolicyEnforcer { * corresponding policy. */ private static FlagPolicy getSingleValueSubflagAsPolicy( - UnparsedOptionValueDescription currentSubflag, FlagPolicy originalPolicy, boolean isExpansion) + ParsedOptionDescription currentSubflag, FlagPolicy originalPolicy, boolean isExpansion) throws OptionsParsingException { FlagPolicy subflagAsPolicy = null; switch (originalPolicy.getOperationCase()) { diff --git a/src/main/java/com/google/devtools/common/options/OptionsParser.java b/src/main/java/com/google/devtools/common/options/OptionsParser.java index 881fb384fa..3e6b5ccba8 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsParser.java +++ b/src/main/java/com/google/devtools/common/options/OptionsParser.java @@ -235,12 +235,12 @@ public class OptionsParser implements OptionsProvider { private final OptionDefinition optionDefinition; private final OptionsData.ExpansionData expansionData; - private final ImmutableList<UnparsedOptionValueDescription> implicitRequirements; + private final ImmutableList<ParsedOptionDescription> implicitRequirements; OptionDescription( OptionDefinition definition, OptionsData.ExpansionData expansionData, - ImmutableList<UnparsedOptionValueDescription> implicitRequirements) { + ImmutableList<ParsedOptionDescription> implicitRequirements) { this.optionDefinition = definition; this.expansionData = expansionData; this.implicitRequirements = implicitRequirements; @@ -250,7 +250,7 @@ public class OptionsParser implements OptionsProvider { return optionDefinition; } - public ImmutableList<UnparsedOptionValueDescription> getImplicitRequirements() { + public ImmutableList<ParsedOptionDescription> getImplicitRequirements() { return implicitRequirements; } @@ -417,7 +417,7 @@ public class OptionsParser implements OptionsProvider { * @return The {@link com.google.devtools.common.options.OptionValueDescription>} for the option, * or null if there is no option by the given name. */ - ImmutableList<UnparsedOptionValueDescription> getExpansionOptionValueDescriptions( + ImmutableList<ParsedOptionDescription> getExpansionOptionValueDescriptions( OptionDefinition option, @Nullable String optionValue, OptionPriority priority, String source) throws OptionsParsingException { return impl.getExpansionOptionValueDescriptions(option, optionValue, priority, source); @@ -524,12 +524,12 @@ public class OptionsParser implements OptionsProvider { } @Override - public List<UnparsedOptionValueDescription> asListOfUnparsedOptions() { - return impl.asListOfUnparsedOptions(); + public List<ParsedOptionDescription> asCompleteListOfParsedOptions() { + return impl.asCompleteListOfParsedOptions(); } @Override - public List<UnparsedOptionValueDescription> asListOfExplicitOptions() { + public List<ParsedOptionDescription> asListOfExplicitOptions() { return impl.asListOfExplicitOptions(); } diff --git a/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java b/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java index b79e72da2e..3c41951014 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java +++ b/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java @@ -46,7 +46,9 @@ class OptionsParserImpl { private final OptionsData optionsData; /** - * We store the results of parsing the arguments in here. It'll look like + * We store the results of option parsing in here - since there can only be one value per option + * field, this is where the different instances of an option have been combined and the final + * value is tracked. It'll look like * * <pre> * OptionDefinition("--host") -> "www.google.com" @@ -55,24 +57,26 @@ class OptionsParserImpl { * * This map is modified by repeated calls to {@link #parse(OptionPriority,Function,List)}. */ - private final Map<OptionDefinition, OptionValueDescription> parsedValues = new HashMap<>(); + private final Map<OptionDefinition, OptionValueDescription> optionValues = new HashMap<>(); /** - * We store the pre-parsed, explicit options for each priority in here. - * We use partially preparsed options, which can be different from the original - * representation, e.g. "--nofoo" becomes "--foo=0". + * Explicit option tracking, tracking each option as it was provided, after they have been parsed. + * + * <p>The value is unconverted, still the string as it was read from the input, or partially + * altered in cases where the flag was set by non {@code --flag=value} forms; e.g. {@code --nofoo} + * becomes {@code --foo=0}. */ - private final List<UnparsedOptionValueDescription> unparsedValues = new ArrayList<>(); + private final List<ParsedOptionDescription> parsedOptions = new ArrayList<>(); /** - * Unparsed values for use with the canonicalize command are stored separately from unparsedValues - * so that invocation policy can modify the values for canonicalization (e.g. override - * user-specified values with default values) without corrupting the data used to represent the - * user's original invocation for {@link #asListOfExplicitOptions()} and {@link - * #asListOfUnparsedOptions()}. A LinkedHashMultimap is used so that canonicalization happens in - * the correct order and multiple values can be stored for flags that allow multiple values. + * The options for use with the canonicalize command are stored separately from parsedOptions so + * that invocation policy can modify the values for canonicalization (e.g. override user-specified + * values with default values) without corrupting the data used to represent the user's original + * invocation for {@link #asListOfExplicitOptions()} and {@link #asCompleteListOfParsedOptions()}. + * A LinkedHashMultimap is used so that canonicalization happens in the correct order and multiple + * values can be stored for flags that allow multiple values. */ - private final Multimap<OptionDefinition, UnparsedOptionValueDescription> canonicalizeValues = + private final Multimap<OptionDefinition, ParsedOptionDescription> canonicalizeValues = LinkedHashMultimap.create(); private final List<String> warnings = new ArrayList<>(); @@ -111,28 +115,24 @@ class OptionsParserImpl { this.argsPreProcessor = Preconditions.checkNotNull(preProcessor); } - /** - * Implements {@link OptionsParser#asListOfUnparsedOptions()}. - */ - List<UnparsedOptionValueDescription> asListOfUnparsedOptions() { - return unparsedValues + /** Implements {@link OptionsParser#asCompleteListOfParsedOptions()}. */ + List<ParsedOptionDescription> asCompleteListOfParsedOptions() { + return parsedOptions .stream() // It is vital that this sort is stable so that options on the same priority are not // reordered. - .sorted(comparing(UnparsedOptionValueDescription::getPriority)) + .sorted(comparing(ParsedOptionDescription::getPriority)) .collect(toCollection(ArrayList::new)); } - /** - * Implements {@link OptionsParser#asListOfExplicitOptions()}. - */ - List<UnparsedOptionValueDescription> asListOfExplicitOptions() { - return unparsedValues + /** Implements {@link OptionsParser#asListOfExplicitOptions()}. */ + List<ParsedOptionDescription> asListOfExplicitOptions() { + return parsedOptions .stream() - .filter(UnparsedOptionValueDescription::isExplicit) + .filter(ParsedOptionDescription::isExplicit) // It is vital that this sort is stable so that options on the same priority are not // reordered. - .sorted(comparing(UnparsedOptionValueDescription::getPriority)) + .sorted(comparing(ParsedOptionDescription::getPriority)) .collect(toCollection(ArrayList::new)); } @@ -175,11 +175,11 @@ class OptionsParserImpl { List<OptionValueDescription> result = new ArrayList<>(); for (Map.Entry<String, OptionDefinition> mapEntry : optionsData.getAllOptionDefinitions()) { OptionDefinition optionDefinition = mapEntry.getValue(); - OptionValueDescription entry = parsedValues.get(optionDefinition); - if (entry == null) { + OptionValueDescription optionValue = optionValues.get(optionDefinition); + if (optionValue == null) { result.add(OptionValueDescription.newDefaultValue(optionDefinition)); } else { - result.add(entry); + result.add(optionValue); } } return result; @@ -200,46 +200,46 @@ class OptionsParserImpl { // Warnings should not end with a '.' because the internal reporter adds one automatically. private void setValue( - UnparsedOptionValueDescription optionValue, + ParsedOptionDescription parsedOption, OptionDefinition implicitDependant, OptionDefinition expandedFrom) throws OptionsParsingException { - OptionDefinition optionDefinition = optionValue.getOptionDefinition(); + OptionDefinition optionDefinition = parsedOption.getOptionDefinition(); Preconditions.checkArgument(!optionDefinition.allowsMultiple()); - Object convertedValue = optionValue.getConvertedValue(); - OptionValueDescription entry = parsedValues.get(optionValue.getOptionDefinition()); - if (entry != null) { + Object convertedValue = parsedOption.getConvertedValue(); + OptionValueDescription optionValue = optionValues.get(parsedOption.getOptionDefinition()); + if (optionValue != null) { // Override existing option if the new value has higher or equal priority. - if (optionValue.getPriority().compareTo(entry.getPriority()) >= 0) { + if (parsedOption.getPriority().compareTo(optionValue.getPriority()) >= 0) { // Output warnings: - if ((implicitDependant != null) && (entry.getImplicitDependant() != null)) { - if (!implicitDependant.equals(entry.getImplicitDependant())) { + if ((implicitDependant != null) && (optionValue.getImplicitDependant() != null)) { + if (!implicitDependant.equals(optionValue.getImplicitDependant())) { warnings.add( "Option '" + optionDefinition.getOptionName() + "' is implicitly defined by both option '" - + entry.getImplicitDependant().getOptionName() + + optionValue.getImplicitDependant().getOptionName() + "' and option '" + implicitDependant.getOptionName() + "'"); } } else if ((implicitDependant != null) - && optionValue.getPriority().equals(entry.getPriority())) { + && parsedOption.getPriority().equals(optionValue.getPriority())) { warnings.add( "Option '" + optionDefinition.getOptionName() + "' is implicitly defined by option '" + implicitDependant.getOptionName() + "'; the implicitly set value overrides the previous one"); - } else if (entry.getImplicitDependant() != null) { + } else if (optionValue.getImplicitDependant() != null) { warnings.add( "A new value for option '" + optionDefinition.getOptionName() + "' overrides a previous implicit setting of that option by option '" - + entry.getImplicitDependant().getOptionName() + + optionValue.getImplicitDependant().getOptionName() + "'"); - } else if ((optionValue.getPriority() == entry.getPriority()) - && ((entry.getExpansionParent() == null) && (expandedFrom != null))) { + } else if ((parsedOption.getPriority() == optionValue.getPriority()) + && ((optionValue.getExpansionParent() == null) && (expandedFrom != null))) { // Create a warning if an expansion option overrides an explicit option: warnings.add( "The option '" @@ -248,38 +248,38 @@ class OptionsParserImpl { + "previous explicitly specified option '" + optionDefinition.getOptionName() + "'"); - } else if ((entry.getExpansionParent() != null) && (expandedFrom != null)) { + } else if ((optionValue.getExpansionParent() != null) && (expandedFrom != null)) { warnings.add( "The option '" + optionDefinition.getOptionName() + "' was expanded to from both options '" - + entry.getExpansionParent().getOptionName() + + optionValue.getExpansionParent().getOptionName() + "' and '" + expandedFrom.getOptionName() + "'"); } // Record the new value: - parsedValues.put( + optionValues.put( optionDefinition, OptionValueDescription.newOptionValue( optionDefinition, null, convertedValue, - optionValue.getPriority(), - optionValue.getSource(), + parsedOption.getPriority(), + parsedOption.getSource(), implicitDependant, expandedFrom)); } } else { - parsedValues.put( + optionValues.put( optionDefinition, OptionValueDescription.newOptionValue( optionDefinition, null, convertedValue, - optionValue.getPriority(), - optionValue.getSource(), + parsedOption.getPriority(), + parsedOption.getSource(), implicitDependant, expandedFrom)); maybeAddDeprecationWarning(optionDefinition); @@ -287,36 +287,36 @@ class OptionsParserImpl { } private void addListValue( - UnparsedOptionValueDescription optionValue, + ParsedOptionDescription parsedOption, OptionDefinition implicitDependant, OptionDefinition expandedFrom) throws OptionsParsingException { - OptionDefinition optionDefinition = optionValue.getOptionDefinition(); + OptionDefinition optionDefinition = parsedOption.getOptionDefinition(); Preconditions.checkArgument(optionDefinition.allowsMultiple()); - OptionValueDescription entry = parsedValues.get(optionDefinition); - if (entry == null) { - entry = + OptionValueDescription optionValue = optionValues.get(optionDefinition); + if (optionValue == null) { + optionValue = OptionValueDescription.newOptionValue( optionDefinition, /* originalValueString */ null, ArrayListMultimap.create(), - optionValue.getPriority(), - optionValue.getSource(), + parsedOption.getPriority(), + parsedOption.getSource(), implicitDependant, expandedFrom); - parsedValues.put(optionDefinition, entry); + optionValues.put(optionDefinition, optionValue); maybeAddDeprecationWarning(optionDefinition); } - Object convertedValue = optionValue.getConvertedValue(); - entry.addValue(optionValue.getPriority(), convertedValue); + Object convertedValue = parsedOption.getConvertedValue(); + optionValue.addValue(parsedOption.getPriority(), convertedValue); } OptionValueDescription clearValue(OptionDefinition optionDefinition) throws OptionsParsingException { // Actually remove the value from various lists tracking effective options. canonicalizeValues.removeAll(optionDefinition); - return parsedValues.remove(optionDefinition); + return optionValues.remove(optionDefinition); } OptionValueDescription getOptionValueDescription(String name) { @@ -324,7 +324,7 @@ class OptionsParserImpl { if (optionDefinition == null) { throw new IllegalArgumentException("No such option '" + name + "'"); } - return parsedValues.get(optionDefinition); + return optionValues.get(optionDefinition); } OptionDescription getOptionDescription(String name, OptionPriority priority, String source) @@ -345,13 +345,13 @@ class OptionsParserImpl { } /** @return A list of the descriptions corresponding to the implicit dependant flags passed in. */ - private ImmutableList<UnparsedOptionValueDescription> getImplicitDependantDescriptions( + private ImmutableList<ParsedOptionDescription> getImplicitDependantDescriptions( ImmutableList<String> options, OptionDefinition implicitDependant, OptionPriority priority, String source) throws OptionsParsingException { - ImmutableList.Builder<UnparsedOptionValueDescription> builder = ImmutableList.builder(); + ImmutableList.Builder<ParsedOptionDescription> builder = ImmutableList.builder(); Iterator<String> optionsIterator = options.iterator(); Function<OptionDefinition, String> sourceFunction = @@ -361,10 +361,10 @@ class OptionsParserImpl { implicitDependant.getOptionName(), source); while (optionsIterator.hasNext()) { String unparsedFlagExpression = optionsIterator.next(); - UnparsedOptionValueDescription unparsedOption = + ParsedOptionDescription parsedOption = identifyOptionAndPossibleArgument( unparsedFlagExpression, optionsIterator, priority, sourceFunction, false); - builder.add(unparsedOption); + builder.add(parsedOption); } return builder.build(); } @@ -375,13 +375,13 @@ class OptionsParserImpl { * correct priority or source for these, as they are not actually set values. The value itself * is also a string, no conversion has taken place. */ - ImmutableList<UnparsedOptionValueDescription> getExpansionOptionValueDescriptions( + ImmutableList<ParsedOptionDescription> getExpansionOptionValueDescriptions( OptionDefinition expansionFlag, @Nullable String flagValue, OptionPriority priority, String source) throws OptionsParsingException { - ImmutableList.Builder<UnparsedOptionValueDescription> builder = ImmutableList.builder(); + ImmutableList.Builder<ParsedOptionDescription> builder = ImmutableList.builder(); ImmutableList<String> options = optionsData.getEvaluatedExpansion(expansionFlag, flagValue); Iterator<String> optionsIterator = options.iterator(); @@ -389,10 +389,10 @@ class OptionsParserImpl { o -> String.format("expanded from %s (source: %s)", expansionFlag.getOptionName(), source); while (optionsIterator.hasNext()) { String unparsedFlagExpression = optionsIterator.next(); - UnparsedOptionValueDescription unparsedOption = + ParsedOptionDescription parsedOption = identifyOptionAndPossibleArgument( unparsedFlagExpression, optionsIterator, priority, sourceFunction, false); - builder.add(unparsedOption); + builder.add(parsedOption); } return builder.build(); } @@ -402,7 +402,7 @@ class OptionsParserImpl { if (optionDefinition == null) { throw new IllegalArgumentException("No such option '" + name + "'"); } - return parsedValues.get(optionDefinition) != null; + return optionValues.get(optionDefinition) != null; } /** @@ -449,11 +449,11 @@ class OptionsParserImpl { break; } - UnparsedOptionValueDescription unparsedOption = + ParsedOptionDescription parsedOption = identifyOptionAndPossibleArgument( arg, argsIterator, priority, sourceFunction, isExplicit); - OptionDefinition optionDefinition = unparsedOption.getOptionDefinition(); - @Nullable String unconvertedValue = unparsedOption.getUnconvertedValue(); + OptionDefinition optionDefinition = parsedOption.getOptionDefinition(); + @Nullable String unconvertedValue = parsedOption.getUnconvertedValue(); if (optionDefinition.isWrapperOption()) { if (unconvertedValue.startsWith("-")) { @@ -476,7 +476,7 @@ class OptionsParserImpl { } // Don't process implicitRequirements or expansions for wrapper options. In particular, - // don't record this option in unparsedValues, so that only the wrapped option shows + // don't record this option in parsedOptions, so that only the wrapped option shows // up in canonicalized options. continue; @@ -496,11 +496,11 @@ class OptionsParserImpl { // Log explicit options and expanded options in the order they are parsed (can be sorted // later). Also remember whether they were expanded or not. This information is needed to // correctly canonicalize flags. - unparsedValues.add(unparsedOption); + parsedOptions.add(parsedOption); if (optionDefinition.allowsMultiple()) { - canonicalizeValues.put(optionDefinition, unparsedOption); + canonicalizeValues.put(optionDefinition, parsedOption); } else { - canonicalizeValues.replaceValues(optionDefinition, ImmutableList.of(unparsedOption)); + canonicalizeValues.replaceValues(optionDefinition, ImmutableList.of(parsedOption)); } } @@ -531,11 +531,11 @@ class OptionsParserImpl { // ...but allow duplicates of single-use options across separate calls to // parse(); latest wins: if (!optionDefinition.allowsMultiple()) { - setValue(unparsedOption, implicitDependent, expandedFrom); + setValue(parsedOption, implicitDependent, expandedFrom); } else { // But if it's a multiple-use option, then accumulate the values, in the order in which // they were seen. - addListValue(unparsedOption, implicitDependent, expandedFrom); + addListValue(parsedOption, implicitDependent, expandedFrom); } } @@ -571,7 +571,7 @@ class OptionsParserImpl { return unparsedArgs; } - private UnparsedOptionValueDescription identifyOptionAndPossibleArgument( + private ParsedOptionDescription identifyOptionAndPossibleArgument( String arg, Iterator<String> nextArgs, OptionPriority priority, @@ -582,7 +582,7 @@ class OptionsParserImpl { // Store the way this option was parsed on the command line. StringBuilder commandLineForm = new StringBuilder(); commandLineForm.append(arg); - String unparsedValue = null; + String unconvertedValue = null; OptionDefinition optionDefinition; boolean booleanValue = true; @@ -604,7 +604,7 @@ class OptionsParserImpl { if (name.trim().isEmpty()) { throw new OptionsParsingException("Invalid options syntax: " + arg, arg); } - unparsedValue = equalsAt == -1 ? null : arg.substring(equalsAt + 1); + unconvertedValue = equalsAt == -1 ? null : arg.substring(equalsAt + 1); optionDefinition = optionsData.getOptionDefinitionFromName(name); // Look for a "no"-prefixed option name: "no<optionName>". @@ -618,12 +618,12 @@ class OptionsParserImpl { throw new OptionsParsingException( "Illegal use of 'no' prefix on non-boolean option: " + arg, arg); } - if (unparsedValue != null) { + if (unconvertedValue != null) { throw new OptionsParsingException( "Unexpected value after boolean option: " + arg, arg); } // "no<optionname>" signifies a boolean option w/ false value - unparsedValue = "0"; + unconvertedValue = "0"; } } } else { @@ -637,26 +637,26 @@ class OptionsParserImpl { throw new OptionsParsingException("Unrecognized option: " + arg, arg); } - if (unparsedValue == null) { + if (unconvertedValue == null) { // Special-case boolean to supply value based on presence of "no" prefix. if (optionDefinition.usesBooleanValueSyntax()) { - unparsedValue = booleanValue ? "1" : "0"; + unconvertedValue = booleanValue ? "1" : "0"; } else if (optionDefinition.getType().equals(Void.class) && !optionDefinition.isWrapperOption()) { // This is expected, Void type options have no args (unless they're wrapper options). } else if (nextArgs.hasNext()) { // "--flag value" form - unparsedValue = nextArgs.next(); - commandLineForm.append(" ").append(unparsedValue); + unconvertedValue = nextArgs.next(); + commandLineForm.append(" ").append(unconvertedValue); } else { throw new OptionsParsingException("Expected value after " + arg); } } - return new UnparsedOptionValueDescription( + return new ParsedOptionDescription( optionDefinition, commandLineForm.toString(), - unparsedValue, + unconvertedValue, priority, sourceFunction.apply(optionDefinition), explicit); @@ -682,11 +682,11 @@ class OptionsParserImpl { for (OptionDefinition optionDefinition : OptionsData.getAllOptionDefinitionsForClass(optionsClass)) { Object value; - OptionValueDescription entry = parsedValues.get(optionDefinition); - if (entry == null) { + OptionValueDescription optionValue = optionValues.get(optionDefinition); + if (optionValue == null) { value = optionDefinition.getDefaultValue(); } else { - value = entry.getValue(); + value = optionValue.getValue(); } try { optionDefinition.getField().set(optionsInstance, value); diff --git a/src/main/java/com/google/devtools/common/options/OptionsProvider.java b/src/main/java/com/google/devtools/common/options/OptionsProvider.java index ab420601eb..1c7737fbda 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsProvider.java +++ b/src/main/java/com/google/devtools/common/options/OptionsProvider.java @@ -34,27 +34,25 @@ public interface OptionsProvider extends OptionsClassProvider { boolean containsExplicitOption(String string); /** - * Returns a mutable copy of the list of all options that were specified - * either explicitly or implicitly. These options are sorted by priority, and - * by the order in which they were specified. If an option was specified - * multiple times, it is included in the result multiple times. Does not - * include the residue. + * Returns a mutable copy of the list of all options that were specified either explicitly or + * implicitly. These options are sorted by priority, and by the order in which they were + * specified. If an option was specified multiple times, it is included in the result multiple + * times. Does not include the residue. * - * <p>The returned list can be filtered if undocumented, hidden or implicit - * options should not be displayed. + * <p>The returned list can be filtered if undocumented, hidden or implicit options should not be + * displayed. */ - List<UnparsedOptionValueDescription> asListOfUnparsedOptions(); + List<ParsedOptionDescription> asCompleteListOfParsedOptions(); /** - * Returns a list of all explicitly specified options, suitable for logging - * or for displaying back to the user. These options are sorted by priority, - * and by the order in which they were specified. If an option was - * explicitly specified multiple times, it is included in the result + * Returns a list of all explicitly specified options, suitable for logging or for displaying back + * to the user. These options are sorted by priority, and by the order in which they were + * specified. If an option was explicitly specified multiple times, it is included in the result * multiple times. Does not include the residue. * * <p>The list includes undocumented options. */ - List<UnparsedOptionValueDescription> asListOfExplicitOptions(); + List<ParsedOptionDescription> asListOfExplicitOptions(); /** * Returns a list of all options, including undocumented ones, and their diff --git a/src/main/java/com/google/devtools/common/options/UnparsedOptionValueDescription.java b/src/main/java/com/google/devtools/common/options/ParsedOptionDescription.java index c6fbbf7456..1c897c39d8 100644 --- a/src/main/java/com/google/devtools/common/options/UnparsedOptionValueDescription.java +++ b/src/main/java/com/google/devtools/common/options/ParsedOptionDescription.java @@ -26,7 +26,7 @@ import javax.annotation.Nullable; * <p>The origin includes the form it had when parsed, its priority, a message about where it came * from, and whether it was set explicitly or expanded/implied by other flags. */ -public final class UnparsedOptionValueDescription { +public final class ParsedOptionDescription { private final OptionDefinition optionDefinition; private final String commandLineForm; @Nullable private final String unconvertedValue; @@ -38,7 +38,7 @@ public final class UnparsedOptionValueDescription { // user, for that to be true, it needs the right combination of explicit & priority. private final boolean explicit; - public UnparsedOptionValueDescription( + public ParsedOptionDescription( OptionDefinition optionDefinition, String commandLineForm, @Nullable String unconvertedValue, |