summaryrefslogtreecommitdiff
path: root/java/com/google/devtools/common/options/ParsedOptionDescription.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/google/devtools/common/options/ParsedOptionDescription.java')
-rw-r--r--java/com/google/devtools/common/options/ParsedOptionDescription.java53
1 files changed, 39 insertions, 14 deletions
diff --git a/java/com/google/devtools/common/options/ParsedOptionDescription.java b/java/com/google/devtools/common/options/ParsedOptionDescription.java
index f55f8ad..5088153 100644
--- a/java/com/google/devtools/common/options/ParsedOptionDescription.java
+++ b/java/com/google/devtools/common/options/ParsedOptionDescription.java
@@ -14,6 +14,7 @@
package com.google.devtools.common.options;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.function.Function;
import javax.annotation.Nullable;
@@ -27,25 +28,49 @@ import javax.annotation.Nullable;
public final class ParsedOptionDescription {
private final OptionDefinition optionDefinition;
- private final String commandLineForm;
+ @Nullable private final String commandLineForm;
@Nullable private final String unconvertedValue;
private final OptionInstanceOrigin origin;
- public ParsedOptionDescription(
+ private ParsedOptionDescription(
OptionDefinition optionDefinition,
- String commandLineForm,
+ @Nullable String commandLineForm,
@Nullable String unconvertedValue,
OptionInstanceOrigin origin) {
- this.optionDefinition = optionDefinition;
+ this.optionDefinition = Preconditions.checkNotNull(optionDefinition);
this.commandLineForm = commandLineForm;
this.unconvertedValue = unconvertedValue;
- this.origin = origin;
+ this.origin = Preconditions.checkNotNull(origin);
+ }
+
+ static ParsedOptionDescription newParsedOptionDescription(
+ OptionDefinition optionDefinition,
+ String commandLineForm,
+ @Nullable String unconvertedValue,
+ OptionInstanceOrigin origin) {
+ // An actual ParsedOptionDescription should always have a form in which it was parsed, but some
+ // options, such as expansion options, legitimately have no value.
+ return new ParsedOptionDescription(
+ optionDefinition,
+ Preconditions.checkNotNull(commandLineForm),
+ unconvertedValue,
+ origin);
+ }
+
+ /**
+ * This factory should be used when there is no actual parsed option, since in those cases we do
+ * not have an original value or form that the option took.
+ */
+ static ParsedOptionDescription newDummyInstance(
+ OptionDefinition optionDefinition, OptionInstanceOrigin origin) {
+ return new ParsedOptionDescription(optionDefinition, null, null, origin);
}
public OptionDefinition getOptionDefinition() {
return optionDefinition;
}
+ @Nullable
public String getCommandLineForm() {
return commandLineForm;
}
@@ -127,11 +152,11 @@ public final class ParsedOptionDescription {
return origin.getSource();
}
- OptionDefinition getImplicitDependent() {
+ ParsedOptionDescription getImplicitDependent() {
return origin.getImplicitDependent();
}
- OptionDefinition getExpandedFrom() {
+ ParsedOptionDescription getExpandedFrom() {
return origin.getExpandedFrom();
}
@@ -152,14 +177,14 @@ public final class ParsedOptionDescription {
@Override
public String toString() {
- StringBuilder result = new StringBuilder();
- result.append(optionDefinition);
- result.append("set to '").append(unconvertedValue).append("' ");
- result.append("with priority ").append(origin.getPriority());
- if (origin.getSource() != null) {
- result.append(" and source '").append(origin.getSource()).append("'");
+ // Check that a dummy value-less option instance does not output all the default information.
+ if (commandLineForm == null) {
+ return optionDefinition.toString();
}
- return result.toString();
+ String source = origin.getSource();
+ return String.format(
+ "option '%s'%s",
+ commandLineForm, source == null ? "" : String.format(" (source %s)", source));
}
}