More correct quickfix testing - do not include suppression actions not available at caret

This commit is contained in:
Valentin Kipyatkov
2016-09-27 18:04:57 +03:00
parent aec2f19682
commit c9bb3607ac
@@ -38,9 +38,9 @@ import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtil;
import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileBasedIndex;
import kotlin.collections.CollectionsKt; import kotlin.collections.CollectionsKt;
import kotlin.text.StringsKt;
import kotlin.io.FilesKt; import kotlin.io.FilesKt;
import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function1;
import kotlin.text.StringsKt;
import org.apache.commons.lang.SystemUtils; import org.apache.commons.lang.SystemUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -310,15 +310,18 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase {
if (intention != null) return intention; if (intention != null) return intention;
// Support warning suppression // Support warning suppression
int caretOffset = myEditor.getCaretModel().getOffset();
for (HighlightInfo highlight : doHighlighting()) { for (HighlightInfo highlight : doHighlighting()) {
ProblemGroup group = highlight.getProblemGroup(); if (highlight.startOffset <= caretOffset && caretOffset <= highlight.endOffset) {
if (group instanceof SuppressableProblemGroup) { ProblemGroup group = highlight.getProblemGroup();
SuppressableProblemGroup problemGroup = (SuppressableProblemGroup) group; if (group instanceof SuppressableProblemGroup) {
PsiElement at = getFile().findElementAt(highlight.getActualStartOffset()); SuppressableProblemGroup problemGroup = (SuppressableProblemGroup) group;
SuppressIntentionAction[] actions = problemGroup.getSuppressActions(at); PsiElement at = getFile().findElementAt(highlight.getActualStartOffset());
for (SuppressIntentionAction action : actions) { SuppressIntentionAction[] actions = problemGroup.getSuppressActions(at);
if (action.getText().equals(text)) { for (SuppressIntentionAction action : actions) {
return action; if (action.getText().equals(text)) {
return action;
}
} }
} }
} }