MultiHostRegistrar (@NonNls @Nullable String prefix, @NonNls @Nullable String suffix, @NotNull PsiLanguageInjectionHost host, @NotNull TextRange rangeInsideHost) { checkThreading(); if (myLanguage == null) { clear(); throw new IllegalStateException("Seems you haven't called startInjecting()"); } if (!host.isValidHost()) { throw new RuntimeExceptionWithAttachments(host + ".isValidHost() in " + host.getClass() + " returned false so you mustn't inject here.", new Attachment("host.txt", host.getText())); } PsiFile containingFile = PsiUtilCore.getTemplateLanguageFile(host); assert containingFile == myHostPsiFile : exceptionContext("Trying to inject into foreign file: "+containingFile, myLanguage, myHostPsiFile, myHostVirtualFile, myHostDocument, placeInfos, myDocumentManagerBase); TextRange hostTextRange = host.getTextRange(); if (!hostTextRange.contains(rangeInsideHost.shiftRight(hostTextRange.getStartOffset()))) { clear(); throw new IllegalArgumentException("rangeInsideHost must lie within host text range. rangeInsideHost:"+rangeInsideHost+"; host textRange:"+ hostTextRange); } cleared = false; String nnPrefix = StringUtil.isEmpty(prefix) ? "" : prefix; // intern empty strings too to reduce gc String nnSuffix = StringUtil.isEmpty(suffix) ? "" : suffix; // intern empty strings too to reduce gc PlaceInfo info = new PlaceInfo(nnPrefix, nnSuffix, host, rangeInsideHost); placeInfos.add(info); return this; }