From cac73cfb47c151ba703bdfa24d403f862de06958 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 24 Nov 2009 14:33:39 +0300 Subject: [PATCH] highlighting fix --- .../daemon/impl/quickfix/ImportClassFixBase.java | 26 ++++++++++----- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 3 +- .../impl/TextEditorBackgroundHighlighter.java | 39 +++++++++++++++++----- .../TextEditorHighlightingPassRegistrarImpl.java | 7 ++-- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 8 +++-- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java index a7de16327d..8803aa9b31 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java @@ -101,9 +101,15 @@ public abstract class ImportClassFixBase im protected abstract String getQualifiedName(T reference); - public boolean doFix(@NotNull final Editor editor, boolean doShow, final boolean allowCaretNearRef) { + public enum Result { + POPUP_SHOWN, + CLASS_IMPORTED, + POPUP_NOT_SHOWN + } + + public Result doFix(@NotNull final Editor editor, boolean doShow, final boolean allowCaretNearRef) { List classesToImport = getClassesToImport(); - if (classesToImport.isEmpty()) return false; + if (classesToImport.isEmpty()) return Result.POPUP_NOT_SHOWN; try { String name = getQualifiedName(myRef); @@ -111,7 +117,7 @@ public abstract class ImportClassFixBase im Pattern pattern = Pattern.compile(DaemonCodeAnalyzerSettings.getInstance().NO_AUTO_IMPORT_PATTERN); Matcher matcher = pattern.matcher(name); if (matcher.matches()) { - return false; + return Result.POPUP_NOT_SHOWN; } } } @@ -141,14 +147,15 @@ public abstract class ImportClassFixBase im action.execute(); } }); - return false; + return Result.CLASS_IMPORTED; } if (doShow && canImportHere) { String hintText = ShowAutoImportPass.getMessage(classes.length > 1, classes[0].getQualifiedName()); HintManager.getInstance().showQuestionHint(editor, hintText, myRef.getTextOffset(), myRef.getTextRange().getEndOffset(), action); + return Result.POPUP_SHOWN; } - return true; + return Result.POPUP_NOT_SHOWN; } private boolean canImportHere(boolean allowCaretNearRef, Editor editor, PsiFile psiFile, String exampleClassName) { @@ -160,7 +167,11 @@ public abstract class ImportClassFixBase im protected abstract boolean isQualified(T reference); public boolean showHint(final Editor editor) { - return !isQualified(myRef) && doFix(editor, true, false); + if (isQualified(myRef)) { + return false; + } + Result result = doFix(editor, true, false); + return result == Result.POPUP_SHOWN || result == Result.CLASS_IMPORTED; } @NotNull @@ -198,7 +209,7 @@ public abstract class ImportClassFixBase im TextRange range = ref.getTextRange(); int offset = editor.getCaretModel().getOffset(); - return range.grown(1).contains(offset); + return offset == range.getEndOffset(); } public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) { @@ -228,5 +239,4 @@ public abstract class ImportClassFixBase im } }; } - } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index 800289a433..3e6b5ceae6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -66,7 +66,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; /** * This class also controls the auto-reparse and auto-hints. @@ -221,7 +220,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx public void updateVisibleHighlighters(@NotNull Editor editor) { ApplicationManager.getApplication().assertIsDispatchThread(); - if (ApplicationManager.getApplication().isUnitTestMode()) return; + //if (ApplicationManager.getApplication().isUnitTestMode()) return; final TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor); BackgroundEditorHighlighter highlighter = textEditor.getBackgroundHighlighter(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorBackgroundHighlighter.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorBackgroundHighlighter.java index 93cef1d0d8..268a4a26dc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorBackgroundHighlighter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorBackgroundHighlighter.java @@ -29,6 +29,7 @@ import com.intellij.psi.impl.PsiFileEx; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; public class TextEditorBackgroundHighlighter implements BackgroundEditorHighlighter { @@ -48,7 +49,6 @@ public class TextEditorBackgroundHighlighter implements BackgroundEditorHighligh private final Project myProject; private boolean myCompiled; private static final int[] EXCEPT_VISIBLE = { - Pass.UPDATE_ALL, Pass.POST_UPDATE_ALL, Pass.UPDATE_OVERRIDEN_MARKERS, Pass.LOCAL_INSPECTIONS, @@ -79,31 +79,52 @@ public class TextEditorBackgroundHighlighter implements BackgroundEditorHighligh } } - private TextEditorHighlightingPass[] getPasses(int[] passesToIgnore) { - if (myProject.isDisposed()) return TextEditorHighlightingPass.EMPTY_ARRAY; + private List getPasses(int[] passesToIgnore) { + if (myProject.isDisposed()) return Collections.emptyList(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); renewFile(); - if (myFile == null || !myFile.isPhysical()) return TextEditorHighlightingPass.EMPTY_ARRAY; + if (myFile == null || !myFile.isPhysical()) return Collections.emptyList(); if (myCompiled) { passesToIgnore = EXCEPT_OVERRIDDEN; } else if (!DaemonCodeAnalyzer.getInstance(myProject).isHighlightingAvailable(myFile)) { - return TextEditorHighlightingPass.EMPTY_ARRAY; + return Collections.emptyList(); } TextEditorHighlightingPassRegistrarEx passRegistrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(myProject); - List createdPasses = passRegistrar.instantiatePasses(myFile, myEditor, passesToIgnore); - return createdPasses.toArray(new TextEditorHighlightingPass[createdPasses.size()]); + return passRegistrar.instantiatePasses(myFile, myEditor, passesToIgnore); } @NotNull public TextEditorHighlightingPass[] createPassesForVisibleArea() { - return getPasses(EXCEPT_VISIBLE); + List passes = getPasses(EXCEPT_VISIBLE); + int updateAllIndex = -1; + int updateVisibleIndex = -1; + for (int i = 0, passesSize = passes.size(); i < passesSize; i++) { + TextEditorHighlightingPass pass = passes.get(i); + if (pass instanceof GeneralHighlightingPass) { + if (pass.getId() == Pass.UPDATE_ALL) updateAllIndex = i; + if (pass.getId() == Pass.UPDATE_VISIBLE) updateVisibleIndex = i; + } + } + + if (updateVisibleIndex != -1 && updateAllIndex == -1) { + // ok + } + else if (updateVisibleIndex == -1 && updateAllIndex != -1) { + // use updateAll pass instead of updateVisible + } + else if (updateVisibleIndex != -1 && updateAllIndex != -1) { + // run only updateVisible, not both + passes.remove(updateAllIndex); + } + return passes.isEmpty() ? TextEditorHighlightingPass.EMPTY_ARRAY : passes.toArray(new TextEditorHighlightingPass[passes.size()]); } @NotNull public TextEditorHighlightingPass[] createPassesForEditor() { - return getPasses(ArrayUtil.EMPTY_INT_ARRAY); + List passes = getPasses(ArrayUtil.EMPTY_INT_ARRAY); + return passes.isEmpty() ? TextEditorHighlightingPass.EMPTY_ARRAY : passes.toArray(new TextEditorHighlightingPass[passes.size()]); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorHighlightingPassRegistrarImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorHighlightingPassRegistrarImpl.java index 0f3c5e49e6..628c5a5cc0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorHighlightingPassRegistrarImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorHighlightingPassRegistrarImpl.java @@ -113,11 +113,10 @@ public class TextEditorHighlightingPassRegistrarImpl extends TextEditorHighlight assert documentFromFile == editor.getDocument() : "Documents are different: " + editor.getDocument() + ";" + documentFromFile; } final TIntObjectHashMap id2Pass = new TIntObjectHashMap(); - final TIntArrayList ignoredPasses = new TIntArrayList(); + final TIntArrayList passesRefusedToCreate = new TIntArrayList(); myRegisteredPassFactories.forEachKey(new TIntProcedure() { public boolean execute(int passId) { if (ArrayUtil.find(passesToIgnore, passId) != -1) { - ignoredPasses.add(passId); return true; } PassConfig passConfig = myRegisteredPassFactories.get(passId); @@ -125,7 +124,7 @@ public class TextEditorHighlightingPassRegistrarImpl extends TextEditorHighlight final TextEditorHighlightingPass pass = factory.createHighlightingPass(psiFile, editor); if (pass == null) { - ignoredPasses.add(passId); + passesRefusedToCreate.add(passId); } else { TIntArrayList ids = new TIntArrayList(passConfig.completionPredecessorIds.length); @@ -146,7 +145,7 @@ public class TextEditorHighlightingPassRegistrarImpl extends TextEditorHighlight }); final FileStatusMap statusMap = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject)).getFileStatusMap(); - ignoredPasses.forEach(new TIntProcedure() { + passesRefusedToCreate.forEach(new TIntProcedure() { public boolean execute(int passId) { statusMap.markFileUpToDate(editor.getDocument(), psiFile, passId); return true; diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index b68b671751..8263966c0a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1084,7 +1084,11 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig Project project = file.getProject(); FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); assertTrue(!DumbServiceImpl.getInstance(project).isDumb()); - ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap().allowDirt(allowDirt); + FileStatusMap fileStatusMap = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap(); + for (int ignoreId : toIgnore) { + fileStatusMap.markFileUpToDate(editor.getDocument(), file, ignoreId); + } + fileStatusMap.allowDirt(allowDirt); try { TextEditorHighlightingPassRegistrarEx registrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project); final List passes = registrar.instantiatePasses(file, editor, toIgnore); @@ -1103,7 +1107,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return infos == null ? Collections.emptyList() : new ArrayList(infos); } finally { - ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap().allowDirt(true); + fileStatusMap.allowDirt(true); } } -- 2.11.4.GIT