程序包 com.intellij.psi

接口 PsiLanguageInjectionHost

所有超级接口:
PsiElement, PsiExternalReferenceHost

public interface PsiLanguageInjectionHost extends PsiExternalReferenceHost
Marks PSI element as (potentially) containing text in another language. Injected language PSI does not embed into the PSI tree of the hosting element, but is used by the IDE for highlighting, completion and other code insight actions.

In order to do the injection, you have to

  • Implement fleet.com.intellij.psi.LanguageInjector to describe exact place where injection should occur.
  • Register injection in fleet.com.intellij.psi.LanguageInjector#EXTENSION_POINT_NAME extension point.
Currently, language can be injected into string literals, XML tag contents and XML attributes.

You don't have to implement PsiLanguageInjectionHost by yourself, unless you want to inject something into your own custom PSI. For all returned injected PSI elements, InjectedLanguageManager#getInjectionHost(PsiElement) returns PsiLanguageInjectionHost they were injected into.

  • 方法详细资料

    • isValidHost

      boolean isValidHost()
      返回:
      true if this instance can accept injections, false otherwise
    • updateText

      PsiLanguageInjectionHost updateText(@NotNull @NotNull String text)
      Update the host element using the provided text of the injected file. It may be required to escape characters from text in accordance with the host language syntax. The implementation may delegate to ElementManipulators#handleContentChange(PsiElement, String) if ElementManipulator implementation is registered for this element class.
      参数:
      text - text of the injected file
      返回:
      the updated instance
    • createLiteralTextEscaper

      @NotNull @NotNull LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper()
      返回:
      LiteralTextEscaper instance which will be used to convert the content of this host element to the content of injected file