Search in sources :

Example 1 with PrivateInternals_DynamicMapImpl

use of com.google.gerrit.extensions.registration.PrivateInternals_DynamicMapImpl in project gerrit by GerritCodeReview.

the class PluginGuiceEnvironment method reattachMap.

private void reattachMap(ListMultimap<TypeLiteral<?>, ReloadableRegistrationHandle<?>> oldHandles, Map<TypeLiteral<?>, DynamicMap<?>> maps, @Nullable Injector src, Plugin newPlugin) {
    if (src == null || maps == null || maps.isEmpty()) {
        return;
    }
    for (Map.Entry<TypeLiteral<?>, DynamicMap<?>> e : maps.entrySet()) {
        @SuppressWarnings("unchecked") TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
        @SuppressWarnings("unchecked") PrivateInternals_DynamicMapImpl<Object> map = (PrivateInternals_DynamicMapImpl<Object>) e.getValue();
        Map<Annotation, ReloadableRegistrationHandle<?>> am = new HashMap<>();
        for (ReloadableRegistrationHandle<?> h : oldHandles.get(type)) {
            Annotation a = h.getKey().getAnnotation();
            if (a != null && !UNIQUE_ANNOTATION.isInstance(a)) {
                am.put(a, h);
            }
        }
        for (Binding<?> binding : bindings(src, e.getKey())) {
            @SuppressWarnings("unchecked") Binding<Object> b = (Binding<Object>) binding;
            Key<Object> key = b.getKey();
            if (key.getAnnotation() == null) {
                continue;
            }
            @SuppressWarnings("unchecked") ReloadableRegistrationHandle<Object> h = (ReloadableRegistrationHandle<Object>) am.remove(key.getAnnotation());
            if (h != null) {
                replace(newPlugin, h, b);
                oldHandles.remove(type, h);
            } else {
                newPlugin.add(map.put(newPlugin.getName(), b.getKey(), b.getProvider()));
            }
        }
    }
}
Also used : Binding(com.google.inject.Binding) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Annotation(java.lang.annotation.Annotation) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) TypeLiteral(com.google.inject.TypeLiteral) ReloadableRegistrationHandle(com.google.gerrit.extensions.registration.ReloadableRegistrationHandle) PrivateInternals_DynamicMapImpl(com.google.gerrit.extensions.registration.PrivateInternals_DynamicMapImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap)

Aggregations

DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 PrivateInternals_DynamicMapImpl (com.google.gerrit.extensions.registration.PrivateInternals_DynamicMapImpl)1 ReloadableRegistrationHandle (com.google.gerrit.extensions.registration.ReloadableRegistrationHandle)1 Binding (com.google.inject.Binding)1 TypeLiteral (com.google.inject.TypeLiteral)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1