Refactoring: Extract registerWithElementsUnwrapped() function

This commit is contained in:
Alexey Sedunov
2016-05-12 21:10:43 +03:00
parent cb36b61f7f
commit 36f3d30250
3 changed files with 20 additions and 29 deletions
@@ -17,11 +17,9 @@
package org.jetbrains.kotlin.idea.inspections
import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInspection.CustomSuppressableInspectionTool
import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.SuppressIntentionAction
import com.intellij.codeInspection.SuppressManager
import com.intellij.codeInspection.*
import com.intellij.psi.PsiElement
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
@@ -64,3 +62,17 @@ private fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity
}
}
@Suppress("unused")
fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(holder: ProblemsHolder, isOnTheFly: Boolean) {
forEach {
@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
)
holder.registerProblem(descriptor)
}
}