Skip to content

Commit

Permalink
#1434 Заполнение isPreferred для квик-фиксов
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Nov 16, 2020
1 parent f79150a commit 73914a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public static List<CodeAction> createCodeActions(
codeAction.setDiagnostics(diagnostics);
codeAction.setEdit(edit);
codeAction.setKind(CodeActionKind.QuickFix);
if (diagnostics.size() == 1) {
codeAction.setIsPreferred(Boolean.TRUE);
}

return Collections.singletonList(codeAction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;

import javax.annotation.CheckForNull;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -102,6 +103,7 @@ void testGetCodeActions() {
.anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(0)))
.anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(1)))
.anyMatch(codeAction -> codeAction.getKind().equals(CodeActionKind.QuickFix))
.allMatch(codeAction -> (codeAction.getDiagnostics().size() == 1) == toBoolean(codeAction.getIsPreferred()))
;
}

Expand Down Expand Up @@ -163,4 +165,11 @@ void testOnly() {
.containsOnly(CodeActionKind.Refactor)
;
}

private static boolean toBoolean(@CheckForNull Boolean value) {
if (value == null) {
return false;
}
return value;
}
}

0 comments on commit 73914a9

Please sign in to comment.