Correctness check for wrapper action's priority
This commit is contained in:
+6
-5
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
|
||||||
abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D : Any>(
|
abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D : Any>(
|
||||||
private val isLowPriority: Boolean = false
|
private val actionPriority: IntentionActionPriority = IntentionActionPriority.NORMAL
|
||||||
) : KotlinIntentionActionFactoryWithDelegate<E, D>() {
|
) : KotlinIntentionActionFactoryWithDelegate<E, D>() {
|
||||||
|
|
||||||
protected abstract fun createFix(data: D): IntentionAction?
|
protected abstract fun createFix(data: D): IntentionAction?
|
||||||
@@ -42,10 +42,11 @@ abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D
|
|||||||
return createFix(data)
|
return createFix(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
val delegateFactory = if (isLowPriority)
|
val delegateFactory = when (actionPriority) {
|
||||||
LowPriorityQuickFixWithDelegateFactory(::createAction)
|
IntentionActionPriority.NORMAL -> QuickFixWithDelegateFactory(::createAction)
|
||||||
else
|
IntentionActionPriority.HIGH -> HighPriorityQuickFixWithDelegateFactory(::createAction)
|
||||||
QuickFixWithDelegateFactory(::createAction)
|
IntentionActionPriority.LOW -> LowPriorityQuickFixWithDelegateFactory(::createAction)
|
||||||
|
}
|
||||||
return listOf(delegateFactory)
|
return listOf(delegateFactory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
@@ -49,10 +50,31 @@ public open class QuickFixWithDelegateFactory(
|
|||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
||||||
val action = delegateFactory() ?: return
|
val action = delegateFactory() ?: return
|
||||||
|
|
||||||
|
assert(action.detectPriority() == this.detectPriority()) {
|
||||||
|
"Incorrect priority of QuickFixWithDelegateFactory wrapper for ${action.javaClass.name}"
|
||||||
|
}
|
||||||
|
|
||||||
action.invoke(project, editor, file)
|
action.invoke(project, editor, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LowPriorityQuickFixWithDelegateFactory(
|
public class LowPriorityQuickFixWithDelegateFactory(
|
||||||
delegateFactory: () -> IntentionAction?
|
delegateFactory: () -> IntentionAction?
|
||||||
): QuickFixWithDelegateFactory(delegateFactory), LowPriorityAction
|
): QuickFixWithDelegateFactory(delegateFactory), LowPriorityAction
|
||||||
|
|
||||||
|
public class HighPriorityQuickFixWithDelegateFactory(
|
||||||
|
delegateFactory: () -> IntentionAction?
|
||||||
|
): QuickFixWithDelegateFactory(delegateFactory), HighPriorityAction
|
||||||
|
|
||||||
|
enum class IntentionActionPriority {
|
||||||
|
LOW, NORMAL, HIGH
|
||||||
|
}
|
||||||
|
|
||||||
|
fun IntentionAction.detectPriority(): IntentionActionPriority {
|
||||||
|
return when (this) {
|
||||||
|
is LowPriorityAction -> IntentionActionPriority.LOW
|
||||||
|
is HighPriorityAction -> IntentionActionPriority.HIGH
|
||||||
|
else -> IntentionActionPriority.NORMAL
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user