mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
language_injection.md: fix code samples
This commit is contained in:
parent
3e3ef6319b
commit
91c28e8302
@ -234,7 +234,9 @@ public class MyRegExpToJavaInjector implements MultiHostInjector {
|
||||
if (context instanceof PsiLiteralExpression && shouldInject(context)) {
|
||||
registrar
|
||||
.startInjecting(RegExpLanguage.INSTANCE)
|
||||
.addPlace(null, null, context, innerRangeStrippingQuotes(context))
|
||||
.addPlace(null, null,
|
||||
(PsiLanguageInjectionHost)context,
|
||||
innerRangeStrippingQuotes(context))
|
||||
.doneInjecting();
|
||||
}
|
||||
}
|
||||
@ -279,13 +281,14 @@ public class MyBizarreDSLInjector implements MultiHostInjector {
|
||||
@Override
|
||||
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar,
|
||||
@NotNull PsiElement context) {
|
||||
if (isMethodTag(context)) {
|
||||
if (context instanceof XmlText && 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));
|
||||
(PsiLanguageInjectionHost)context,
|
||||
rangeForMethodName(context));
|
||||
|
||||
// inject method body, append closing braces
|
||||
// to form a valid Java class structure
|
||||
@ -293,6 +296,11 @@ public class MyBizarreDSLInjector implements MultiHostInjector {
|
||||
registrar.doneInjecting();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<? extends Class<? extends PsiElement>> elementsToInjectIn() {
|
||||
return List.of(XmlText.class);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user