void (TempPlace place) { PsiLanguageInjectionHost host = place.elementPointer.getElement(); if (host == null) return; Set<PsiLanguageInjectionHost> hosts = new HashSet<>(); hosts.add(host); // because `enumerate` doesn't handle reference injections InjectedLanguageManager.getInstance(myProject).enumerate(host, (injectedPsi, places) -> { injectedPsi.putUserData(LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, place.language); for (PsiLanguageInjectionHost.Shred shred: places) { hosts.add(shred.getHost()); } }); List<TempPlace> injectionPoints = getInjectionPlacesSafe(); for (TempPlace tempPlace : injectionPoints) { if (hosts.contains(tempPlace.elementPointer.getElement())) { injectionPoints.remove(tempPlace); break; } } if (place.language != null) { injectionPoints.add(place); } host.putUserData(LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, place.language); host.getManager().dropPsiCaches(); }