KT-18538 Fix inspection to detect unnecessary grand-base class qualifier
- Add separate option to enable/disable this inspection, as it is not obvious if it should be always enabled or not - This option can be used to detect all unnecessary qualifiers in tests - Add possibility to configure inspections via `settings.xml` in the `AbstractMultiFileLocalInspectionTest.kt` - ^KT-18538 Fixed
This commit is contained in:
@@ -17,6 +17,7 @@ import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
|
||||
import junit.framework.ComparisonFailure
|
||||
import junit.framework.TestCase
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
@@ -128,7 +129,8 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
|
||||
inspection: AbstractKotlinInspection,
|
||||
expectedProblemString: String?,
|
||||
expectedHighlightString: String?,
|
||||
localFixTextString: String?
|
||||
localFixTextString: String?,
|
||||
inspectionSettings: Element? = null
|
||||
): Boolean {
|
||||
val problemExpected = expectedProblemString == null || expectedProblemString != "none"
|
||||
myFixture.enableInspections(inspection::class.java)
|
||||
@@ -139,6 +141,10 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
|
||||
val state = inspectionProfile.getToolDefaultState(inspection.shortName, project)
|
||||
state.level = HighlightDisplayLevel.WARNING
|
||||
|
||||
if (inspectionSettings != null) {
|
||||
state.tool.tool.readSettings(inspectionSettings)
|
||||
}
|
||||
|
||||
val caretOffset = myFixture.caretOffset
|
||||
val highlightInfos = CodeInsightTestFixtureImpl.instantiateAndRun(
|
||||
file, editor, intArrayOf(
|
||||
|
||||
+8
-1
@@ -16,6 +16,8 @@ import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import junit.framework.TestCase
|
||||
import org.jdom.Document
|
||||
import org.jdom.input.SAXBuilder
|
||||
import org.jetbrains.kotlin.idea.jsonUtils.getString
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
@@ -47,10 +49,15 @@ abstract class AbstractMultiFileLocalInspectionTest : AbstractLocalInspectionTes
|
||||
val problemExpectedString = config["problem"]?.asString // null means "some problem", "none" means no problem
|
||||
val localFixTextString = config["fix"]?.asString // null means "some single fix" or "none" if no problem expected
|
||||
|
||||
val inspectionSettings = File(testFile.parentFile, "settings.xml")
|
||||
.takeIf { it.exists() }
|
||||
?.let { (SAXBuilder().build(it) as Document).rootElement }
|
||||
|
||||
|
||||
doTest(path) test@{ _ ->
|
||||
myFixture.configureFromTempProjectFile(mainFilePath)
|
||||
|
||||
runInspectionWithFixesAndCheck(inspection, problemExpectedString, null, localFixTextString)
|
||||
runInspectionWithFixesAndCheck(inspection, problemExpectedString, null, localFixTextString, inspectionSettings)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
+15
@@ -98,6 +98,21 @@ public class MultiFileLocalInspectionTestGenerated extends AbstractMultiFileLoca
|
||||
runTest("idea/testData/multiFileLocalInspections/redundantQualifierName/javaStatic/fromKotlinTest.test");
|
||||
}
|
||||
|
||||
@TestMetadata("redundantQualifierName/unnecessaryNonDirectParentClassQualifier/fromKotlinTest.test")
|
||||
public void testRedundantQualifierName_unnecessaryNonDirectParentClassQualifier_FromKotlinTest() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/redundantQualifierName/unnecessaryNonDirectParentClassQualifier/fromKotlinTest.test");
|
||||
}
|
||||
|
||||
@TestMetadata("redundantQualifierName/unnecessaryNonDirectParentClassQualifierAmbiguous/fromKotlinTest.test")
|
||||
public void testRedundantQualifierName_unnecessaryNonDirectParentClassQualifierAmbiguous_FromKotlinTest() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/redundantQualifierName/unnecessaryNonDirectParentClassQualifierAmbiguous/fromKotlinTest.test");
|
||||
}
|
||||
|
||||
@TestMetadata("redundantQualifierName/unnecessaryNonDirectParentClassQualifierDisabled/fromKotlinTest.test")
|
||||
public void testRedundantQualifierName_unnecessaryNonDirectParentClassQualifierDisabled_FromKotlinTest() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/redundantQualifierName/unnecessaryNonDirectParentClassQualifierDisabled/fromKotlinTest.test");
|
||||
}
|
||||
|
||||
@TestMetadata("unusedSymbol/fromKotlinTest/fromKotlinTest.test")
|
||||
public void testUnusedSymbol_fromKotlinTest_FromKotlinTest() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/unusedSymbol/fromKotlinTest/fromKotlinTest.test");
|
||||
|
||||
Reference in New Issue
Block a user