aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/common/options/ExpansionFunction.java
diff options
context:
space:
mode:
authorGravatar Jon Brandvein <brandjon@google.com>2017-03-21 23:15:28 +0000
committerGravatar Yue Gan <yueg@google.com>2017-03-22 10:54:26 +0000
commit22d261c21748fba31797f0de8bd98fb2ff2fd2f5 (patch)
tree6e6eed659033730eab800d0ec01dac7e65fcc6f0 /src/main/java/com/google/devtools/common/options/ExpansionFunction.java
parentb628cab872f5784e661e6c5c2db2827877d43837 (diff)
Add expansion functions to options parser
This provides a way to programmatically define expansions of options based on what other options are defined for the parser. In particular, it will be used for the --incompatible_* changes mechanism, to turn on all incompatible change flags. Expansion functions are specified in the @Option annotation, similar to converters. They are computed when an OptionsParser is constructed, and inspect a preliminary version of its OptionsData to determine the expansion result. This is then cached in the final OptionsData used by the parser. Expansion information for usage strings is available, but only when the usage strings are obtained via the parser. -- PiperOrigin-RevId: 150817553 MOS_MIGRATED_REVID=150817553
Diffstat (limited to 'src/main/java/com/google/devtools/common/options/ExpansionFunction.java')
-rw-r--r--src/main/java/com/google/devtools/common/options/ExpansionFunction.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/common/options/ExpansionFunction.java b/src/main/java/com/google/devtools/common/options/ExpansionFunction.java
new file mode 100644
index 0000000000..ffab6e70fc
--- /dev/null
+++ b/src/main/java/com/google/devtools/common/options/ExpansionFunction.java
@@ -0,0 +1,31 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.common.options;
+
+/**
+ * A function from an option parser's static setup (what flags it knows about) to an expansion
+ * String[] to use for one of its options.
+ */
+public interface ExpansionFunction {
+
+ /**
+ * Compute the expansion for an option. May be called at any time during or after the {@link
+ * OptionsParser}'s construction, or not at all.
+ *
+ * @param optionsData the parser's indexed information about its own options, before expansion
+ * information is computed
+ * @return An expansion to use for all occurrences of this option in this parser
+ */
+ public String[] getExpansion(IsolatedOptionsData optionsData);
+}