package com.intellij.codeInspection.tests.kotlin import com.intellij.jvm.analysis.internal.testFramework.SuppressionAnnotationInspectionTestBase import com.intellij.jvm.analysis.testFramework.JvmLanguage import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin abstract class KotlinSuppressionAnnotationInspectionTest : SuppressionAnnotationInspectionTestBase(), ExpectedPluginModeProvider { override fun setUp() { setUpWithKotlinPlugin(testRootDisposable) { super.setUp() } } fun `test highlighting`() { inspection.myAllowedSuppressions.add("FreeSpeech") myFixture.testHighlighting( JvmLanguage.KOTLIN, """ @Suppress("ALL", "SuppressionAnnotation") class A { @Suppress("PublicField") var s: String? = null @Suppress var t: String? = null fun foo() { //noinspection HardCodedStringLiteral any("hello") // noinspection any() } @Suppress("FreeSpeech") fun bar() { // noinspection FreeSpeech any() } } private fun any(s: String? = null): String? = s """.trimIndent() ) } fun `test quickfix - remove annotation`() { myFixture.testQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress("PublicField", "HardCodedStringLiteral") var s: String = "test" } """.trimIndent(), """ class A { var s: String = "test" } """.trimIndent(), "Remove '@Suppress' annotation", testPreview = true) } fun `test quickfix - remove comment`() { myFixture.testQuickFix(JvmLanguage.KOTLIN, """ class A { //noinspection PublicField, HardCodedStringLiteral var s: String = "test" } """.trimIndent(), """ class A { var s: String = "test" } """.trimIndent(), "Remove //noinspection", testPreview = true) } fun `test quickfix - allow a single suppression from annotation`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress("PublicField") var s: String = "test" } """.trimIndent(), "PublicField") } fun `test quickfix - allow a single suppression from annotation when array form used`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress(["PublicField"]) var s: String = "test" } """.trimIndent(), "PublicField") } fun `test quickfix - allow a single suppression from annotation when explicit attribute name exists`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress(names = "PublicField") var s: String = "test" } """.trimIndent(), "PublicField") } fun `test quickfix - allow multiple suppressions from annotation`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress("PublicField", "HardCodedStringLiteral") var s: String = "test" } """.trimIndent(), "PublicField", "HardCodedStringLiteral") } fun `test quickfix - allow multiple suppressions from annotation when array form used`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress(["PublicField", "HardCodedStringLiteral"]) var s: String = "test" } """.trimIndent(), "PublicField", "HardCodedStringLiteral") } fun `test quickfix - allow multiple suppressions from annotation when explicit attribute name exists`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { @Suppress(names = ["PublicField", "HardCodedStringLiteral"]) var s: String = "test" } """.trimIndent(), "PublicField", "HardCodedStringLiteral") } fun `test quickfix - allow multiple suppressions from annotation when constants used`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ object Constants { const val PUBLIC_FIELD = "PublicField" const val HARD_CODED_STRING_LITERAL = "HardCodedStringLiteral" } class A { @Suppress([Constants.PUBLIC_FIELD, Constants.HARD_CODED_STRING_LITERAL]) var s: String = "test" } """.trimIndent(), "PublicField", "HardCodedStringLiteral") } fun `test quickfix - allow a single suppression from comment`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { //noinspection PublicField var s: String = "test" } """.trimIndent(), "PublicField") } fun `test quickfix - allow multiple suppressions from comment`() { testAllowSuppressionQuickFix(JvmLanguage.KOTLIN, """ class A { //noinspection PublicField, HardCodedStringLiteral var s: String = "test" } """.trimIndent(), "PublicField", "HardCodedStringLiteral") } }