コード例 #1
0
 private static <T> void addNewElements(
     @NotNull Collection<T> original, @NotNull Collection<T> toAdd) {
   for (T item : toAdd) {
     if (!original.contains(item)) {
       original.add(item);
     }
   }
 }
コード例 #2
0
 public boolean setHostInjectionEnabled(
     final PsiLanguageInjectionHost host,
     final Collection<String> languages,
     final boolean enabled) {
   final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>();
   final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>();
   for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
     for (BaseInjection injection : getInjections(support.getId())) {
       if (!languages.contains(injection.getInjectedLanguageId())) continue;
       boolean replace = false;
       final ArrayList<InjectionPlace> newPlaces = new ArrayList<InjectionPlace>();
       for (InjectionPlace place : injection.getInjectionPlaces()) {
         if (place.isEnabled() != enabled
             && place.getElementPattern() != null
             && (place.getElementPattern().accepts(host)
                 || place.getElementPattern().accepts(host.getParent()))) {
           newPlaces.add(place.enabled(enabled));
           replace = true;
         } else newPlaces.add(place);
       }
       if (replace) {
         originalInjections.add(injection);
         final BaseInjection newInjection = injection.copy();
         newInjection.setInjectionPlaces(newPlaces.toArray(new InjectionPlace[newPlaces.size()]));
         newInjections.add(newInjection);
       }
     }
   }
   if (!originalInjections.isEmpty()) {
     replaceInjectionsWithUndo(
         host.getProject(),
         newInjections,
         originalInjections,
         Collections.<PsiElement>emptyList());
     return true;
   }
   return false;
 }