diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/InspectionUtils.kt b/idea/tests/org/jetbrains/kotlin/idea/inspections/InspectionUtils.kt index bd468b3f97c..a21972a5f53 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/InspectionUtils.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/InspectionUtils.kt @@ -17,6 +17,8 @@ package org.jetbrains.kotlin.idea.inspections import com.intellij.analysis.AnalysisScope +import com.intellij.codeInspection.GlobalInspectionTool +import com.intellij.codeInspection.InspectionProfileEntry import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.ex.LocalInspectionToolWrapper import com.intellij.codeInspection.ui.InspectionToolPresentation @@ -50,9 +52,21 @@ fun runInspection( inspectionClass: Class<*>, project: Project, settings: Element? = null, files: List? = null, withTestDir: String? = null ): InspectionToolPresentation { - val inspection = inspectionClass.newInstance() as LocalInspectionTool + @Suppress("UNCHECKED_CAST") + val profileEntryClass = inspectionClass as Class + + val inspection = InspectionTestUtil.instantiateTools(listOf(profileEntryClass)).singleOrNull() + ?: error("Can't create `$inspectionClass` inspection") + if (settings != null) { inspection.readSettings(settings) } - return runInspection(inspection, project, files, withTestDir) + + val localInspection = when (inspection) { + is LocalInspectionTool -> inspection + is GlobalInspectionTool -> inspection.sharedLocalInspectionTool ?: error("Global inspection ${inspection::class} without local counterpart") + else -> error("Unknown class for inspection instance") + } + + return runInspection(localInspection, project, files, withTestDir) }