QuickFixTest: all inspections should be initialized from EP
This commit is contained in:
@@ -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<InspectionProfileEntry> {
|
||||
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<InspectionProfileEntry>
|
||||
} 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<InspectionProfileEntry>
|
||||
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<InspectionProfileEntry>
|
||||
return InspectionTestUtil.instantiateTools(listOf(inspectionClass))
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
return InspectionTestUtil.instantiateTools(profiles)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user