Class LiteralTextEscaper<T extends PsiLanguageInjectionHost>

java.lang.Object
com.intellij.psi.LiteralTextEscaper<T>

public abstract class LiteralTextEscaper<T extends PsiLanguageInjectionHost> extends Object
  • Field Details

  • Constructor Details

    • LiteralTextEscaper

      protected LiteralTextEscaper(@NotNull T host)
  • Method Details

    • decode

      public abstract boolean decode(@NotNull @NotNull com.intellij.openapi.util.TextRange rangeInsideHost, @NotNull @NotNull StringBuilder outChars)
      Add decoded and unescaped characters from the host element to outChars buffer. If it's impossible to properly decode some chars from the specified range (e.g. if the range starts or ends inside escaped sequence), decode the longest acceptable prefix of the range and return false
      Parameters:
      rangeInsideHost - range to be decoded. It's guarantied to be inside getRelevantTextRange()
      outChars - buffer for output chars. Use append methods only, it's forbidden to modify or remove existing characters
      Returns:
      true if whole range was successfully decoded, false otherwise
    • getOffsetInHost

      public abstract int getOffsetInHost(int offsetInDecoded, @NotNull @NotNull com.intellij.openapi.util.TextRange rangeInsideHost)
      This method is called only after decode(com.intellij.openapi.util.TextRange, java.lang.StringBuilder), so it's possible to prepare necessary data in decode(com.intellij.openapi.util.TextRange, java.lang.StringBuilder) and then use it here.
      Parameters:
      offsetInDecoded - offset in the parsed injected file
      rangeInsideHost - range where injection is performed, E.g. if some language fragment xyz was injected into string literal expression "xyz", then rangeInsideHost = (1,4)
      Returns:
      offset in the host PSI element, or -1 if offset is out of host range. E.g. if some language fragment xyz was injected into string literal expression "xyz", then getOffsetInHost(0)==1 (there is an 'x' at offset 0 in the injected fragment, and that 'x' occurs in "xyz" string literal at offset 1 since string literal expression "xyz" starts with double quote) getOffsetInHost(1)==2 getOffsetInHost(2)==3 getOffsetInHost(3)==-1 (out of range)

      Similarly, for some language fragment xyz being injected into xml text inside xml tag 'tag': xyz getOffsetInHost(0)==0 (there is an 'x' at offset 0 in injected fragment, and that 'x' occurs in xyz xml text at offset 0) getOffsetInHost(1)==1 getOffsetInHost(2)==2 getOffsetInHost(3)==-1 (out of range)

    • getRelevantTextRange

      @NotNull public @NotNull com.intellij.openapi.util.TextRange getRelevantTextRange()
      Returns:
      range inside the host where injection can be performed; usually it's range of text without boundary quotes
    • isOneLine

      public abstract boolean isOneLine()
      Returns:
      true if the host cannot accept multiline content, false otherwise
    • createSimple

      @NotNull public static <T extends PsiLanguageInjectionHost> @NotNull LiteralTextEscaper<T> createSimple(@NotNull T element)