From c9bb3607acbb181221b7f1e531ecfcb6808e9359 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 27 Sep 2016 18:04:57 +0300 Subject: [PATCH] More correct quickfix testing - do not include suppression actions not available at caret --- .../idea/quickfix/AbstractQuickFixTest.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java index 39f9ddfc5ba..41dfea190d1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java @@ -38,9 +38,9 @@ import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.util.ArrayUtil; import com.intellij.util.indexing.FileBasedIndex; import kotlin.collections.CollectionsKt; -import kotlin.text.StringsKt; import kotlin.io.FilesKt; import kotlin.jvm.functions.Function1; +import kotlin.text.StringsKt; import org.apache.commons.lang.SystemUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -310,15 +310,18 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase { if (intention != null) return intention; // Support warning suppression + int caretOffset = myEditor.getCaretModel().getOffset(); for (HighlightInfo highlight : doHighlighting()) { - ProblemGroup group = highlight.getProblemGroup(); - if (group instanceof SuppressableProblemGroup) { - SuppressableProblemGroup problemGroup = (SuppressableProblemGroup) group; - PsiElement at = getFile().findElementAt(highlight.getActualStartOffset()); - SuppressIntentionAction[] actions = problemGroup.getSuppressActions(at); - for (SuppressIntentionAction action : actions) { - if (action.getText().equals(text)) { - return action; + if (highlight.startOffset <= caretOffset && caretOffset <= highlight.endOffset) { + ProblemGroup group = highlight.getProblemGroup(); + if (group instanceof SuppressableProblemGroup) { + SuppressableProblemGroup problemGroup = (SuppressableProblemGroup) group; + PsiElement at = getFile().findElementAt(highlight.getActualStartOffset()); + SuppressIntentionAction[] actions = problemGroup.getSuppressActions(at); + for (SuppressIntentionAction action : actions) { + if (action.getText().equals(text)) { + return action; + } } } }