void () { InjectedLanguageManager.getInstance(getProject()).registerMultiHostInjector(new MultiHostInjector() { @Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if (context.getText().contains("xxx")) { registrar .startInjecting(RegExpLanguage.INSTANCE) .addPlace(null, null, (PsiLanguageInjectionHost) context, StringLiteralManipulator.getValueRange((PsiLiteralExpression) context)) .doneInjecting(); } } @Override public @NotNull List<? extends Class<? extends PsiElement>> elementsToInjectIn() { return List.of(PsiLiteralExpression.class); } }, getTestRootDisposable()); String text = "class C { String s = \" abc def xxx \"; }"; PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText("a.java", JavaFileType.INSTANCE, text, 0, true); assertNull(TextExtractor.findTextAt(file, text.indexOf("def"), TextContent.TextDomain.ALL)); }