-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow expansion flags to have values.
This lets us change what it expands based on the argument passed to the flag. RELNOTES: Allows flags that expand to take values. PiperOrigin-RevId: 1602984
- Loading branch information
Showing
16 changed files
with
709 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/google/devtools/common/options/ExpansionContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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; | ||
|
||
import java.lang.reflect.Field; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* Encapsulates the data given to {@link ExpansionFunction} objects. This lets {@link | ||
* ExpansionFunction} objects change how it expands flags based on the arguments given to the {@link | ||
* OptionsParser}. | ||
*/ | ||
@ThreadSafe | ||
public final class ExpansionContext { | ||
private final IsolatedOptionsData optionsData; | ||
private final Field field; | ||
@Nullable private final String unparsedValue; | ||
|
||
public ExpansionContext( | ||
IsolatedOptionsData optionsData, Field field, @Nullable String unparsedValue) { | ||
this.optionsData = optionsData; | ||
this.field = field; | ||
this.unparsedValue = unparsedValue; | ||
} | ||
|
||
/** Metadata for the option that is being expanded. */ | ||
public IsolatedOptionsData getOptionsData() { | ||
return optionsData; | ||
} | ||
|
||
/** {@link Field} object for option that is being expanded. */ | ||
public Field getField() { | ||
return field; | ||
} | ||
|
||
/** Argument given to this flag during options parsing. Will be null if no argument was given. */ | ||
@Nullable | ||
public String getUnparsedValue() { | ||
return unparsedValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/google/devtools/common/options/ExpansionNeedsValueException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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; | ||
|
||
/** | ||
* Exception specific to evaluating {@link ExpansionFunction} objects. Used when expansion isn't | ||
* possible because of a missing input. | ||
*/ | ||
public final class ExpansionNeedsValueException extends OptionsParsingException { | ||
|
||
public ExpansionNeedsValueException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.