| 77 | } |
| 78 | |
| 79 | public void add(Key<?> key, InjectorBindingData state, Object source) { |
| 80 | if (backingMap == null) { |
| 81 | backingMap = Maps.newHashMap(); |
| 82 | } |
| 83 | // if it's an instanceof Class, it was a JIT binding, which we don't |
| 84 | // want to retain. |
| 85 | if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) { |
| 86 | source = null; |
| 87 | } |
| 88 | Object convertedSource = Errors.convert(source); |
| 89 | backingMap.computeIfAbsent(key, k -> LinkedHashMultiset.create()).add(convertedSource); |
| 90 | |
| 91 | // Avoid all the extra work if we can. |
| 92 | if (state.parent().isPresent()) { |
| 93 | Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state); |
| 94 | if (keyAndSources == null) { |
| 95 | evictionCache.put(state, keyAndSources = Sets.newHashSet()); |
| 96 | } |
| 97 | keyAndSources.add(new KeyAndSource(key, convertedSource)); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | public boolean contains(Key<?> key) { |
| 102 | evictionCache.cleanUp(); |