コード例 #1
0
 public void processInjectableElements(
     Collection<PsiElement> in, Processor<PsiElement> processor) {
   ClassMapCachingNulls<MultiHostInjector> map = getInjectorMap();
   for (PsiElement element : in) {
     if (map.get(element.getClass()) != null) processor.process(element);
   }
 }
コード例 #2
0
  public void processInPlaceInjectorsFor(
      @NotNull PsiElement element, @NotNull InjProcessor processor) {
    MultiHostInjector[] infos = cachedInjectors.get(element.getClass());
    if (infos != null) {
      final boolean dumb = myDumbService.isDumb();
      for (MultiHostInjector injector : infos) {
        if (dumb && !DumbService.isDumbAware(injector)) {
          continue;
        }

        if (!processor.process(element, injector)) return;
      }
    }
  }
コード例 #3
0
 @TestOnly
 public static void checkInjectorsAreDisposed(@NotNull Project project) {
   InjectedLanguageManagerImpl cachedManager =
       (InjectedLanguageManagerImpl) project.getUserData(INSTANCE_CACHE);
   if (cachedManager == null) {
     return;
   }
   try {
     ClassMapCachingNulls<MultiHostInjector> cached = cachedManager.cachedInjectors;
     if (cached == null) return;
     for (Map.Entry<Class, MultiHostInjector[]> entry : cached.getBackingMap().entrySet()) {
       Class key = entry.getKey();
       if (cachedManager.myInjectorsClone.isEmpty()) return;
       MultiHostInjector[] oldInjectors = cachedManager.myInjectorsClone.get(key);
       for (MultiHostInjector injector : entry.getValue()) {
         if (ArrayUtil.indexOf(oldInjectors, injector) == -1) {
           throw new AssertionError("Injector was not disposed: " + key + " -> " + injector);
         }
       }
     }
   } finally {
     cachedManager.myInjectorsClone.clear();
   }
 }
コード例 #4
0
 @Override
 public void registerMultiHostInjector(@NotNull MultiHostInjector injector) {
   for (Class<? extends PsiElement> place : injector.elementsToInjectIn()) {
     LOG.assertTrue(place != null, injector);
     while (true) {
       MultiHostInjector[] injectors = this.injectors.get(place);
       if (injectors == null) {
         if (this.injectors.putIfAbsent(place, new MultiHostInjector[] {injector}) == null) break;
       } else {
         MultiHostInjector[] newInfos = ArrayUtil.append(injectors, injector);
         if (this.injectors.replace(place, injectors, newInfos)) break;
       }
     }
   }
   cachedInjectors.clearCache();
 }
コード例 #5
0
 @Override
 public boolean unregisterMultiHostInjector(@NotNull MultiHostInjector injector) {
   boolean removed = false;
   Iterator<Map.Entry<Class, MultiHostInjector[]>> iterator = injectors.entrySet().iterator();
   while (iterator.hasNext()) {
     Map.Entry<Class, MultiHostInjector[]> entry = iterator.next();
     MultiHostInjector[] infos = entry.getValue();
     int i = ArrayUtil.find(infos, injector);
     if (i != -1) {
       MultiHostInjector[] newInfos = ArrayUtil.remove(infos, i);
       if (newInfos.length == 0) {
         iterator.remove();
       } else {
         injectors.put(entry.getKey(), newInfos);
       }
       removed = true;
     }
   }
   cachedInjectors.clearCache();
   return removed;
 }