KT-21770 Pasting into an interpolated string shouldn't escape $

This commit is contained in:
Toshiaki Kameyama
2017-12-15 11:24:30 +09:00
committed by Dmitry Jemerov
parent eb25ac44e6
commit a4fbe95112
5 changed files with 19 additions and 2 deletions
@@ -177,7 +177,8 @@ private class TemplateTokenSequence(private val inputString: String) : Sequence<
}
else if (this.length > 1 && this[0] == '$') {
val guessedIdentifier = substring(1)
KotlinLexer().apply { start(guessedIdentifier) }.tokenType == KtTokens.IDENTIFIER
val tokenType = KotlinLexer().apply { start(guessedIdentifier) }.tokenType
tokenType == KtTokens.IDENTIFIER || tokenType == KtTokens.THIS_KEYWORD
}
else {
false
@@ -190,7 +191,8 @@ private class TemplateTokenSequence(private val inputString: String) : Sequence<
when (lexer.tokenType) {
KtTokens.SHORT_TEMPLATE_ENTRY_START -> {
lexer.advance()
return if (lexer.tokenType == KtTokens.IDENTIFIER) {
val tokenType = lexer.tokenType
return if (tokenType == KtTokens.IDENTIFIER || tokenType == KtTokens.THIS_KEYWORD) {
from + lexer.tokenEnd - 1
}
else {
@@ -0,0 +1,3 @@
class Bar() {
val a = "begin This is $this end"
}
+3
View File
@@ -0,0 +1,3 @@
class Foo() {
val a = "<selection>This is $this</selection>"
}
+3
View File
@@ -0,0 +1,3 @@
class Bar() {
val a = "begin <caret> end"
}
@@ -54,6 +54,12 @@ public class LiteralKotlinToKotlinCopyPasteTestGenerated extends AbstractLiteral
doTest(fileName);
}
@TestMetadata("DontEscapeThis.kt")
public void testDontEscapeThis() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/literal/DontEscapeThis.kt");
doTest(fileName);
}
@TestMetadata("DontUnescapeLiteralWIthCode.kt")
public void testDontUnescapeLiteralWIthCode() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/literal/DontUnescapeLiteralWIthCode.kt");