private static <T> void addNewElements(
     @NotNull Collection<T> original, @NotNull Collection<T> toAdd) {
   for (T item : toAdd) {
     if (!original.contains(item)) {
       original.add(item);
     }
   }
 }
Exemplo n.º 2
0
 static void importInjections(
     final Collection<BaseInjection> existingInjections,
     final Collection<BaseInjection> importingInjections,
     final Collection<BaseInjection> originalInjections,
     final Collection<BaseInjection> newInjections) {
   final MultiValuesMap<InjectionPlace, BaseInjection> placeMap =
       new MultiValuesMap<InjectionPlace, BaseInjection>();
   for (BaseInjection exising : existingInjections) {
     for (InjectionPlace place : exising.getInjectionPlaces()) {
       placeMap.put(place, exising);
     }
   }
   main:
   for (BaseInjection other : importingInjections) {
     final List<BaseInjection> matchingInjections =
         ContainerUtil.concat(
             other.getInjectionPlaces(),
             new Function<InjectionPlace, Collection<? extends BaseInjection>>() {
               public Collection<? extends BaseInjection> fun(final InjectionPlace o) {
                 final Collection<BaseInjection> collection = placeMap.get(o);
                 return collection == null ? Collections.<BaseInjection>emptyList() : collection;
               }
             });
     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);
       }
     }
   }
 }
 @TestOnly
 public static void allowRootAccess(@NotNull String... roots) {
   for (String root : roots) {
     ourAdditionalRoots.add(FileUtil.toSystemIndependentName(root));
   }
 }