Spring Support: Implement Spring @Autowired inspection
#KT-12278 Fixed #KT-12147 Fixed #KT-12366 Fixed #KT-12122 Fixed
This commit is contained in:
+11
-9
@@ -63,16 +63,18 @@ private fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(holder: ProblemsHolder, isOnTheFly: Boolean) {
|
||||
forEach {
|
||||
fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(
|
||||
holder: ProblemsHolder,
|
||||
isOnTheFly: Boolean,
|
||||
quickFixSubstitutor: ((LocalQuickFix, PsiElement) -> LocalQuickFix?)? = null) {
|
||||
forEach { problem ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val descriptor = holder.manager.createProblemDescriptor(
|
||||
it.psiElement.unwrapped ?: it.psiElement,
|
||||
it.descriptionTemplate,
|
||||
isOnTheFly,
|
||||
it.fixes as? Array<LocalQuickFix> ?: LocalQuickFix.EMPTY_ARRAY,
|
||||
it.highlightType
|
||||
)
|
||||
val originalFixes = problem.fixes as? Array<LocalQuickFix> ?: LocalQuickFix.EMPTY_ARRAY
|
||||
val newElement = problem.psiElement.unwrapped ?: return@forEach
|
||||
val newFixes = quickFixSubstitutor?.let { subst ->
|
||||
originalFixes.mapNotNull { subst(it, newElement) }.toTypedArray()
|
||||
} ?: originalFixes
|
||||
val descriptor = holder.manager.createProblemDescriptor(newElement, problem.descriptionTemplate, isOnTheFly, newFixes, problem.highlightType)
|
||||
holder.registerProblem(descriptor)
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.ex.InspectionManagerEx
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.InspectionTestUtil
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
@@ -51,6 +52,10 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
protected open fun configExtra(psiFiles: List<PsiFile>, options: String) {
|
||||
|
||||
}
|
||||
|
||||
protected fun doTest(path: String) {
|
||||
val optionsFile = File(path)
|
||||
val options = FileUtil.loadFile(optionsFile, true)
|
||||
@@ -110,6 +115,8 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
|
||||
fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, myFixture.module) }
|
||||
|
||||
configExtra(psiFiles, options)
|
||||
|
||||
val scope = AnalysisScope(project, psiFiles.map { it.virtualFile!! })
|
||||
scope.invalidate()
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase {
|
||||
}), LocalInspectionTool.class);
|
||||
}
|
||||
|
||||
protected void configExtra(String options) {
|
||||
|
||||
}
|
||||
|
||||
private void doKotlinQuickFixTest(final String testName, final QuickFixTestCase quickFixTestCase) {
|
||||
String relativePath = notNull(quickFixTestCase.getBasePath(), "") + "/" + StringsKt.decapitalize(testName);
|
||||
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
|
||||
@@ -150,6 +154,8 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase {
|
||||
|
||||
checkForUnexpectedActions();
|
||||
|
||||
configExtra(fileText);
|
||||
|
||||
applyAction(contents, quickFixTestCase, testName, testFullPath);
|
||||
|
||||
assertEmpty(expectedErrorMessage);
|
||||
|
||||
Reference in New Issue
Block a user