Provides list of places to inject a language to.
For example, to inject "RegExp" language to java string literal, you can override this method with something like this:
class MyRegExpToJavaInjector implements MultiHostInjector {
void getLanguagesToInject(MultiHostRegistrar registrar, PsiElement context) {
if (context instanceof PsiLiteralExpression && looksLikeAGoodPlaceToInject(context)) {
registrar.startInjecting(REGEXP_LANG).addPlace(null,null,context,innerRangeStrippingQuotes(context));
}
}
}
Also, we may need to inject into several fragments at once. For example, if we have this really bizarre XML-based DSL:
<myDSL>
<method>
<name>foo</name>
<body>System.out.println(42);</body>
</method>
</myDSL>
which should be converted to Java:
class MyDsl { void foo() { System.out.println(42);} }
Then we can inject Java into several places at once - method name and its body:
class MyBizarreDSLInjector implements MultiHostInjector {
void getLanguagesToInject(MultiHostRegistrar registrar, PsiElement context) {
if (isMethodTag(context)) {
registrar.startInjecting(JavaLanguage.INSTANCE);
// construct class header, method header, inject method name, append code block start
registrar.addPlace("class MyDsl { void ", "() {", context, rangeForMethodName(context));
// inject method body, append closing braces to form a valid Java class structure
registrar.addPlace(null, "}}", context, rangeForBody(context));
registrar.doneInjecting();
}
}
}
Now, then we look at this XML in the editor, "foo" will feel like a method name
and "System.out.println(42);" will look and feel like a method body - with highlighting, completion, goto definitions etc.