diff --git a/platform/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java b/platform/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java index 2bd126ef4a44..25ab41d9db0f 100644 --- a/platform/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java +++ b/platform/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java @@ -218,8 +218,32 @@ public final class ActionHint { } assert comment != null : commenter; - // "quick fix action text to perform" "should be available" - Pattern pattern = Pattern.compile("^" + Pattern.quote(comment) + " \"(.*)\" \"(\\w+)(?:-(\\w+))?\".*", Pattern.DOTALL); + return parse(file, contents, Pattern.quote(comment), exactMatch); + } + + /** + * Parse given file with given contents extracting ActionHint of it. + *
+ * Currently the following syntax is supported: + *
+ * {@code $commentPrefix "quick-fix name or intention text[|->next step]" "true|false|+ * If {@link ProblemHighlightType} enum value is specified instead of true/false + * (e.g. {@code "INFORMATION"}), then + * it's expected that the action is present and it's a quick-fix with given highlight type. + *
+ * + * @param file PsiFile associated with contents (used to determine the language) + * @param contents file contents + * @param commentPrefix any custom specific prefix, could be a regexp + * @param exactMatch if false then action hint matches prefix like in {@link CodeInsightTestFixture#filterAvailableIntentions(String)} + * @return ActionHint object + * @throws AssertionError if action hint is absent or has invalid format + */ + @NotNull + public static ActionHint parse(@NotNull PsiFile file, @NotNull String contents, @NotNull String commentPrefix, boolean exactMatch) { + // $commentPrefix "quick fix action text to perform" "should be available" + Pattern pattern = Pattern.compile("^" + commentPrefix + " \"([^\n]*)\" \"(\\w+)(?:-(\\w+))?\".*", Pattern.DOTALL); Matcher matcher = pattern.matcher(contents); TestCase.assertTrue("No comment found in " + file.getVirtualFile(), matcher.matches()); final String text = matcher.group(1); diff --git a/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt b/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt index f158b07d62b4..0d4fde0cb012 100644 --- a/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt +++ b/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/quickfix/AbstractHighLevelQuickFixTest.kt @@ -3,7 +3,6 @@ package org.jetbrains.kotlin.idea.fir.quickfix import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.codeInspection.InspectionProfileEntry import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.idea.fir.invalidateCaches import org.jetbrains.kotlin.idea.quickfix.AbstractQuickFixTest @@ -19,6 +18,7 @@ abstract class AbstractHighLevelQuickFixTest : AbstractQuickFixTest() { } override fun isFirPlugin(): Boolean = true + override fun tearDown() { runAll( { runInEdtAndWait { project.invalidateCaches() } }, @@ -59,8 +59,11 @@ abstract class AbstractHighLevelQuickFixTest : AbstractQuickFixTest() { // TODO: Enable these as more actions/inspections are enabled, and/or add more FIR-specific directives override fun checkForUnexpectedErrors() {} + + override val inspectionFileName: String + get() = ".k2Inspection" + + override val actionPrefix: String? = "K2_ACTION:" + override fun checkAvailableActionsAreExpected(actions: List(val p: P) -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.inspections.SafeDeleteFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.inspections.SafeDeleteFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.highlighting.SafeDeleteFix \ No newline at end of file diff --git a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/FirGenerateTests.kt b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/FirGenerateTests.kt index 0de0e5d867c1..cc456516c806 100644 --- a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/FirGenerateTests.kt +++ b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/FirGenerateTests.kt @@ -311,7 +311,7 @@ private fun assembleWorkspace(): TWorkspace = workspace { model("quickfix/removeSuspend", pattern = pattern, isIgnored = true) model("quickfix/removeToStringInStringTemplate", pattern = pattern, isIgnored = true) model("quickfix/removeTypeVariance", pattern = pattern, isIgnored = true) - model("quickfix/removeUnused", pattern = pattern, isIgnored = true) + model("quickfix/removeUnused", pattern = pattern) model("quickfix/removeUnusedParameter", pattern = pattern, isIgnored = true) model("quickfix/removeUnusedReceiver", pattern = pattern, isIgnored = true) model("quickfix/removeUseSiteTarget", pattern = pattern, isIgnored = true)