Search in sources :

Example 1 with AbstractIntentionAction

use of com.intellij.codeInsight.intention.AbstractIntentionAction in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testLightBulbDoesNotUpdateIntentionsInEDT.

public void testLightBulbDoesNotUpdateIntentionsInEDT() throws Exception {
    final IntentionAction longLongUpdate = new AbstractIntentionAction() {

        @Override
        public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
        }

        @Nls
        @NotNull
        @Override
        public String getText() {
            return "LongAction";
        }

        @Override
        public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
            if (ApplicationManager.getApplication().isDispatchThread()) {
                throw new RuntimeException("Must not update actions in EDT");
            }
            return true;
        }
    };
    IntentionManager.getInstance().addAction(longLongUpdate);
    Disposer.register(getTestRootDisposable(), () -> IntentionManager.getInstance().unregisterIntention(longLongUpdate));
    configureByText(JavaFileType.INSTANCE, "class X { <caret>  }");
    makeEditorWindowVisible(new Point(0, 0), myEditor);
    doHighlighting();
    myDaemonCodeAnalyzer.restart();
    executeWithReparseDelay(() -> {
        for (int i = 0; i < 1000; i++) {
            caretRight();
            UIUtil.dispatchAllInvocationEvents();
            caretLeft();
            DaemonProgressIndicator updateProgress = myDaemonCodeAnalyzer.getUpdateProgress();
            while (myDaemonCodeAnalyzer.getUpdateProgress() == updateProgress) {
                // wait until daemon started
                UIUtil.dispatchAllInvocationEvents();
            }
            long start = System.currentTimeMillis();
            while (myDaemonCodeAnalyzer.isRunning() && System.currentTimeMillis() < start + 500) {
                // wait for a bit more until ShowIntentionsPass.doApplyInformationToEditor() called
                UIUtil.dispatchAllInvocationEvents();
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) AbstractIntentionAction(com.intellij.codeInsight.intention.AbstractIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AbstractIntentionAction(com.intellij.codeInsight.intention.AbstractIntentionAction) TextEditor(com.intellij.openapi.fileEditor.TextEditor) NotNull(org.jetbrains.annotations.NotNull) LightweightHint(com.intellij.ui.LightweightHint)

Aggregations

AbstractIntentionAction (com.intellij.codeInsight.intention.AbstractIntentionAction)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 Project (com.intellij.openapi.project.Project)1 LightweightHint (com.intellij.ui.LightweightHint)1 NotNull (org.jetbrains.annotations.NotNull)1