Reformat: AbstractKotlinInspection
This commit is contained in:
+19
-18
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.inspections
|
|||||||
|
|
||||||
import com.intellij.codeHighlighting.HighlightDisplayLevel
|
import com.intellij.codeHighlighting.HighlightDisplayLevel
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.asJava.unwrapped
|
import org.jetbrains.kotlin.asJava.unwrapped
|
||||||
@@ -26,7 +25,7 @@ import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
|||||||
import org.jetbrains.kotlin.diagnostics.Severity
|
import org.jetbrains.kotlin.diagnostics.Severity
|
||||||
import org.jetbrains.kotlin.idea.highlighter.createSuppressWarningActions
|
import org.jetbrains.kotlin.idea.highlighter.createSuppressWarningActions
|
||||||
|
|
||||||
abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSuppressableInspectionTool {
|
abstract class AbstractKotlinInspection : LocalInspectionTool(), CustomSuppressableInspectionTool {
|
||||||
override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
||||||
if (element == null) return emptyArray()
|
if (element == null) return emptyArray()
|
||||||
|
|
||||||
@@ -49,22 +48,22 @@ abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSuppressab
|
|||||||
protected open val suppressionKey: String get() = this.shortName.removePrefix("Kotlin")
|
protected open val suppressionKey: String get() = this.shortName.removePrefix("Kotlin")
|
||||||
|
|
||||||
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
|
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
|
||||||
element: PsiElement,
|
element: PsiElement,
|
||||||
description: String,
|
description: String,
|
||||||
isOnTheFly: Boolean,
|
isOnTheFly: Boolean,
|
||||||
highlightType: ProblemHighlightType,
|
highlightType: ProblemHighlightType,
|
||||||
vararg fixes: LocalQuickFix
|
vararg fixes: LocalQuickFix
|
||||||
) {
|
) {
|
||||||
registerProblemWithoutOfflineInformation(element, description, isOnTheFly, highlightType, null, *fixes)
|
registerProblemWithoutOfflineInformation(element, description, isOnTheFly, highlightType, null, *fixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
|
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
|
||||||
element: PsiElement,
|
element: PsiElement,
|
||||||
description: String,
|
description: String,
|
||||||
isOnTheFly: Boolean,
|
isOnTheFly: Boolean,
|
||||||
highlightType: ProblemHighlightType,
|
highlightType: ProblemHighlightType,
|
||||||
range: TextRange?,
|
range: TextRange?,
|
||||||
vararg fixes: LocalQuickFix
|
vararg fixes: LocalQuickFix
|
||||||
) {
|
) {
|
||||||
if (!isOnTheFly && highlightType == ProblemHighlightType.INFORMATION) return
|
if (!isOnTheFly && highlightType == ProblemHighlightType.INFORMATION) return
|
||||||
val problemDescriptor = manager.createProblemDescriptor(element, range, description, highlightType, isOnTheFly, *fixes)
|
val problemDescriptor = manager.createProblemDescriptor(element, range, description, highlightType, isOnTheFly, *fixes)
|
||||||
@@ -72,7 +71,7 @@ abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSuppressab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
||||||
return when (highlightDisplayLevel) {
|
return when (highlightDisplayLevel) {
|
||||||
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
||||||
|
|
||||||
@@ -89,9 +88,10 @@ fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
|||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(
|
fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(
|
||||||
holder: ProblemsHolder,
|
holder: ProblemsHolder,
|
||||||
isOnTheFly: Boolean,
|
isOnTheFly: Boolean,
|
||||||
quickFixSubstitutor: ((LocalQuickFix, PsiElement) -> LocalQuickFix?)? = null) {
|
quickFixSubstitutor: ((LocalQuickFix, PsiElement) -> LocalQuickFix?)? = null
|
||||||
|
) {
|
||||||
forEach { problem ->
|
forEach { problem ->
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val originalFixes = problem.fixes as? Array<LocalQuickFix> ?: LocalQuickFix.EMPTY_ARRAY
|
val originalFixes = problem.fixes as? Array<LocalQuickFix> ?: LocalQuickFix.EMPTY_ARRAY
|
||||||
@@ -99,7 +99,8 @@ fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(
|
|||||||
val newFixes = quickFixSubstitutor?.let { subst ->
|
val newFixes = quickFixSubstitutor?.let { subst ->
|
||||||
originalFixes.mapNotNull { subst(it, newElement) }.toTypedArray()
|
originalFixes.mapNotNull { subst(it, newElement) }.toTypedArray()
|
||||||
} ?: originalFixes
|
} ?: originalFixes
|
||||||
val descriptor = holder.manager.createProblemDescriptor(newElement, problem.descriptionTemplate, isOnTheFly, newFixes, problem.highlightType)
|
val descriptor =
|
||||||
|
holder.manager.createProblemDescriptor(newElement, problem.descriptionTemplate, isOnTheFly, newFixes, problem.highlightType)
|
||||||
holder.registerProblem(descriptor)
|
holder.registerProblem(descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user