From 93da6311fcb0db6cbb34c45fd1c19c276d9ad0d9 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 29 Sep 2021 15:12:55 +0200 Subject: [PATCH] optimization: hoist "may import" condition out of loop GitOrigin-RevId: f63f50eed1ba065fb8449b68e80e39c35e63c810 --- .../daemon/impl/ShowAutoImportPass.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java index 92275919e0ed..05b121d95667 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java @@ -54,7 +54,7 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass { private final int myEndOffset; private final boolean hasDirtyTextRange; - ShowAutoImportPass(@NotNull Project project, @NotNull final PsiFile file, @NotNull Editor editor) { + ShowAutoImportPass(@NotNull Project project, @NotNull PsiFile file, @NotNull Editor editor) { super(project, editor.getDocument(), false); ApplicationManager.getApplication().assertIsDispatchThread(); @@ -105,9 +105,10 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass { } } - private void importUnambiguousImports(final int caretOffset) { + private void importUnambiguousImports(int caretOffset) { + if (!mayAutoImportNow(myFile)) return; Document document = myEditor.getDocument(); - final List infos = new ArrayList<>(); + List infos = new ArrayList<>(); DaemonCodeAnalyzerEx.processHighlights(document, myProject, null, 0, document.getTextLength(), info -> { if (info.hasHint() && info.getSeverity() == HighlightSeverity.ERROR && !info.getFixTextRange().containsOffset(caretOffset)) { infos.add(info); @@ -117,8 +118,7 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass { for (HighlightInfo info : infos) { for (HintAction action : extractHints(info)) { - if (mayAutoImportNow(myFile) && - action.isAvailable(myProject, myEditor, myFile) && + if (action.isAvailable(myProject, myEditor, myFile) && action.fixSilently(myEditor)) { break; } @@ -145,12 +145,12 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass { } @NotNull - private static List getVisibleHighlights(final int startOffset, - final int endOffset, + private static List getVisibleHighlights(int startOffset, + int endOffset, @NotNull Project project, @NotNull Editor editor, boolean isDirty) { - final List highlights = new ArrayList<>(); + List highlights = new ArrayList<>(); int offset = editor.getCaretModel().getOffset(); DaemonCodeAnalyzerEx.processHighlights(editor.getDocument(), project, null, startOffset, endOffset, info -> { //no changes after escape => suggest imports under caret only @@ -273,8 +273,8 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass { @NotNull - public static @NlsContexts.HintText String getMessage(final boolean multiple, @NotNull String name) { - final String messageKey = multiple ? "import.popup.multiple" : "import.popup.text"; + public static @NlsContexts.HintText String getMessage(boolean multiple, @NotNull String name) { + String messageKey = multiple ? "import.popup.multiple" : "import.popup.text"; String hintText = DaemonBundle.message(messageKey, name); hintText += " " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));