Multiline string enter handler: do not insert 'trimIndent()' in const (KT-34785)

#KT-34785 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-11-07 17:55:38 +09:00
committed by Nikolay Krasko
parent ce0fb662c0
commit 58fb1dede3
3 changed files with 15 additions and 1 deletions
@@ -358,7 +358,7 @@ class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter() {
fun insertTrimCall(document: Document, literal: KtStringTemplateExpression, marginChar: Char?) {
if (hasTrimIndentCallInChain(literal) || getMarginCharFromTrimMarginCallsInChain(literal) != null) return
if (literal.parents.any { it is KtAnnotationEntry }) return
if (literal.parents.any { it is KtAnnotationEntry || (it as? KtProperty)?.hasModifier(KtTokens.CONST_KEYWORD) == true }) return
if (marginChar == null) {
document.insertString(literal.textRange.endOffset, ".$TRIM_INDENT_CALL()")
@@ -0,0 +1,9 @@
object O {
const val s = """<caret>"""
}
//-----
object O {
const val s = """
<caret>
"""
}
@@ -220,6 +220,11 @@ public class MultiLineStringIndentTestGenerated extends AbstractMultiLineStringI
runTest("idea/testData/editor/enterHandler/multilineString/spaces/noTrimIndentInAnnotations.kt");
}
@TestMetadata("noTrimIndentInConst.kt")
public void testNoTrimIndentInConst() throws Exception {
runTest("idea/testData/editor/enterHandler/multilineString/spaces/noTrimIndentInConst.kt");
}
@TestMetadata("restoreIndentFromEmptyLine.kt")
public void testRestoreIndentFromEmptyLine() throws Exception {
runTest("idea/testData/editor/enterHandler/multilineString/spaces/restoreIndentFromEmptyLine.kt");