mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-53719 WEB-54398 Use multi-line LiteralTextEscaper for XML text injections
GitOrigin-RevId: 17a5b776c71d1fbf7c79e41a5d6f910c641ea172
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3dc603bc98
commit
dd42335edb
@@ -73,6 +73,11 @@ public abstract class LiteralTextEscaper<T extends PsiLanguageInjectionHost> {
|
||||
|
||||
@NotNull
|
||||
public static <T extends PsiLanguageInjectionHost> LiteralTextEscaper<T> createSimple(@NotNull T element) {
|
||||
return createSimple(element, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends PsiLanguageInjectionHost> LiteralTextEscaper<T> createSimple(@NotNull T element, boolean isOneLine) {
|
||||
return new LiteralTextEscaper<T>(element) {
|
||||
@Override
|
||||
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
|
||||
@@ -87,7 +92,7 @@ public abstract class LiteralTextEscaper<T extends PsiLanguageInjectionHost> {
|
||||
|
||||
@Override
|
||||
public boolean isOneLine() {
|
||||
return true;
|
||||
return isOneLine;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Use of this source code is governed by the MIT license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.toml.lang.psi
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.LiteralTextEscaper
|
||||
import com.intellij.psi.PsiLanguageInjectionHost
|
||||
|
||||
/** Same as [com.intellij.psi.LiteralTextEscaper.createSimple], but multi line */
|
||||
class SimpleMultiLineTextEscaper<T: PsiLanguageInjectionHost>(host: T) : LiteralTextEscaper<T>(host) {
|
||||
override fun decode(rangeInsideHost: TextRange, outChars: java.lang.StringBuilder): Boolean {
|
||||
outChars.append(rangeInsideHost.substring(myHost.text))
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getOffsetInHost(offsetInDecoded: Int, rangeInsideHost: TextRange): Int {
|
||||
return rangeInsideHost.startOffset + offsetInDecoded
|
||||
}
|
||||
|
||||
override fun isOneLine(): Boolean = false
|
||||
}
|
||||
@@ -7,7 +7,6 @@ package org.toml.lang.psi.impl
|
||||
|
||||
import com.intellij.ide.projectView.PresentationData
|
||||
import com.intellij.lang.ASTFactory
|
||||
import org.toml.lang.psi.SimpleMultiLineTextEscaper
|
||||
import com.intellij.navigation.ItemPresentation
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry
|
||||
@@ -91,7 +90,8 @@ class TomlLiteralImpl(type: IElementType) : CompositePsiElement(type), TomlLiter
|
||||
|
||||
override fun createLiteralTextEscaper(): LiteralTextEscaper<out PsiLanguageInjectionHost> {
|
||||
val tokenType = node.findChildByType(TOML_STRING_LITERALS)?.elementType ?: error("$text is not string literal")
|
||||
return if (tokenType in TOML_BASIC_STRINGS) TomlLiteralTextEscaper(this) else SimpleMultiLineTextEscaper(this)
|
||||
return if (tokenType in TOML_BASIC_STRINGS) TomlLiteralTextEscaper(this)
|
||||
else LiteralTextEscaper.createSimple(this, false)
|
||||
}
|
||||
|
||||
override fun accept(visitor: PsiElementVisitor) {
|
||||
|
||||
@@ -457,7 +457,7 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText, PsiLanguageI
|
||||
@NotNull
|
||||
public LiteralTextEscaper<XmlTextImpl> createLiteralTextEscaper() {
|
||||
return getParentTag() instanceof HtmlTag ?
|
||||
LiteralTextEscaper.createSimple(this) :
|
||||
LiteralTextEscaper.createSimple(this, false) :
|
||||
new XmlTextLiteralEscaper(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user