diff options
author | 2017-06-09 11:51:45 -0400 | |
---|---|---|
committer | 2017-06-09 14:06:16 -0400 | |
commit | f39dc6fc707cca9496d5baef5549bb7c24933776 (patch) | |
tree | f5a1ad175daf54395789d19a8d33c890ca3aff9d /src/main/java/com/google/devtools/common/options/CommandNameCache.java | |
parent | 6c1106b1a721516d3b3db54d2e1c31b44a76fbb1 (diff) |
Move InvocationPolicy to the options parser package.
It was originally included in runtime due to external dependencies, and
a desire to keep the options parser a general options library. These
dependencies have been or will be removed, and there are plenty of other
general flag libraries.
InvocationPolicy is fundamentally acting on the properties of this
specific OptionsParser and needs proper access to it for the proper
solution to a number of existing bugs, which means having access to
things that should be package private.
PiperOrigin-RevId: 158523111
Diffstat (limited to 'src/main/java/com/google/devtools/common/options/CommandNameCache.java')
-rw-r--r-- | src/main/java/com/google/devtools/common/options/CommandNameCache.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/common/options/CommandNameCache.java b/src/main/java/com/google/devtools/common/options/CommandNameCache.java new file mode 100644 index 0000000000..13c85b71e5 --- /dev/null +++ b/src/main/java/com/google/devtools/common/options/CommandNameCache.java @@ -0,0 +1,41 @@ +// Copyright 2016 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.build.lib.flags; +package com.google.devtools.common.options; + +import com.google.common.collect.ImmutableSet; + +/** Cache mapping a command to the names of all commands it inherits from, including itself. */ +public interface CommandNameCache { + /** Class that exists only to expose a static instance variable that can be set and retrieved. */ + class CommandNameCacheInstance implements CommandNameCache { + public static final CommandNameCacheInstance INSTANCE = new CommandNameCacheInstance(); + private CommandNameCache delegate; + + private CommandNameCacheInstance() {} + + /** Only for use by {@code BlazeRuntime}. */ + public void setCommandNameCache(CommandNameCache cache) { + // Can be set multiple times in tests. + this.delegate = cache; + } + + @Override + public ImmutableSet<String> get(String commandName) { + return delegate.get(commandName); + } + } + + /** Returns the names of all commands {@code commandName} inherits from, including itself. */ + ImmutableSet<String> get(String commandName); +} |