"Indent raw string" intention: do not suggest in const

#KT-34784 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-11-07 17:30:19 +09:00
committed by Mikhail Glukhikh
parent 688a2185fa
commit 39db76b2ab
4 changed files with 28 additions and 0 deletions
@@ -8,9 +8,13 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.application.options.CodeStyle
import com.intellij.openapi.editor.Editor
import com.intellij.psi.codeStyle.CodeStyleManager
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForReceiver
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class IndentRawStringIntention : SelfTargetingIntention<KtStringTemplateExpression>(
@@ -19,6 +23,7 @@ class IndentRawStringIntention : SelfTargetingIntention<KtStringTemplateExpressi
override fun isApplicableTo(element: KtStringTemplateExpression, caretOffset: Int): Boolean {
if (!element.text.startsWith("\"\"\"")) return false
if (element.parents.any { it is KtAnnotationEntry || (it as? KtProperty)?.hasModifier(KtTokens.CONST_KEYWORD) == true }) return false
if (element.getQualifiedExpressionForReceiver() != null) return false
val entries = element.entries
if (entries.size <= 1 || entries.any { it.text.startsWith(" ") || it.text.startsWith("\t") }) return false
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
@Ann("""foo
bar
baz"""<caret>)
class Test
annotation class Ann(val s: String)
+6
View File
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
object Test {
const val foo = <caret>"""foo
bar
baz"""
}
@@ -8712,6 +8712,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/indentRawString"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), true);
}
@TestMetadata("annotationEntry.kt")
public void testAnnotationEntry() throws Exception {
runTest("idea/testData/intentions/indentRawString/annotationEntry.kt");
}
@TestMetadata("const.kt")
public void testConst() throws Exception {
runTest("idea/testData/intentions/indentRawString/const.kt");
}
@TestMetadata("hasIndent.kt")
public void testHasIndent() throws Exception {
runTest("idea/testData/intentions/indentRawString/hasIndent.kt");