From dd42335edb9458432ef540d8716e6a32adfa4dae Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Tue, 27 Jun 2023 12:19:36 +0200 Subject: [PATCH] WEB-53719 WEB-54398 Use multi-line LiteralTextEscaper for XML text injections GitOrigin-RevId: 17a5b776c71d1fbf7c79e41a5d6f910c641ea172 --- .../com/intellij/psi/LiteralTextEscaper.java | 7 +++++- .../lang/psi/SimpleMultiLineTextEscaper.kt | 24 ------------------- .../main/kotlin/org/toml/lang/psi/impl/Psi.kt | 4 ++-- .../psi/impl/source/xml/XmlTextImpl.java | 2 +- 4 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 plugins/toml/core/src/main/kotlin/org/toml/lang/psi/SimpleMultiLineTextEscaper.kt diff --git a/platform/core-api/src/com/intellij/psi/LiteralTextEscaper.java b/platform/core-api/src/com/intellij/psi/LiteralTextEscaper.java index 959cc0f45343..f6cf52c32270 100644 --- a/platform/core-api/src/com/intellij/psi/LiteralTextEscaper.java +++ b/platform/core-api/src/com/intellij/psi/LiteralTextEscaper.java @@ -73,6 +73,11 @@ public abstract class LiteralTextEscaper { @NotNull public static LiteralTextEscaper createSimple(@NotNull T element) { + return createSimple(element, true); + } + + @NotNull + public static LiteralTextEscaper createSimple(@NotNull T element, boolean isOneLine) { return new LiteralTextEscaper(element) { @Override public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) { @@ -87,7 +92,7 @@ public abstract class LiteralTextEscaper { @Override public boolean isOneLine() { - return true; + return isOneLine; } }; } diff --git a/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/SimpleMultiLineTextEscaper.kt b/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/SimpleMultiLineTextEscaper.kt deleted file mode 100644 index 07e4d95f41b9..000000000000 --- a/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/SimpleMultiLineTextEscaper.kt +++ /dev/null @@ -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(host: T) : LiteralTextEscaper(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 -} diff --git a/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt b/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt index 1d7ca6bb1f61..0db02b1e582a 100644 --- a/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt +++ b/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt @@ -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 { 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) { diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java index 016d29bdd427..27bd368b992e 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java @@ -457,7 +457,7 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText, PsiLanguageI @NotNull public LiteralTextEscaper createLiteralTextEscaper() { return getParentTag() instanceof HtmlTag ? - LiteralTextEscaper.createSimple(this) : + LiteralTextEscaper.createSimple(this, false) : new XmlTextLiteralEscaper(this); } }