From 1db775429865d0361a28a34d8edbd4b3c0d29445 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Tue, 23 Apr 2019 13:36:13 +0300 Subject: [PATCH] A workaround for the IDEA-211491 in IDEA 191 to make Kotlin tests pass for instance `InspectionTestGenerated$Inspections.testOverridingDeprecatedMember_inspectionData_Inspections_test` --- .../inspections/AbstractKotlinInspection.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt index c07a238621e..424504d1acc 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt @@ -20,10 +20,15 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel import com.intellij.codeInspection.* import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement +import com.intellij.psi.PsiNamedElement +import com.intellij.psi.util.parents import org.jetbrains.kotlin.asJava.unwrapped import org.jetbrains.kotlin.caches.resolve.KotlinCacheService import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.idea.highlighter.createSuppressWarningActions +import org.jetbrains.kotlin.psi.KtNamedDeclaration +import org.jetbrains.kotlin.psi.KtPropertyAccessor +import org.jetbrains.kotlin.psi.KtValVarKeywordOwner abstract class AbstractKotlinInspection : LocalInspectionTool(), CustomSuppressableInspectionTool { override fun getSuppressActions(element: PsiElement?): Array? { @@ -69,6 +74,21 @@ abstract class AbstractKotlinInspection : LocalInspectionTool(), CustomSuppressa val problemDescriptor = manager.createProblemDescriptor(element, range, description, highlightType, isOnTheFly, *fixes) registerProblem(problemDescriptor) } + + // a workaround for IDEA-211491 + override fun getProblemElement(psiElement: PsiElement): PsiNamedElement? { + val parent = psiElement.parents().firstOrNull { parent -> + when (parent) { + is KtPropertyAccessor -> true + is KtNamedDeclaration -> parent !is KtValVarKeywordOwner || parent.valOrVarKeyword != null + else -> false + } + } + if (parent is KtPropertyAccessor) { + return parent.property + } + return super.getProblemElement(psiElement) + } } fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {