Inspection: do not report anything with manual INFORMATION level offline
So #KT-20369 Fixed So #KT-20333 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
ec64a7e422
commit
e1ccd3afc5
+26
@@ -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 {
|
||||
|
||||
+8
-2
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,10 @@ class LiftReturnOrAssignmentInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
val assignmentNumber = BranchedFoldingUtils.getFoldableAssignmentNumber(expression)
|
||||
if (assignmentNumber > 0) {
|
||||
holder.registerProblem(
|
||||
holder.registerProblemWithoutOfflineInformation(
|
||||
keyword,
|
||||
"Assignment can be lifted out of '${keyword.text}'",
|
||||
isOnTheFly,
|
||||
if (assignmentNumber > 1) ProblemHighlightType.GENERIC_ERROR_OR_WARNING
|
||||
else ProblemHighlightType.INFORMATION,
|
||||
LiftAssignmentOutFix(keyword.text)
|
||||
|
||||
@@ -55,10 +55,13 @@ class NullableBooleanElvisInspection : AbstractKotlinInspection(), CleanupLocalI
|
||||
else
|
||||
INFORMATION to "can"
|
||||
|
||||
holder.registerProblem(expression,
|
||||
"Equality check $verb be used instead of elvis for nullable boolean check",
|
||||
highlightType,
|
||||
ReplaceWithEqualityCheckFix())
|
||||
holder.registerProblemWithoutOfflineInformation(
|
||||
expression,
|
||||
"Equality check $verb be used instead of elvis for nullable boolean check",
|
||||
isOnTheFly,
|
||||
highlightType,
|
||||
ReplaceWithEqualityCheckFix()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,14 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs
|
||||
declaration as? KtDeclarationWithBody ?: return
|
||||
val (toHighlight, suffix, highlightType) = statusFor(declaration) ?: return
|
||||
|
||||
val problemDescriptor = holder.manager.createProblemDescriptor(
|
||||
holder.registerProblemWithoutOfflineInformation(
|
||||
declaration,
|
||||
toHighlight?.textRange?.shiftRight(-declaration.startOffset),
|
||||
"Use expression body instead of $suffix",
|
||||
highlightType,
|
||||
isOnTheFly,
|
||||
highlightType,
|
||||
toHighlight?.textRange?.shiftRight(-declaration.startOffset),
|
||||
ConvertToExpressionBodyFix()
|
||||
)
|
||||
holder.registerProblem(problemDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user