Inspection for highlighting problem API usage
It's planned to use this inspection for show patchset branches problems during development process.
This commit is contained in:
committed by
Nikolay Krasko
parent
a95ec598f2
commit
3ef67e1d9d
@@ -21,6 +21,8 @@ import com.intellij.openapi.command.CommandProcessor
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.testFramework.TestLoggerFactory
|
||||
import org.jdom.Document
|
||||
import org.jdom.input.SAXBuilder
|
||||
import org.jetbrains.kotlin.idea.inspections.runInspection
|
||||
import org.jetbrains.kotlin.idea.test.*
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
@@ -66,6 +68,13 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
val inspectionsTestDir = optionsFile.parentFile!!
|
||||
val srcDir = inspectionsTestDir.parentFile!!
|
||||
|
||||
val settingsFile = File(inspectionsTestDir, "settings.xml")
|
||||
val settingsElement = if (settingsFile.exists()) {
|
||||
(SAXBuilder().build(settingsFile) as Document).rootElement
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
with(myFixture) {
|
||||
testDataPath = "${KotlinTestUtils.getHomeDirectory()}/$srcDir"
|
||||
|
||||
@@ -110,7 +119,9 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
configExtra(psiFiles, options)
|
||||
|
||||
val presentation = runInspection(
|
||||
inspectionClass, project, files = psiFiles.map { it.virtualFile!! }, withTestDir = inspectionsTestDir.path
|
||||
inspectionClass, project,
|
||||
settings = settingsElement,
|
||||
files = psiFiles.map { it.virtualFile!! }, withTestDir = inspectionsTestDir.path
|
||||
)
|
||||
|
||||
if (afterFiles.isNotEmpty()) {
|
||||
|
||||
+5
@@ -174,6 +174,11 @@ public class InspectionTestGenerated extends AbstractInspectionTest {
|
||||
runTest("idea/testData/inspections/hasPlatformType/inspectionData/inspections.test");
|
||||
}
|
||||
|
||||
@TestMetadata("incompatibleAPI/inspectionData/inspections.test")
|
||||
public void testIncompatibleAPI_inspectionData_Inspections_test() throws Exception {
|
||||
runTest("idea/testData/inspections/incompatibleAPI/inspectionData/inspections.test");
|
||||
}
|
||||
|
||||
@TestMetadata("javaCollectionsStaticMethodOnImmutableList/inspectionData/inspections.test")
|
||||
public void testJavaCollectionsStaticMethodOnImmutableList_inspectionData_Inspections_test() throws Exception {
|
||||
runTest("idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/inspections.test");
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.InspectionTestUtil
|
||||
import com.intellij.testFramework.createGlobalContextForTool
|
||||
import org.jdom.Element
|
||||
|
||||
fun runInspection(
|
||||
inspection: LocalInspectionTool, project: Project, files: List<VirtualFile>? = null, withTestDir: String? = null
|
||||
@@ -46,8 +47,12 @@ fun runInspection(
|
||||
}
|
||||
|
||||
fun runInspection(
|
||||
inspectionClass: Class<*>, project: Project, files: List<VirtualFile>? = null, withTestDir: String? = null
|
||||
inspectionClass: Class<*>, project: Project,
|
||||
settings: Element? = null, files: List<VirtualFile>? = null, withTestDir: String? = null
|
||||
): InspectionToolPresentation {
|
||||
val inspection = inspectionClass.newInstance() as LocalInspectionTool
|
||||
if (settings != null) {
|
||||
inspection.readSettings(settings)
|
||||
}
|
||||
return runInspection(inspection, project, files, withTestDir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user