Inspection: do not report anything with manual INFORMATION level offline

So #KT-20369 Fixed
So #KT-20333 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-10-05 17:29:07 +03:00
committed by Mikhail Glukhikh
parent ec64a7e422
commit e1ccd3afc5
5 changed files with 46 additions and 11 deletions
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.idea.inspections
import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInspection.*
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
@@ -45,6 +47,30 @@ abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSuppressab
}
protected open val suppressionKey: String get() = this.shortName.removePrefix("Kotlin")
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
element: PsiElement,
description: String,
isOnTheFly: Boolean,
highlightType: ProblemHighlightType,
vararg fixes: LocalQuickFix
) {
registerProblemWithoutOfflineInformation(element, description, isOnTheFly, highlightType, null, *fixes)
}
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
element: PsiElement,
description: String,
isOnTheFly: Boolean,
highlightType: ProblemHighlightType,
range: TextRange?,
vararg fixes: LocalQuickFix
) {
if (!ApplicationManager.getApplication().isUnitTestMode &&
!isOnTheFly && highlightType == ProblemHighlightType.INFORMATION) return
val problemDescriptor = manager.createProblemDescriptor(element, range, description, highlightType, isOnTheFly, *fixes)
registerProblem(problemDescriptor)
}
}
private fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
@@ -123,8 +123,14 @@ abstract class IntentionBasedInspection<TElement : PsiElement>(
val allFixes = fixes ?: SmartList<LocalQuickFix>()
additionalFixes(targetElement)?.let { allFixes.addAll(it) }
if (!allFixes.isEmpty()) {
holder.registerProblem(targetElement, problemText ?: allFixes.first().name,
problemHighlightType(targetElement), range, *allFixes.toTypedArray())
holder.registerProblemWithoutOfflineInformation(
targetElement,
problemText ?: allFixes.first().name,
isOnTheFly,
problemHighlightType(targetElement),
range,
*allFixes.toTypedArray()
)
}
}
}