Janak Ramakrishnan | e9cd0f3 | 2016-04-29 22:46:16 +0000 | [diff] [blame] | 1 | // Copyright 2016 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License.package com.google.devtools.build.lib.flags; |
ccalvarin | f39dc6f | 2017-06-09 11:51:45 -0400 | [diff] [blame] | 14 | package com.google.devtools.common.options; |
Janak Ramakrishnan | e9cd0f3 | 2016-04-29 22:46:16 +0000 | [diff] [blame] | 15 | |
| 16 | import com.google.common.collect.ImmutableSet; |
| 17 | |
| 18 | /** Cache mapping a command to the names of all commands it inherits from, including itself. */ |
Jonathan Bluett-Duncan | 0df3ddbd | 2017-08-09 11:13:54 +0200 | [diff] [blame] | 19 | @FunctionalInterface |
Janak Ramakrishnan | e9cd0f3 | 2016-04-29 22:46:16 +0000 | [diff] [blame] | 20 | public interface CommandNameCache { |
| 21 | /** Class that exists only to expose a static instance variable that can be set and retrieved. */ |
| 22 | class CommandNameCacheInstance implements CommandNameCache { |
| 23 | public static final CommandNameCacheInstance INSTANCE = new CommandNameCacheInstance(); |
| 24 | private CommandNameCache delegate; |
| 25 | |
| 26 | private CommandNameCacheInstance() {} |
| 27 | |
| 28 | /** Only for use by {@code BlazeRuntime}. */ |
| 29 | public void setCommandNameCache(CommandNameCache cache) { |
| 30 | // Can be set multiple times in tests. |
| 31 | this.delegate = cache; |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public ImmutableSet<String> get(String commandName) { |
| 36 | return delegate.get(commandName); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** Returns the names of all commands {@code commandName} inherits from, including itself. */ |
| 41 | ImmutableSet<String> get(String commandName); |
| 42 | } |