• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
14 package com.google.devtools.common.options;
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. */
19 @FunctionalInterface
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 
CommandNameCacheInstance()26     private CommandNameCacheInstance() {}
27 
28     /** Only for use by {@code BlazeRuntime}. */
setCommandNameCache(CommandNameCache cache)29     public void setCommandNameCache(CommandNameCache cache) {
30       // Can be set multiple times in tests.
31       this.delegate = cache;
32     }
33 
34     @Override
get(String commandName)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. */
get(String commandName)41   ImmutableSet<String> get(String commandName);
42 }
43