From cd6dbd2515ae635ca4dc0321b47e06e328517fd5 Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Thu, 10 Jun 2021 07:11:46 +0000 Subject: [PATCH] FIR IDE: Assert that the action to invoke in AbstractHighLevelQuickFixTest is of type QuickFixActionBase. --- .../quickfix/AbstractHighLevelQuickFixTest.kt | 4 ++++ .../addPropertyAccessors/varHasGetter.kt | 3 ++- .../addPropertyAccessors/varHasGetter.kt.after | 3 ++- .../addPropertyAccessors/varHasSetter.kt | 3 ++- .../addPropertyAccessors/varHasSetter.kt.after | 3 ++- .../kotlin/idea/quickfix/AbstractQuickFixTest.kt | 16 +++++++++++++--- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt index 7b9fa3b9ef4..ee39bac98aa 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt @@ -45,6 +45,10 @@ abstract class AbstractHighLevelQuickFixTest : AbstractQuickFixTest() { } } + override val shouldCheckIntentionActionType: Boolean + // All quickfixes from the FIR plugin are guaranteed to be of type QuickFixActionBase (see HLDiagnosticFixFactory) + get() = true + // TODO: Enable these as more actions/inspections are enabled, and/or add more FIR-specific directives override fun checkForUnexpectedErrors() {} override fun checkAvailableActionsAreExpected(actions: List) {} diff --git a/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt b/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt index ead42a039e3..23c9f8c080f 100644 --- a/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt +++ b/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt @@ -4,4 +4,5 @@ class Test { get() { return 1 } -} \ No newline at end of file +} +/* IGNORE_FIR */ \ No newline at end of file diff --git a/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt.after b/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt.after index 8153f5e1411..b0171ce9c96 100644 --- a/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt.after +++ b/idea/testData/quickfix/addPropertyAccessors/varHasGetter.kt.after @@ -5,4 +5,5 @@ class Test { return 1 } set(value) {} -} \ No newline at end of file +} +/* IGNORE_FIR */ \ No newline at end of file diff --git a/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt b/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt index 1b4835daa07..411de17a597 100644 --- a/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt +++ b/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt @@ -3,4 +3,5 @@ class Test { var x: Int set(value) {} -} \ No newline at end of file +} +/* IGNORE_FIR */ \ No newline at end of file diff --git a/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt.after b/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt.after index bfc6afd8468..df74bb2924b 100644 --- a/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt.after +++ b/idea/testData/quickfix/addPropertyAccessors/varHasSetter.kt.after @@ -6,4 +6,5 @@ class Test { TODO() } set(value) {} -} \ No newline at end of file +} +/* IGNORE_FIR */ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt index 36af4c5e119..65522987f15 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt @@ -20,7 +20,6 @@ import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.UsefulTestCase import com.intellij.util.ui.UIUtil import junit.framework.TestCase -import org.jetbrains.annotations.NotNull import org.jetbrains.kotlin.idea.caches.resolve.ResolveInDispatchThreadException import org.jetbrains.kotlin.idea.caches.resolve.forceCheckForResolveInDispatchThreadInTests import org.jetbrains.kotlin.idea.facet.KotlinFacet @@ -163,9 +162,12 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase(), Q return } - val writeActionResolveHandler: () -> Unit = { - val unwrappedIntention = unwrapIntention(intention) + val unwrappedIntention = unwrapIntention(intention) + if (shouldCheckIntentionActionType) { + assertInstanceOf(unwrappedIntention, QuickFixActionBase::class.java) + } + val writeActionResolveHandler: () -> Unit = { val intentionClassName = unwrappedIntention.javaClass.name if (!quickFixesAllowedToResolveInWriteAction.isWriteActionAllowed(intentionClassName)) { throw ResolveInDispatchThreadException("Resolve is not allowed under the write action for `$intentionClassName`!") @@ -205,6 +207,14 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase(), Q return File(beforeFileName).name + ".after" } + /** + * If true, the type of the [IntentionAction] to invoke is [QuickFixActionBase]. This ensures that the action is coming from a + * quickfix (i.e., diagnostic-based), and not a regular IDE intention. + */ + protected open val shouldCheckIntentionActionType: Boolean + // For FE 1.0, many quickfixes are implemented as IntentionActions, which may or may not be used as regular IDE intentions as well + get() = false + @Throws(ClassNotFoundException::class) private fun checkForUnexpectedActions() { val text = myFixture.editor.document.text