diff options
author | ccalvarin <ccalvarin@google.com> | 2017-12-19 12:23:17 -0800 |
---|---|---|
committer | Ivan Gavrilovic <gavra@google.com> | 2018-05-04 10:36:31 +0100 |
commit | c9ab0808f008a976220475fff19aee72d6839292 (patch) | |
tree | 2281c998d4149715a3ef21b2b129bfc5152cf110 | |
parent | 9797e822f8bf3ebfea27240271b715cf3a6837b7 (diff) | |
download | desugar-c9ab0808f008a976220475fff19aee72d6839292.tar.gz |
Remove wrapper options support.
RELNOTES: None.
PiperOrigin-RevId: 179588174
GitOrigin-RevId: 16f1c19c2c4f68555bb23891e3a4da4d5ac4a68d
Change-Id: I089b4b2e4c846682db552aa4c0e0905142e9278b
5 files changed, 9 insertions, 115 deletions
diff --git a/java/com/google/devtools/common/options/Option.java b/java/com/google/devtools/common/options/Option.java index 45f320a..f26a136 100644 --- a/java/com/google/devtools/common/options/Option.java +++ b/java/com/google/devtools/common/options/Option.java @@ -186,22 +186,4 @@ public @interface Option { * that the old name is deprecated and the new name should be used. */ String oldName() default ""; - - /** - * Indicates that this option is a wrapper for other options, and will be unwrapped when parsed. - * For example, if foo is a wrapper option, then "--foo=--bar=baz" will be parsed as the flag - * "--bar=baz" (rather than --foo taking the value "--bar=baz"). A wrapper option should have the - * type {@link Void} (if it is something other than Void, the parser will not assign a value to - * it). The {@link Option#implicitRequirements()}, {@link Option#expansion()}, {@link - * Option#converter()} attributes will not be processed. Wrapper options are implicitly repeatable - * (i.e., as though {@link Option#allowMultiple()} is true regardless of its value in the - * annotation). - * - * <p>Wrapper options are provided only for transitioning flags which appear as values to other - * flags, to top-level flags. Wrapper options should not be used in Invocation Policy, as - * expansion flags to other flags, or as implicit requirements to other flags. Use the inner flags - * instead. - */ - @Deprecated - boolean wrapperOption() default false; } diff --git a/java/com/google/devtools/common/options/OptionDefinition.java b/java/com/google/devtools/common/options/OptionDefinition.java index 84a9d2d..7b87744 100644 --- a/java/com/google/devtools/common/options/OptionDefinition.java +++ b/java/com/google/devtools/common/options/OptionDefinition.java @@ -156,11 +156,6 @@ public class OptionDefinition implements Comparable<OptionDefinition> { return optionAnnotation.oldName(); } - /** {@link Option#wrapperOption()} ()} ()} */ - public boolean isWrapperOption() { - return optionAnnotation.wrapperOption(); - } - /** Returns whether an option --foo has a negative equivalent --nofoo. */ public boolean hasNegativeOption() { return getType().equals(boolean.class) || getType().equals(TriState.class); diff --git a/java/com/google/devtools/common/options/OptionValueDescription.java b/java/com/google/devtools/common/options/OptionValueDescription.java index 616b3b5..3fde138 100644 --- a/java/com/google/devtools/common/options/OptionValueDescription.java +++ b/java/com/google/devtools/common/options/OptionValueDescription.java @@ -98,8 +98,6 @@ public abstract class OptionValueDescription { return new RepeatableOptionValueDescription(option); } else if (option.hasImplicitRequirements()) { return new OptionWithImplicitRequirementsValueDescription(option); - } else if (option.isWrapperOption()) { - return new WrapperOptionValueDescription(option); } else { return new SingleOptionValueDescription(option); } @@ -430,50 +428,6 @@ public abstract class OptionValueDescription { optionDefinition, parsedOption.getSource())); } } - - /** Form for options that contain other options in the value text to which they expand. */ - private static final class WrapperOptionValueDescription extends OptionValueDescription { - - WrapperOptionValueDescription(OptionDefinition optionDefinition) { - super(optionDefinition); - } - - @Override - public Object getValue() { - return null; - } - - @Override - public String getSourceString() { - return null; - } - - @Override - ExpansionBundle addOptionInstance(ParsedOptionDescription parsedOption, List<String> warnings) - throws OptionsParsingException { - if (!parsedOption.getUnconvertedValue().startsWith("-")) { - throw new OptionsParsingException( - String.format( - "Invalid value format for %s. You may have meant --%s=--%s", - optionDefinition, - optionDefinition.getOptionName(), - parsedOption.getUnconvertedValue())); - } - return new ExpansionBundle( - ImmutableList.of(parsedOption.getUnconvertedValue()), - (parsedOption.getSource() == null) - ? String.format("unwrapped from %s", optionDefinition) - : String.format( - "unwrapped from %s (source %s)", optionDefinition, parsedOption.getSource())); - } - - @Override - public ImmutableList<ParsedOptionDescription> getCanonicalInstances() { - // No wrapper options get listed in the canonical form - the options they are wrapping will - // be in the right place. - return ImmutableList.of(); - } - } } diff --git a/java/com/google/devtools/common/options/OptionsParserImpl.java b/java/com/google/devtools/common/options/OptionsParserImpl.java index 496927b..5ce35da 100644 --- a/java/com/google/devtools/common/options/OptionsParserImpl.java +++ b/java/com/google/devtools/common/options/OptionsParserImpl.java @@ -392,16 +392,15 @@ class OptionsParserImpl { @Nullable String unconvertedValue = parsedOption.getUnconvertedValue(); // There are 3 types of flags that expand to other flag values. Expansion flags are the - // accepted way to do this, but two legacy features remain: implicit requirements and wrapper - // options. We rely on the OptionProcessor compile-time check's guarantee that no option sets - // multiple of these behaviors. (In Bazel, --config is another such flag, but that expansion + // accepted way to do this, but implicit requirements also do this. We rely on the + // OptionProcessor compile-time check's guarantee that no option sets + // both expansion behaviors. (In Bazel, --config is another such flag, but that expansion // is not controlled within the options parser, so we ignore it here) // As much as possible, we want the behaviors of these different types of flags to be // identical, as this minimizes the number of edge cases, but we do not yet track these values - // in the same way. Wrapper options are replaced by their value and implicit requirements are - // hidden from the reported lists of parsed options. - if (parsedOption.getImplicitDependent() == null && !optionDefinition.isWrapperOption()) { + // in the same way. + if (parsedOption.getImplicitDependent() == null) { // Log explicit options and expanded options in the order they are parsed (can be sorted // later). This information is needed to correctly canonicalize flags. parsedOptions.add(parsedOption); @@ -416,13 +415,7 @@ class OptionsParserImpl { optionDefinition.isExpansionOption() ? optionDefinition : null, expansionBundle.expansionArgs); if (!residueAndPriority.residue.isEmpty()) { - if (optionDefinition.isWrapperOption()) { - throw new OptionsParsingException( - "Unparsed options remain after unwrapping " - + unconvertedValue - + ": " - + Joiner.on(' ').join(residueAndPriority.residue)); - } else { + // Throw an assertion here, because this indicates an error in the definition of this // option's expansion or requirements, not with the input as provided by the user. throw new AssertionError( @@ -430,7 +423,7 @@ class OptionsParserImpl { + unconvertedValue + ": " + Joiner.on(' ').join(residueAndPriority.residue)); - } + } } } @@ -506,9 +499,8 @@ class OptionsParserImpl { // Special-case boolean to supply value based on presence of "no" prefix. if (optionDefinition.usesBooleanValueSyntax()) { 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 (optionDefinition.getType().equals(Void.class)) { + // This is expected, Void type options have no args. } else if (nextArgs.hasNext()) { // "--flag value" form unconvertedValue = nextArgs.next(); diff --git a/java/com/google/devtools/common/options/processor/OptionProcessor.java b/java/com/google/devtools/common/options/processor/OptionProcessor.java index fd7c023..76b9640 100644 --- a/java/com/google/devtools/common/options/processor/OptionProcessor.java +++ b/java/com/google/devtools/common/options/processor/OptionProcessor.java @@ -476,10 +476,6 @@ public final class OptionProcessor extends AbstractProcessor { } if (isExpansion || hasImplicitRequirements) { - if (annotation.wrapperOption()) { - throw new OptionProcessorException( - optionField, "Wrapper options cannot have expansions or implicit requirements."); - } if (annotation.allowMultiple()) { throw new OptionProcessorException( optionField, @@ -488,30 +484,6 @@ public final class OptionProcessor extends AbstractProcessor { } } - /** - * Some flags wrap other flags. They are objectively useless, as there is no difference between - * passing --wrapper=--foo and --foo other than the "source" information tracked. This - * functionality comes from requiring compatibility at some past point in time, but is actively - * being deprecated. No non-deprecated flag can use this feature. - */ - private void checkWrapperOptions(VariableElement optionField) throws OptionProcessorException { - Option annotation = optionField.getAnnotation(Option.class); - if (annotation.wrapperOption()) { - if (annotation.deprecationWarning().isEmpty()) { - throw new OptionProcessorException( - optionField, - "Can't have non deprecated wrapper options, this feature is deprecated. " - + "Please add a deprecationWarning."); - } - if (!ImmutableList.copyOf(annotation.metadataTags()).contains(OptionMetadataTag.DEPRECATED)) { - throw new OptionProcessorException( - optionField, - "Can't have non deprecated wrapper options, this feature is deprecated. " - + "Please add the metadata tag DEPRECATED."); - } - } - } - @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Option.class)) { @@ -528,7 +500,6 @@ public final class OptionProcessor extends AbstractProcessor { checkConverter(optionField); checkEffectTagRationality(optionField); checkMetadataTagAndCategoryRationality(optionField); - checkWrapperOptions(optionField); } catch (OptionProcessorException e) { error(e.getElementInError(), e.getMessage()); } |