From 33d94cd5e127ee618e74eadfa1f6763bb56b4973 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 19 Dec 2017 13:20:45 +0300 Subject: [PATCH] J2kPostProcessing: add inspection-based processing #KT-21635 Fixed --- .../kotlin/idea/j2k/J2kPostProcessings.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt index 407668c9428..32008a15ba5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt +++ b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.j2k +import com.intellij.codeInspection.ProblemHighlightType import com.intellij.psi.search.LocalSearchScope import com.intellij.psi.search.searches.ReferencesSearch import org.jetbrains.kotlin.builtins.KotlinBuiltIns @@ -169,6 +170,33 @@ object J2KPostProcessingRegistrar { }) } + private inline fun + > registerInspectionBasedProcessing( + + inspection: TInspection, + acceptInformationLevel: Boolean = false + ) { + _processings.add(object : J2kPostProcessing { + // Inspection can either need or not need write action + override val writeActionNeeded = inspection.startFixInWriteAction + + override fun createAction(element: KtElement, diagnostics: Diagnostics): (() -> Unit)? { + if (!TElement::class.java.isInstance(element)) return null + val tElement = element as TElement + if (!inspection.isApplicable(tElement)) return null + val highlightType = inspection.inspectionHighlightType(tElement) + if (!acceptInformationLevel && highlightType == ProblemHighlightType.INFORMATION) return null + return { + if (inspection.isApplicable(tElement)) { // check availability of the intention again because something could change + val apply = { inspection.applyTo(element) } + apply() + } + } + } + }) + } + private inline fun registerDiagnosticBasedProcessing( vararg diagnosticFactory: DiagnosticFactory<*>, crossinline fix: (TElement, Diagnostic) -> Unit