From eaa21f86c4c79c2319d26437bba9cc6778c130dc Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Mon, 23 Mar 2020 20:42:32 +0700 Subject: [PATCH] QuickFixTest: all inspections should be initialized from EP --- .../kotlin/idea/quickfix/QuickFixTest.kt | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt index 815d725b25f..9596891c776 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.idea.quickfix import com.intellij.codeInspection.InspectionProfileEntry -import com.intellij.codeInspection.LocalInspectionTool import com.intellij.openapi.util.io.FileUtil import com.intellij.testFramework.InspectionTestUtil import org.jetbrains.kotlin.idea.quickfix.utils.findInspectionFile @@ -16,24 +15,20 @@ import java.io.File interface QuickFixTest { fun parseInspectionsToEnable(beforeFileName: String, beforeFileText: String): List { val toolsStrings = InTextDirectivesUtils.findListWithPrefixes(beforeFileText, "TOOL:") - if (toolsStrings.isNotEmpty()) { - return toolsStrings.map { toolFqName -> - try { - val aClass = Class.forName(toolFqName) - return@map aClass.newInstance() as LocalInspectionTool - } catch (e: Exception) { - throw IllegalArgumentException("Failed to create inspection for key '$toolFqName'", e) - } + val profiles = try { + if (toolsStrings.isNotEmpty()) toolsStrings.map { toolFqName -> + @Suppress("UNCHECKED_CAST") + Class.forName(toolFqName) as Class + } else { + val inspectionFile = findInspectionFile(File(beforeFileName).parentFile) ?: return emptyList() + val className = FileUtil.loadFile(inspectionFile).trim { it <= ' ' } + @Suppress("UNCHECKED_CAST") val inspectionClass = Class.forName(className) as Class + listOf(inspectionClass) } + } catch (e: Exception) { + throw IllegalArgumentException("Failed to create inspections", e) } - val inspectionFile = findInspectionFile(File(beforeFileName).parentFile) - if (inspectionFile != null) { - val className = FileUtil.loadFile(inspectionFile).trim { it <= ' ' } - @Suppress("UNCHECKED_CAST") val inspectionClass = Class.forName(className) as Class - return InspectionTestUtil.instantiateTools(listOf(inspectionClass)) - } - - return emptyList() + return InspectionTestUtil.instantiateTools(profiles) } } \ No newline at end of file