void (final Collection<? extends BaseInjection> existingInjections, final Collection<? extends BaseInjection> importingInjections, final Collection<? super BaseInjection> originalInjections, final Collection<? super BaseInjection> newInjections) { final MultiValuesMap<InjectionPlace, BaseInjection> placeMap = new MultiValuesMap<>(); for (BaseInjection exising : existingInjections) { for (InjectionPlace place : exising.getInjectionPlaces()) { placeMap.put(place, exising); } } main: for (BaseInjection other : importingInjections) { InjectionPlace[] places = other.getInjectionPlaces(); if (places.length == 0) { if (!existingInjections.contains(other)) newInjections.add(other); continue; } final Set<BaseInjection> matchingInjections = JBIterable.of(places) .flatten(o -> JBIterable.from(placeMap.get(o))).toSet(); if (matchingInjections.isEmpty()) { newInjections.add(other); } else { BaseInjection existing = null; for (BaseInjection injection : matchingInjections) { if (injection.equals(other)) continue main; if (existing == null && injection.sameLanguageParameters(other)) { existing = injection; } } if (existing == null) continue main; // skip!! language changed final BaseInjection newInjection = existing.copy(); newInjection.mergeOriginalPlacesFrom(other, true); if (!newInjection.equals(existing)) { originalInjections.add(existing); newInjections.add(newInjection); } } } }