Do special insert even for custom trimIndent() function to avoid using resolve (KT-31810)
This commit is contained in:
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.idea.inspections.collections.isCalling
|
|||||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||||
import org.jetbrains.kotlin.lexer.KotlinLexer
|
import org.jetbrains.kotlin.lexer.KotlinLexer
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.psi.KtEscapeStringTemplateEntry
|
import org.jetbrains.kotlin.psi.KtEscapeStringTemplateEntry
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||||
@@ -151,13 +150,15 @@ class KotlinLiteralCopyPasteProcessor : CopyPastePreProcessor {
|
|||||||
res.toString()
|
res.toString()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val indent = if (beginTp.firstChild?.text == "\"\"\"" &&
|
val indent =
|
||||||
beginTp.getQualifiedExpressionForReceiver()?.callExpression?.isCalling(FqName("kotlin.text.trimIndent")) == true
|
if (beginTp.firstChild?.text == "\"\"\"" &&
|
||||||
) {
|
beginTp.getQualifiedExpressionForReceiver()?.callExpression?.calleeExpression?.text == "trimIndent"
|
||||||
begin.parent?.prevSibling?.takeIf { it.text != "\n" }?.text ?: ""
|
) {
|
||||||
} else {
|
begin.parent?.prevSibling?.takeIf { it.text != "\n" }?.text
|
||||||
""
|
} else {
|
||||||
}
|
null
|
||||||
|
} ?: ""
|
||||||
|
|
||||||
val tripleQuoteRe = Regex("[\"]{3,}")
|
val tripleQuoteRe = Regex("[\"]{3,}")
|
||||||
TemplateTokenSequence(text).mapIndexed { index, chunk ->
|
TemplateTokenSequence(text).mapIndexed { index, chunk ->
|
||||||
when (chunk) {
|
when (chunk) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fun String.trimIndent() = this
|
||||||
|
|
||||||
|
fun test() = doTest("""
|
||||||
|
def foo(a)
|
||||||
|
a ? 0 : 1
|
||||||
|
end
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
fun doTest(rubyCode: String) {
|
||||||
|
// some code here
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun String.trimIndent() = this
|
||||||
|
|
||||||
|
fun test() = doTest("""
|
||||||
|
<caret>
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
fun doTest(rubyCode: String) {
|
||||||
|
// some code here
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
def foo(a)
|
||||||
|
a ? 0 : 1
|
||||||
|
end
|
||||||
Generated
+5
@@ -34,6 +34,11 @@ public class LiteralTextToKotlinCopyPasteTestGenerated extends AbstractLiteralTe
|
|||||||
runTest("idea/testData/copyPaste/plainTextLiteral/BrokenEntries.txt");
|
runTest("idea/testData/copyPaste/plainTextLiteral/BrokenEntries.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("CustomTrimIndent.txt")
|
||||||
|
public void testCustomTrimIndent() throws Exception {
|
||||||
|
runTest("idea/testData/copyPaste/plainTextLiteral/CustomTrimIndent.txt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("MultiLine.txt")
|
@TestMetadata("MultiLine.txt")
|
||||||
public void testMultiLine() throws Exception {
|
public void testMultiLine() throws Exception {
|
||||||
runTest("idea/testData/copyPaste/plainTextLiteral/MultiLine.txt");
|
runTest("idea/testData/copyPaste/plainTextLiteral/MultiLine.txt");
|
||||||
|
|||||||
Reference in New Issue
Block a user