diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 3094a4d41a60d..83a6cb10983ff 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -49,6 +49,7 @@ import com.intellij.util.Chunk; import com.intellij.util.SystemProperties; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.DateFormatUtil; @@ -386,7 +387,7 @@ private void startup(final CompileScope scope, final boolean withModalProgress, final CompileStatusNotification callback, final CompilerMessage message) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ModalityState modalityState = ModalityState.current(); final boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode(); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java index c7b8a0f236cbc..9848f9e8e58a0 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java @@ -42,6 +42,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiMethodUtil; import com.intellij.util.PathUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -256,7 +257,7 @@ public static VirtualFile showDialogAndCreateManifest(final ArtifactEditorContex @Nullable public static VirtualFile createManifestFile(final @NotNull VirtualFile directory, final @NotNull Project project) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { return WriteAction.compute(() -> { VirtualFile dir = directory; diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextUtil.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextUtil.java index aca59093b4882..74c352a0132a9 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextUtil.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextUtil.java @@ -9,7 +9,6 @@ import com.intellij.debugger.engine.events.DebuggerCommandImpl; import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.ui.impl.watch.ThreadDescriptorImpl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl; @@ -19,6 +18,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiMethod; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XSourcePosition; import org.jetbrains.annotations.NotNull; @@ -27,7 +27,7 @@ public final class DebuggerContextUtil { public static void setStackFrame(final DebuggerStateManager manager, final StackFrameProxyImpl stackFrame) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final DebuggerContextImpl context = manager.getContext(); final DebuggerSession session = context.getDebuggerSession(); @@ -53,7 +53,7 @@ protected void action() { } public static void setThread(DebuggerStateManager contextManager, ThreadDescriptorImpl item) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final DebuggerSession session = contextManager.getContext().getDebuggerSession(); final DebuggerContextImpl newContext = diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java index cc1ca602391e5..104cfb8593c34 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java @@ -1,7 +1,10 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.debugger.impl; -import com.intellij.debugger.*; +import com.intellij.debugger.DebugEnvironment; +import com.intellij.debugger.DebuggerManagerEx; +import com.intellij.debugger.JavaDebuggerBundle; +import com.intellij.debugger.NameMapper; import com.intellij.debugger.engine.*; import com.intellij.debugger.ui.breakpoints.BreakpointManager; import com.intellij.debugger.ui.tree.render.BatchEvaluator; @@ -17,7 +20,6 @@ import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.execution.ui.RunContentWithExecutorListener; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; @@ -33,6 +35,7 @@ import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.PsiClass; import com.intellij.util.EventDispatcher; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.UIUtil; @@ -143,7 +146,7 @@ public void globalSchemeChange(EditorColorsScheme scheme) { @Nullable @Override public DebuggerSession getSession(DebugProcess process) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return ContainerUtil.find(getSessions(), debuggerSession -> process == debuggerSession.getProcess()); } @@ -360,7 +363,7 @@ public void setState(@NotNull final DebuggerContextImpl context, DebuggerSession.State state, DebuggerSession.Event event, String description) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myDebuggerSession = context.getDebuggerSession(); if (myDebuggerSession != null) { myDebuggerSession.getContextManager().setState(context, state, event, description); diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java index 31f3c80fc5571..fbe9ad8a7fec1 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java @@ -41,6 +41,7 @@ import com.intellij.unscramble.ThreadState; import com.intellij.util.Alarm; import com.intellij.util.TimeoutUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.AbstractDebuggerSession; @@ -158,7 +159,7 @@ public void setState(@NotNull final DebuggerContextImpl context, final State state, final Event event, final @NlsContexts.Label String description) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final DebuggerSession session = context.getDebuggerSession(); LOG.assertTrue(session == DebuggerSession.this || session == null); final Runnable setStateRunnable = () -> { @@ -418,7 +419,7 @@ public boolean isRunning() { } private SuspendContextImpl getSuspendContext() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return getContextManager().getContext().getSuspendContext(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 5138f8644f0ac..9a8e978ca7770 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -32,6 +32,7 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiField; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.xdebugger.XDebuggerManager; @@ -191,7 +192,7 @@ public StepIntoBreakpoint addStepIntoBreakpoint(@NotNull BreakpointStepMethodFil @Nullable public LineBreakpoint addLineBreakpoint(Document document, int lineIndex, Consumer setupAction) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!LineBreakpoint.canAddLineBreakpoint(myProject, document, lineIndex)) { return null; } @@ -228,7 +229,7 @@ public FieldBreakpoint addFieldBreakpoint(@NotNull Document document, int offset @Nullable public FieldBreakpoint addFieldBreakpoint(Document document, int lineIndex, String fieldName) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); XLineBreakpoint xBreakpoint = addXLineBreakpoint(JavaFieldBreakpointType.class, document, lineIndex); Breakpoint javaBreakpoint = getJavaBreakpoint(xBreakpoint); if (javaBreakpoint instanceof FieldBreakpoint fieldBreakpoint) { @@ -241,7 +242,7 @@ public FieldBreakpoint addFieldBreakpoint(Document document, int lineIndex, Stri @Nullable public ExceptionBreakpoint addExceptionBreakpoint(@NotNull final String exceptionClassName, final String packageName) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final JavaExceptionBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); return WriteAction.compute(() -> { XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() @@ -259,7 +260,7 @@ public ExceptionBreakpoint addExceptionBreakpoint(@NotNull final String exceptio @Nullable public MethodBreakpoint addMethodBreakpoint(Document document, int lineIndex) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); XLineBreakpoint xBreakpoint = addXLineBreakpoint(JavaMethodBreakpointType.class, document, lineIndex); if (getJavaBreakpoint(xBreakpoint) instanceof MethodBreakpoint methodBreakpoint) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java index 246a5a15c56ea..f6f7ab4c0f694 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java @@ -26,13 +26,13 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.NlsContexts; import com.intellij.ui.SpeedSearchComparator; import com.intellij.ui.TreeSpeedSearch; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.tree.TreeUtil; import com.sun.jdi.ThreadReference; import org.jetbrains.annotations.NotNull; @@ -282,7 +282,7 @@ public final void treeChanged() { protected abstract void build(DebuggerContextImpl context); public void rebuild(final DebuggerContextImpl context) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final DebugProcessImpl process = context.getDebugProcess(); if (process == null) { return; // empty context, no process available yet diff --git a/java/idea-ui/src/com/intellij/jarFinder/AbstractAttachSourceProvider.java b/java/idea-ui/src/com/intellij/jarFinder/AbstractAttachSourceProvider.java index 4d0d41f3383b7..c14aadfa8286c 100644 --- a/java/idea-ui/src/com/intellij/jarFinder/AbstractAttachSourceProvider.java +++ b/java/idea-ui/src/com/intellij/jarFinder/AbstractAttachSourceProvider.java @@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.psi.PsiFile; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.io.HttpRequests; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -92,7 +93,7 @@ public String getBusyText() { @Override public @NotNull ActionCallback perform(@NotNull List orderEntriesContainingFile) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ActionCallback callback = new ActionCallback(); callback.setDone(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index 765a44d9407f7..f48fb3de4ab6e 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -17,7 +17,6 @@ import com.intellij.ide.util.projectWizard.NamePathComponent; import com.intellij.ide.util.projectWizard.ProjectWizardUtil; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.BaseExtensionPointName; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.*; @@ -48,6 +47,7 @@ import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.ui.navigation.Place; import com.intellij.util.PlatformIcons; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NonNls; @@ -194,7 +194,7 @@ protected Collection getProjectStructureEleme @Override protected void updateSelection(@Nullable NamedConfigurable configurable) { myProjectStructureConfigurable.getFacetStructureConfigurable().disposeMultipleSettingsEditor(); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.updateSelection(configurable); if (configurable != null) { updateModuleEditorSelection(configurable); diff --git a/java/idea-ui/src/org/jetbrains/idea/maven/utils/library/RepositoryLibraryResolveErrorNotification.java b/java/idea-ui/src/org/jetbrains/idea/maven/utils/library/RepositoryLibraryResolveErrorNotification.java index 10c77dffb5f09..b1a32990f120f 100644 --- a/java/idea-ui/src/org/jetbrains/idea/maven/utils/library/RepositoryLibraryResolveErrorNotification.java +++ b/java/idea-ui/src/org/jetbrains/idea/maven/utils/library/RepositoryLibraryResolveErrorNotification.java @@ -7,9 +7,9 @@ import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.notification.NotificationsManager; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -29,7 +29,7 @@ class RepositoryLibraryResolveErrorNotification extends Notification { } void addLibraryResolveError(@NotNull RepositoryLibraryProperties lib) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myErrors.add(lib.getMavenId()); String message; @@ -50,7 +50,7 @@ void addLibraryResolveError(@NotNull RepositoryLibraryProperties lib) { } static synchronized void showOrUpdate(@NotNull RepositoryLibraryProperties libWithError, @NotNull Project project) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); RepositoryLibraryResolveErrorNotification[] notifications = NotificationsManager.getNotificationsManager().getNotificationsOfType(RepositoryLibraryResolveErrorNotification.class, project); RepositoryLibraryResolveErrorNotification notification = notifications.length > 0 ? notifications[0] : null; diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewDiffRequest.java b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewDiffRequest.java index 62db7e4c7dad6..283740014efc5 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewDiffRequest.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewDiffRequest.java @@ -8,7 +8,6 @@ import com.intellij.diff.tools.simple.SimpleDiffViewer; import com.intellij.diff.tools.util.base.DiffViewerBase; import com.intellij.diff.tools.util.base.DiffViewerListener; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.ScrollType; @@ -17,6 +16,7 @@ import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.TextRange; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -41,7 +41,7 @@ class PreviewDiffRequest extends SimpleDiffRequest { } public void setViewer(FrameDiffTool.DiffViewer viewer) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (viewer instanceof UnifiedDiffViewer) { myCaretTracker = new UnifiedCaretTracker((UnifiedDiffViewer)viewer); @@ -55,7 +55,7 @@ else if (viewer instanceof SimpleDiffViewer) { } public void onNodeSelected(@NotNull FragmentNode node) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Couple bounds = myLinesBounds.get(node); if (bounds != null && myCaretTracker != null) { @@ -64,7 +64,7 @@ public void onNodeSelected(@NotNull FragmentNode node) { } public void onInitialized() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myInitialized = true; } diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java index 3be9dd0e94cd3..a21387b8a9b60 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java @@ -21,6 +21,7 @@ import com.intellij.ui.scale.JBUIScale; import com.intellij.usages.impl.UsageModelTracker; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.DialogUtil; import com.intellij.util.ui.components.BorderLayoutPanel; import one.util.streamex.StreamEx; @@ -153,7 +154,7 @@ private void updateLater() { } private void updateImmediately() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myProject.isDisposed()) return; boolean isModified = myDiffPanel.isModified(); diff --git a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java index 9a703cba8ad1e..a5cfe6a424185 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java @@ -59,6 +59,13 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; +import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener; +import com.intellij.platform.backend.workspace.WorkspaceModelTopics; +import com.intellij.platform.workspace.jps.entities.LibraryEntity; +import com.intellij.platform.workspace.jps.entities.ModuleCustomImlDataEntity; +import com.intellij.platform.workspace.storage.EntityChange; +import com.intellij.platform.workspace.storage.VersionedStorageChange; +import com.intellij.platform.workspace.storage.WorkspaceEntity; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleSettings; import com.intellij.psi.util.PsiTreeUtil; @@ -69,17 +76,11 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.Processor; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.OptionsMessageDialog; -import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener; -import com.intellij.platform.backend.workspace.WorkspaceModelTopics; -import com.intellij.platform.workspace.storage.EntityChange; -import com.intellij.platform.workspace.storage.VersionedStorageChange; -import com.intellij.platform.workspace.storage.WorkspaceEntity; -import com.intellij.platform.workspace.jps.entities.LibraryEntity; -import com.intellij.platform.workspace.jps.entities.ModuleCustomImlDataEntity; import one.util.streamex.StreamEx; import org.jdom.Element; import org.jetbrains.annotations.*; @@ -195,7 +196,7 @@ public void annotateExternally(@NotNull PsiModifierListOwner listOwner, @NotNull PsiFile fromFile, PsiNameValuePair @Nullable [] value) throws CanceledConfigurationException { Application application = ApplicationManager.getApplication(); - application.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LOG.assertTrue(!application.isWriteAccessAllowed()); final Project project = myPsiManager.getProject(); @@ -597,7 +598,7 @@ public Icon getIconFor(final VirtualFile aValue) { @Override public boolean deannotate(@NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQN) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return processExistingExternalAnnotations(listOwner, annotationFQN, annotationTag -> { PsiElement parent = annotationTag.getParent(); annotationTag.delete(); @@ -612,7 +613,7 @@ public boolean deannotate(@NotNull PsiModifierListOwner listOwner, @NotNull Stri @Override public void elementRenamedOrMoved(@NotNull PsiModifierListOwner element, @NotNull String oldExternalName) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { final List files = findExternalAnnotationsXmlFiles(element); if (files == null) { @@ -661,7 +662,7 @@ public void elementRenamedOrMoved(@NotNull PsiModifierListOwner element, @NotNul public boolean editExternalAnnotation(@NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQN, PsiNameValuePair @Nullable [] value) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return processExistingExternalAnnotations(listOwner, annotationFQN, annotationTag -> { annotationTag.replace(XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText( createAnnotationTag(annotationFQN, value))); @@ -745,7 +746,7 @@ private boolean processExistingExternalAnnotations(@NotNull PsiModifierListOwner @Override public @NotNull AnnotationPlace chooseAnnotationsPlace(@NotNull PsiElement element) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return chooseAnnotationsPlace(element, () -> confirmNewExternalAnnotationRoot(element)); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaReferenceImporter.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaReferenceImporter.java index cee1a809ca272..8ffac48844eea 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaReferenceImporter.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaReferenceImporter.java @@ -12,6 +12,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiJavaCodeReferenceElement; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -24,7 +25,7 @@ public class JavaReferenceImporter implements ReferenceImporter { */ @Deprecated(forRemoval = true) public static boolean autoImportReferenceAtCursor(@NotNull Editor editor, @NotNull PsiFile file, boolean allowCaretNearRef) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return new JavaReferenceImporter().autoImportReferenceAtCursor(editor, file); } 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 b9bd3a9dc12e4..2112401ab51e9 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 @@ -34,6 +34,7 @@ import com.intellij.psi.util.PsiUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -349,7 +350,7 @@ public enum Result { @NotNull public Result doFix(@NotNull Editor editor, boolean allowPopup, boolean allowCaretNearRef, boolean mayAddUnambiguousImportsSilently) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); List result = getClassesToImport(); PsiClass[] classes = result.toArray(PsiClass.EMPTY_ARRAY); if (classes.length == 0) return Result.POPUP_NOT_SHOWN; diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java index 4651b00c9100d..932e646976dd7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java @@ -54,6 +54,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.ObjectUtils; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import com.siyeh.ig.controlflow.UnnecessaryDefaultInspection; import com.siyeh.ig.fixes.*; import com.siyeh.ipp.modifiers.ChangeModifierIntention; @@ -866,7 +867,7 @@ public List createAddAnnotationAttributeNameFixes(@NotNull PsiN } private static boolean timeToOptimizeImports(@NotNull PsiFile file, boolean isInContent, @NotNull ThreeState extensionsAllowToChangeFileSilently) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!CodeInsightWorkspaceSettings.getInstance(file.getProject()).isOptimizeImportsOnTheFly()) { return false; } diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java index ff8921f481334..a6af2e4a7b479 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java @@ -17,6 +17,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.util.ObjectUtils; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -98,7 +99,7 @@ public boolean isTerminalSymbol(char currentChar) { @Override public void preExpand(@NotNull final PsiFile file, @NotNull final Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isSemicolonNeeded(file, editor)) { ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().runUndoTransparentAction(() -> { EditorModificationUtil.insertStringAtCaret(editor, ";", false, false); diff --git a/java/java-impl/src/com/intellij/ide/util/SuperMethodWarningUtil.java b/java/java-impl/src/com/intellij/ide/util/SuperMethodWarningUtil.java index ccdf2096055b4..ce42e52f0185b 100644 --- a/java/java-impl/src/com/intellij/ide/util/SuperMethodWarningUtil.java +++ b/java/java-impl/src/com/intellij/ide/util/SuperMethodWarningUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.util; import com.intellij.java.JavaBundle; @@ -30,6 +30,7 @@ import com.intellij.refactoring.RefactoringBundle; import com.intellij.util.ArrayUtilRt; import com.intellij.util.ObjectUtils; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,7 +42,7 @@ public final class SuperMethodWarningUtil { private SuperMethodWarningUtil() {} public static PsiMethod @NotNull [] checkSuperMethods(@NotNull PsiMethod method, @NotNull String actionString) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return checkSuperMethods(method, actionString, Collections.emptyList()); } @@ -61,7 +62,7 @@ private SuperMethodWarningUtil() {} public static PsiMethod @NotNull [] checkSuperMethods(@NotNull PsiMethod method, @NlsSafe @Nullable String actionString, @NotNull Collection ignore) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); PsiMethod[] methodTargetCandidates = getTargetMethodCandidates(method, ignore); if (methodTargetCandidates.length == 1 && methodTargetCandidates[0] == method) return methodTargetCandidates; @@ -93,7 +94,7 @@ private SuperMethodWarningUtil() {} @NotNull static Collection getSuperMethods(@NotNull PsiMethod method, PsiClass aClass, @NotNull Collection ignore) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert !ApplicationManager.getApplication().isWriteAccessAllowed(); final Collection superMethods = DeepestSuperMethodsSearch.search(method).findAll(); superMethods.removeAll(ignore); @@ -118,7 +119,7 @@ static Collection getSuperMethods(@NotNull PsiMethod method, PsiClass public static PsiMethod checkSuperMethod(@NotNull PsiMethod method) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); PsiClass aClass = method.getContainingClass(); if (aClass == null) return method; @@ -148,7 +149,7 @@ public static PsiMethod checkSuperMethod(@NotNull PsiMethod method) { public static void checkSuperMethod(@NotNull PsiMethod method, @NotNull final PsiElementProcessor processor, @NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); PsiClass aClass = method.getContainingClass(); if (aClass == null) { processor.execute(method); diff --git a/java/java-tests/testData/codeInsight/enterAction/Performance.java b/java/java-tests/testData/codeInsight/enterAction/Performance.java index bdbb96fe69018..5d2c6d038f991 100644 --- a/java/java-tests/testData/codeInsight/enterAction/Performance.java +++ b/java/java-tests/testData/codeInsight/enterAction/Performance.java @@ -11,6 +11,8 @@ import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.concurrency.ThreadingAssertions; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -291,12 +293,12 @@ public ScrollingModel getScrollingModel() { } public EditorSettings getSettings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return mySettings; } public void reinitSettings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCharHeight = -1; myLineHeight = -1; myDescent = -1; @@ -505,7 +507,7 @@ private void fireFocusGained() { } public void setHighlighter(EditorHighlighter highlighter) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myHighlighter != null) { getDocument().removeDocumentListener(myHighlighter); } @@ -520,7 +522,7 @@ public void setHighlighter(EditorHighlighter highlighter) { } public EditorHighlighter getHighlighter() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myHighlighter; } @@ -541,7 +543,7 @@ public void removePropertyChangeListener(PropertyChangeListener listener) { } public void setInsertMode(boolean mode) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean oldValue = myIsInsertMode; myIsInsertMode = mode; myPropertyChangeSupport.firePropertyChange(EditorEx.PROP_INSERT_MODE, oldValue, mode); @@ -555,7 +557,7 @@ public boolean isInsertMode() { } public void setColumnMode(boolean mode) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean oldValue = myIsColumnMode; myIsColumnMode = mode; myPropertyChangeSupport.firePropertyChange(PROP_COLUMN_MODE, oldValue, mode); @@ -812,7 +814,7 @@ public int visibleLineNumberToYPosition(int lineNum) { } public void repaint(int startOffset, int endOffset) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myScrollPane == null) { return; } @@ -1692,7 +1694,7 @@ private int getTextSegmentWidth(CharSequence text, int xStart, int fontType) { public int getLineHeight() { if (myLineHeight != -1) return myLineHeight; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FontMetrics fontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); myLineHeight = (int)(fontMetrics.getHeight() * (isOneLineMode() ? 1 : myScheme.getLineSpacing())); @@ -1717,7 +1719,7 @@ int getDescent() { public FontMetrics getFontMetrics(int fontType) { if (myPlainFontMetrics == null) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myPlainFontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); myBoldFontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.BOLD)); myItalicFontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.ITALIC)); @@ -1736,7 +1738,7 @@ public FontMetrics getFontMetrics(int fontType) { private int getCharHeight() { if (myCharHeight == -1) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FontMetrics fontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); myCharHeight = fontMetrics.charWidth('a'); } @@ -1773,7 +1775,7 @@ public JScrollPane getScrollPane() { } public int logicalPositionToOffset(LogicalPosition pos) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myDocument.getLineCount() == 0) return 0; if (pos.line < 0) throw new IndexOutOfBoundsException("Wrong line: " + pos.line); @@ -1793,12 +1795,12 @@ public int logicalPositionToOffset(LogicalPosition pos) { } public void setLastColumnNumber(int val) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLastColumnNumber = val; } public int getLastColumnNumber() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myLastColumnNumber; } @@ -1809,7 +1811,7 @@ int getVisibleLineCount() { } public VisualPosition logicalToVisualPosition(LogicalPosition logicalPos) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myFoldingModel.isFoldingEnabled()) return new VisualPosition(logicalPos.line, logicalPos.column); int offset = logicalPositionToOffset(logicalPos); @@ -1917,7 +1919,7 @@ private FoldRegion getLastCollapsedBeforePosition(VisualPosition visual) { } public LogicalPosition visualToLogicalPosition(VisualPosition visiblePos) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myFoldingModel.isFoldingEnabled()) return new LogicalPosition(visiblePos.line, visiblePos.column); int line = visiblePos.line; @@ -2571,7 +2573,7 @@ public boolean isEmbeddedIntoDialogWrapper() { } public void setEmbeddedIntoDialogWrapper(boolean b) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myEmbeddedIntoDialogWrapper = b; myScrollPane.setFocusable(!b); @@ -2941,18 +2943,18 @@ private void executeAction(String actionId, DataContext dataContext) { } public void setColorsScheme(EditorColorsScheme scheme) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myScheme = scheme; reinitSettings(); } public EditorColorsScheme getColorsScheme() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myScheme; } public void setVerticalScrollbarOrientation(int type) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int currentHorOffset = myScrollingModel.getHorizontalScrollOffset(); myScrollbarOrientation = type; if (type == EditorEx.VERTICAL_SCROLLBAR_LEFT) { diff --git a/java/java-tests/testData/psi/autodetect/bigFile.java b/java/java-tests/testData/psi/autodetect/bigFile.java index eea88add04639..27f691877bbd7 100644 --- a/java/java-tests/testData/psi/autodetect/bigFile.java +++ b/java/java-tests/testData/psi/autodetect/bigFile.java @@ -33,6 +33,8 @@ import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.actionSystem.impl.MouseGestureManager; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.concurrency.ThreadingAssertions; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.UndoConfirmationPolicy; @@ -5215,7 +5217,7 @@ public EditorColorsScheme getColorsScheme() { } static void assertIsDispatchThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } private static void assertReadAccess() { diff --git a/java/java-tests/testData/psi/formatter/java/performance.java b/java/java-tests/testData/psi/formatter/java/performance.java index b0512bcaf379c..47b0043736686 100644 --- a/java/java-tests/testData/psi/formatter/java/performance.java +++ b/java/java-tests/testData/psi/formatter/java/performance.java @@ -10,6 +10,8 @@ import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.concurrency.ThreadingAssertions; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -288,12 +290,12 @@ public ScrollingModel getScrollingModel() { } public EditorSettings getSettings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return mySettings; } public void reinitSettings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCharHeight = -1; myLineHeight = -1; myDescent = -1; @@ -505,7 +507,7 @@ private void fireFocusGained() { } public void setHighlighter(EditorHighlighter highlighter) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myHighlighter != null) { getDocument().removeDocumentListener(myHighlighter); } @@ -520,7 +522,7 @@ public void setHighlighter(EditorHighlighter highlighter) { } public EditorHighlighter getHighlighter() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myHighlighter; } @@ -541,7 +543,7 @@ public void removePropertyChangeListener(PropertyChangeListener listener) { } public void setInsertMode(boolean mode) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean oldValue = myIsInsertMode; myIsInsertMode = mode; myPropertyChangeSupport.firePropertyChange(EditorEx.PROP_INSERT_MODE, oldValue, mode); @@ -555,7 +557,7 @@ public boolean isInsertMode() { } public void setColumnMode(boolean mode) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean oldValue = myIsColumnMode; myIsColumnMode = mode; myPropertyChangeSupport.firePropertyChange(PROP_COLUMN_MODE, oldValue, mode); @@ -812,7 +814,7 @@ public int visibleLineNumberToYPosition(int lineNum) { } public void repaint(int startOffset, int endOffset) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myScrollPane == null) { return; } @@ -1738,7 +1740,7 @@ private int getTextSegmentWidth(CharSequence text, int xStart, int fontType) { public int getLineHeight() { if (myLineHeight != -1) return myLineHeight; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FontMetrics fontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); myLineHeight = (int)(fontMetrics.getHeight() * (isOneLineMode() ? 1 : myScheme.getLineSpacing())); @@ -1763,7 +1765,7 @@ int getDescent() { public FontMetrics getFontMetrics(int fontType) { if (myPlainFontMetrics == null) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myPlainFontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); myBoldFontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.BOLD)); myItalicFontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.ITALIC)); @@ -1782,7 +1784,7 @@ public FontMetrics getFontMetrics(int fontType) { private int getCharHeight() { if (myCharHeight == -1) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FontMetrics fontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); myCharHeight = fontMetrics.charWidth('a'); } @@ -1819,7 +1821,7 @@ public JScrollPane getScrollPane() { } public int logicalPositionToOffset(LogicalPosition pos) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myDocument.getLineCount() == 0) return 0; if (pos.line < 0) throw new IndexOutOfBoundsException("Wrong line: " + pos.line); @@ -1839,12 +1841,12 @@ public int logicalPositionToOffset(LogicalPosition pos) { } public void setLastColumnNumber(int val) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLastColumnNumber = val; } public int getLastColumnNumber() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myLastColumnNumber; } @@ -1855,7 +1857,7 @@ int getVisibleLineCount() { } public VisualPosition logicalToVisualPosition(LogicalPosition logicalPos) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myFoldingModel.isFoldingEnabled()) return new VisualPosition(logicalPos.line, logicalPos.column); int offset = logicalPositionToOffset(logicalPos); @@ -1963,7 +1965,7 @@ private FoldRegion getLastCollapsedBeforePosition(VisualPosition visual) { } public LogicalPosition visualToLogicalPosition(VisualPosition visiblePos) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myFoldingModel.isFoldingEnabled()) return new LogicalPosition(visiblePos.line, visiblePos.column); int line = visiblePos.line; @@ -2973,18 +2975,18 @@ private void executeAction(String actionId, DataContext dataContext) { } public void setColorsScheme(EditorColorsScheme scheme) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myScheme = scheme; reinitSettings(); } public EditorColorsScheme getColorsScheme() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myScheme; } public void setVerticalScrollbarOrientation(int type) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int currentHorOffset = myScrollingModel.getHorizontalScrollOffset(); myScrollbarOrientation = type; if (type == EditorEx.VERTICAL_SCROLLBAR_LEFT) { diff --git a/java/java-tests/testData/psi/formatter/java/performance/bigFile.java b/java/java-tests/testData/psi/formatter/java/performance/bigFile.java index 603937de3d923..86e254cff36e3 100644 --- a/java/java-tests/testData/psi/formatter/java/performance/bigFile.java +++ b/java/java-tests/testData/psi/formatter/java/performance/bigFile.java @@ -34,6 +34,8 @@ import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.actionSystem.impl.MouseGestureManager; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.concurrency.ThreadingAssertions; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.UndoConfirmationPolicy; @@ -5200,7 +5202,7 @@ public EditorColorsScheme getColorsScheme() { } static void assertIsDispatchThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } private static void assertReadAccess() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java index 887e47a0da0e8..337278c7a9cbe 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java @@ -100,6 +100,7 @@ import com.intellij.ui.HintListener; import com.intellij.ui.LightweightHint; import com.intellij.util.*; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.storage.HeavyProcessLatch; import com.intellij.util.ref.GCWatcher; @@ -2208,7 +2209,7 @@ private void checkFoldingState(String expected) { } private void waitForDaemon() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); long start = System.currentTimeMillis(); long deadline = start + 60_000; while (!daemonIsWorkingOrPending()) { @@ -2930,7 +2931,7 @@ class X /* */ { } public void testUncommittedByAccidentNonPhysicalDocumentMustNotHangDaemon() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); configureByText(JavaFileType.INSTANCE, "class X { void f() { } }"); assertEmpty(highlightErrors()); assertFalse(ApplicationManager.getApplication().isWriteAccessAllowed()); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/ImportHelperTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/ImportHelperTest.java index 8795f1ba1d8e0..2e62fdb3b4523 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/ImportHelperTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/ImportHelperTest.java @@ -45,6 +45,7 @@ import com.intellij.util.ExceptionUtil; import com.intellij.util.ThreeState; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import com.siyeh.ig.naming.ClassNamingConvention; @@ -111,7 +112,7 @@ protected void runTestRunnable(@NotNull ThrowableRunnable testRunnabl } public static void assertResolveNotCalledInEDTDuring(@NotNull BooleanSupplier isInsideResolve, @NotNull Runnable runnable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); AtomicBoolean resolveHappened = new AtomicBoolean(); // we run the test in EDT under this fake progress which is needed for one thing only: to be able to assert that no resolve happens in EDT. // Since resolve calls checkCanceled() a lot, we intercept these calls and check is we are being called from outside of EDT @@ -601,7 +602,7 @@ public void testAutoImportMustNotRunResolveInEDT() throws Exception { CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true; DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); doHighlighting(); assertOneImportAdded("java.util.ArrayList"); } @@ -614,7 +615,7 @@ public static boolean isFromJavaCodeReferenceElementResolve() { } public void testImportHintsMustBeComputedForAllUnresolvedReferencesInVisibleAreaToBeAbleToShowPopups() throws Exception { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); @Language("JAVA") @NonNls final String text = "class S {{ \n" + "new ArrayList();\n".repeat(1000) + diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/GlobalInspectionContextTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/GlobalInspectionContextTest.java index f46606ef02ad5..08ada297485d3 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/GlobalInspectionContextTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/GlobalInspectionContextTest.java @@ -21,6 +21,7 @@ import com.intellij.openapi.progress.util.ProgressWrapper; import com.intellij.psi.*; import com.intellij.testFramework.InspectionsKt; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.Nls; @@ -37,7 +38,7 @@ public class GlobalInspectionContextTest extends JavaCodeInsightTestCase { public void setUp() throws Exception { super.setUp(); InspectionProfileImpl.INIT_INSPECTIONS = true; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertFalse(ApplicationManager.getApplication().isWriteAccessAllowed()); } diff --git a/java/java-tests/testSrc/com/intellij/java/psi/search/ClassInheritorsTest.java b/java/java-tests/testSrc/com/intellij/java/psi/search/ClassInheritorsTest.java index cd91605c12506..3eee6e9bc342a 100644 --- a/java/java-tests/testSrc/com/intellij/java/psi/search/ClassInheritorsTest.java +++ b/java/java-tests/testSrc/com/intellij/java/psi/search/ClassInheritorsTest.java @@ -2,7 +2,6 @@ package com.intellij.java.psi.search; import com.intellij.concurrency.JobScheduler; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.progress.ProcessCanceledException; @@ -21,6 +20,7 @@ import com.intellij.testFramework.PsiTestUtil; import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; import com.intellij.util.CommonProcessors; +import com.intellij.util.concurrency.ThreadingAssertions; import java.io.IOException; import java.util.Collection; @@ -46,7 +46,7 @@ public void testClsAndSourcesDoNotMixUp() { } public void testStressInPresenceOfPCEs() { - ApplicationManager.getApplication().assertIsDispatchThread(); // no write action can go through while we test + ThreadingAssertions.assertEventDispatchThread(); // no write action can go through while we test int N = 1000; PsiClassOwner file0 = (PsiJavaFile)myFixture.addFileToProject("C0.java", "class C0 { }"); for (int i=1;i() } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/ReferenceImporter.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/ReferenceImporter.java index 86281d02d570f..61b2e931c791b 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/ReferenceImporter.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/ReferenceImporter.java @@ -7,6 +7,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.PsiFile; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -23,7 +24,7 @@ public interface ReferenceImporter { * (for example, in case of Java, the plugin added the corresponding import statement to this file, thus making this reference valid) */ default boolean autoImportReferenceAtCursor(@NotNull Editor editor, @NotNull PsiFile file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Future future = ApplicationManager.getApplication().executeOnPooledThread(() -> ReadAction.compute(() -> { if (editor.isDisposed() || file.getProject().isDisposed()) return null; int offset = editor.getCaretModel().getOffset(); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CanISilentlyChange.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CanISilentlyChange.java index 6dcc1773dd992..1473f31061595 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CanISilentlyChange.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CanISilentlyChange.java @@ -2,7 +2,6 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.ide.scratch.ScratchUtil; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.undo.UndoManager; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -11,6 +10,7 @@ import com.intellij.psi.PsiCodeFragment; import com.intellij.psi.PsiFileSystemItem; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; /** @@ -33,7 +33,7 @@ */ final class CanISilentlyChange { private static boolean canUndo(@NotNull VirtualFile virtualFile, @NotNull Project project) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(virtualFile); if (editors.length == 0) { return false; @@ -62,7 +62,7 @@ boolean canIReally(boolean isInContent, @NotNull ThreeState extensionsAllowToCha @NotNull static Result thisFile(@NotNull PsiFileSystemItem file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Project project = file.getProject(); VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java index 9deeb2241e462..6ad8c44bbdca1 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java @@ -22,6 +22,7 @@ import com.intellij.util.ObjectUtils; import com.intellij.util.ThreeState; import com.intellij.util.concurrency.EdtExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; @@ -124,7 +125,7 @@ static HighlightingSessionImpl createHighlightingSession(@NotNull PsiFile psiFil @Nullable EditorColorsScheme editorColorsScheme, @NotNull DaemonProgressIndicator progressIndicator, @NotNull Number daemonCancelEventCount) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); TextRange fileRange = psiFile.getTextRange(); ProperTextRange visibleRange; visibleRange = editor == null ? ProperTextRange.create(ObjectUtils.notNull(fileRange, TextRange.EMPTY_RANGE)) @@ -208,7 +209,7 @@ void addInfoIncrementally(@NotNull HighlightInfo info, @NotNull TextRange restri } void waitForHighlightInfosApplied() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (RunnableFuture request : pendingFileLevelHighlightRequests) { request.run(); } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java index 4358b061f0686..8689fc4a10882 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java @@ -6,7 +6,6 @@ import com.intellij.codeInsight.daemon.GutterMark; import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils; import com.intellij.lang.annotation.HighlightSeverity; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; @@ -25,6 +24,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.util.Consumer; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -109,7 +109,7 @@ public static void setHighlightersToSingleEditor(@NotNull Project project, @NotNull Collection highlights, @Nullable EditorColorsScheme colorsScheme, // if null, the global scheme will be used int group) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Document document = editor.getDocument(); MarkupModelEx markup = (MarkupModelEx)editor.getMarkupModel(); setHighlightersToEditor(project, document, startOffset, endOffset, highlights, colorsScheme, group, markup); @@ -122,7 +122,7 @@ public static void setHighlightersToEditor(@NotNull Project project, @NotNull Collection highlights, @Nullable EditorColorsScheme colorsScheme, // if null, the global scheme will be used int group) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); setHighlightersToEditor(project, document, startOffset, endOffset, highlights, colorsScheme, group, markup); } @@ -158,7 +158,7 @@ private static void setHighlightersInRange(@NotNull Document document, @NotNull MarkupModelEx markup, int group, @NotNull HighlightingSession session) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Project project = session.getProject(); PsiFile psiFile = session.getPsiFile(); SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project); @@ -401,7 +401,7 @@ static void clearWhiteSpaceOptimizationFlag(@NotNull Document document) { } static void updateHighlightersByTyping(@NotNull Project project, @NotNull DocumentEvent e) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Document document = e.getDocument(); if (document.isInBulkUpdate()) return; @@ -451,7 +451,7 @@ static void updateHighlightersByTyping(@NotNull Project project, @NotNull Docume */ public static void removeHighlightersWithExactRange(@NotNull Document document, @NotNull Project project, @NotNull Segment range) { if (IntentionPreviewUtils.isIntentionPreviewActive()) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); MarkupModel model = DocumentMarkupModel.forDocument(document, project, false); if (model == null) return; diff --git a/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java b/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java index 4dc92bdd1d87b..734f48bec195f 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java @@ -8,6 +8,7 @@ import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.registry.Registry; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NonNls; @@ -90,7 +91,7 @@ public void submitTransactionAndWait(final @NotNull Runnable runnable) throws Pr */ @ApiStatus.Internal public void performUserActivity(Runnable activity) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); performActivity(true, activity); } @@ -106,7 +107,7 @@ public void performActivity(boolean userActivity, @NotNull Runnable runnable) { return; } - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean prev = myWritingAllowed; myWritingAllowed = allowWriting; try { diff --git a/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java b/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java index c3962f5774745..897c6cf7422a5 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java +++ b/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java @@ -13,6 +13,7 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.util.Condition; import com.intellij.util.ExceptionUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectList; import org.jetbrains.annotations.*; @@ -29,12 +30,11 @@ final class FlushQueue { private final BulkArrayQueue myQueue = new BulkArrayQueue<>(); //guarded by getQueueLock() private void flushNow() { - ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - app.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); synchronized (getQueueLock()) { FLUSHER_SCHEDULED = false; } - + ApplicationEx app = ApplicationManagerEx.getApplicationEx(); long startTime = System.currentTimeMillis(); while (true) { RunnableInfo info = pollNextEvent(); @@ -165,7 +165,7 @@ private static void runNextEvent(@NotNull RunnableInfo info, @NotNull Applicatio } void reincludeSkippedItems() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); synchronized (getQueueLock()) { int size = mySkippedItems.size(); if (size != 0) { @@ -183,7 +183,7 @@ void reincludeSkippedItems() { } void purgeExpiredItems() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); synchronized (getQueueLock()) { reincludeSkippedItems(); myQueue.removeAll(info -> info.expired.value(null)); diff --git a/platform/core-impl/src/com/intellij/openapi/application/impl/LaterInvocator.java b/platform/core-impl/src/com/intellij/openapi/application/impl/LaterInvocator.java index 3dd969e8392d3..b8ba9477bc2a0 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/impl/LaterInvocator.java +++ b/platform/core-impl/src/com/intellij/openapi/application/impl/LaterInvocator.java @@ -13,6 +13,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.util.*; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; @@ -147,7 +148,7 @@ public static void enterModal(@NotNull Object modalEntity) { } public static void enterModal(@NotNull Object modalEntity, @NotNull ModalityStateEx appendedState) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (LOG.isDebugEnabled()) { LOG.debug("enterModal:" + modalEntity); @@ -169,7 +170,7 @@ public static void enterModal(@NotNull Object modalEntity, @NotNull ModalityStat } public static void enterModal(@NotNull Project project, @NotNull Dialog dialog) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (LOG.isDebugEnabled()) { LOG.debug("enterModal:" + dialog.getName() + " ; for project: " + project.getName()); @@ -196,13 +197,13 @@ public static void enterModal(@NotNull Project project, @NotNull Dialog dialog) @ApiStatus.ScheduledForRemoval @Deprecated public static void markTransparent(@NotNull ModalityState state) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ((ModalityStateEx)state).markTransparent(); reincludeSkippedItemsAndRequestFlush(); } public static void leaveModal(Project project, @NotNull Dialog dialog) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (LOG.isDebugEnabled()) { LOG.debug("leaveModal:" + dialog.getName() + " ; for project: " + project.getName()); @@ -243,7 +244,7 @@ private static void removeModality(@NotNull Object modalEntity, int index) { public static void leaveModal(@NotNull Object modalEntity) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (LOG.isDebugEnabled()) { LOG.debug("leaveModal:" + modalEntity); @@ -260,7 +261,7 @@ public static void leaveModal(@NotNull Object modalEntity) { @TestOnly public static void leaveAllModals() { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); while (!ourModalEntities.isEmpty()) { leaveModal(ourModalEntities.get(ourModalEntities.size() - 1)); } @@ -275,7 +276,7 @@ public static void leaveAllModals() { */ @ApiStatus.Internal public static void forceLeaveAllModals() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ModalityStateEx currentState = getCurrentModalityState(); if (currentState != ModalityState.nonModal()) { currentState.cancelAllEntities(); @@ -285,19 +286,19 @@ public static void forceLeaveAllModals() { } public static Object @NotNull [] getCurrentModalEntities() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return ArrayUtil.toObjectArray(ourModalEntities); } public static @NotNull ModalityStateEx getCurrentModalityState() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); synchronized (ourModalityStack) { return ourModalityStack.peek(); } } public static boolean isInModalContextForProject(@Nullable Project project) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (ourModalEntities.isEmpty()) return false; if (project == null) return true; @@ -338,10 +339,6 @@ private static boolean isAncestor(@NotNull Component ancestor, @Nullable Compone return false; } - private static void assertIsDispatchThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); - } - static boolean isFlushNow(@NotNull Runnable runnable) { return ourEdtQueue.isFlushNow(runnable); } @@ -356,12 +353,12 @@ public static void pollWriteThreadEventsOnce() { } private static void reincludeSkippedItemsAndRequestFlush() { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ourEdtQueue.reincludeSkippedItems(); } public static void purgeExpiredItems() { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ourEdtQueue.purgeExpiredItems(); } diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java index 7c66d71a6c3b6..7db1a4f50433f 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java @@ -40,6 +40,7 @@ import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.*; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.EdtInvocationManager; @@ -208,7 +209,7 @@ public Document getCachedDocument(@NotNull PsiFile file) { @Override public void commitAllDocuments() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ((TransactionGuardImpl)TransactionGuard.getInstance()).assertWriteActionAllowed(); if (myUncommittedDocuments.isEmpty()) return; @@ -297,7 +298,7 @@ public void performForCommittedDocument(@NotNull Document doc, @NotNull Runnable * @return true if action has been run immediately, or false if action was scheduled for execution later. */ public boolean cancelAndRunWhenAllCommitted(@NonNls @NotNull Object key, @NotNull Runnable action) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myProject.isDisposed()) { action.run(); return true; @@ -354,7 +355,7 @@ boolean finishCommit(@NotNull Document document, @NotNull Object reason) { assert !myProject.isDisposed() : "Already disposed"; if (isEventSystemEnabled(document)) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } boolean[] ok = {true}; if (synchronously) { @@ -384,7 +385,7 @@ protected boolean finishCommitInWriteAction(@NotNull Document document, @NotNull List reparseInjectedProcessors, boolean synchronously) { if (isEventSystemEnabled(document)) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } if (myProject.isDisposed()) return false; assert !(document instanceof DocumentWindow); @@ -592,7 +593,7 @@ public boolean performWhenAllCommitted(@NotNull Runnable action) { // return true when action is run, false when it's queued to run later private boolean performWhenAllCommitted(@NotNull ModalityState modality, @NotNull Runnable action) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertWeAreOutsideAfterCommitHandler(); assert !myProject.isDisposed() : "Already disposed: " + myProject; @@ -690,7 +691,7 @@ else if (isEventSystemEnabled(document)) { } private void runActionsWhenAllCommitted() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!mayRunActionsWhenAllCommitted()) return; List actions = new ArrayList<>(actionsWhenAllDocumentsAreCommitted.values()); beforeCommitHandler(); @@ -721,7 +722,7 @@ private void runActionsWhenAllCommitted() { } private boolean mayRunActionsWhenAllCommitted() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return !isCommitInProgress() && !actionsWhenAllDocumentsAreCommitted.isEmpty() && !hasEventSystemEnabledUncommittedDocuments(); @@ -735,7 +736,7 @@ public boolean hasEventSystemEnabledUncommittedDocuments() { } private void beforeCommitHandler() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); actionsWhenAllDocumentsAreCommitted.put(PERFORM_ALWAYS_KEY, EmptyRunnable.getInstance()); // to prevent listeners from registering new actions during firing } private void assertWeAreOutsideAfterCommitHandler() { @@ -745,7 +746,7 @@ private void assertWeAreOutsideAfterCommitHandler() { } private boolean isInsideCommitHandler() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return actionsWhenAllDocumentsAreCommitted.get(PERFORM_ALWAYS_KEY) == EmptyRunnable.getInstance(); } @@ -991,7 +992,7 @@ private void retainProviderAndCommitAsync(@NotNull Document document, @NotNull ModalityState modality) { FileViewProvider viewProvider = getCachedViewProvider(document); if (viewProvider != null && viewProvider.isEventSystemEnabled()) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); // make cached provider non-gcable temporarily (until commit end) to avoid surprising getCachedProvider()==null myDocumentCommitProcessor.commitAsynchronously(myProject, this, document, reason, modality, viewProvider); } diff --git a/platform/diff-impl/src/com/intellij/diff/impl/CacheDiffRequestProcessor.java b/platform/diff-impl/src/com/intellij/diff/impl/CacheDiffRequestProcessor.java index bf49db3a94178..b6b1585e3ba1e 100644 --- a/platform/diff-impl/src/com/intellij/diff/impl/CacheDiffRequestProcessor.java +++ b/platform/diff-impl/src/com/intellij/diff/impl/CacheDiffRequestProcessor.java @@ -25,7 +25,6 @@ import com.intellij.diff.util.DiffUserDataKeysEx.ScrollToPolicy; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; @@ -33,6 +32,7 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.UserDataHolder; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresEdt; import org.jetbrains.annotations.Nls; @@ -97,7 +97,7 @@ public void updateRequest(final boolean force, @Nullable final ScrollToPolicy sc @RequiresEdt public void updateRequest(final boolean force, boolean useCache, @Nullable final ScrollToPolicy scrollToChangePolicy) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; final T requestProvider = getCurrentRequestProvider(); diff --git a/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java b/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java index 225032d56ddef..8ae937cb47157 100644 --- a/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java +++ b/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java @@ -30,7 +30,6 @@ import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.actionSystem.impl.ActionButton; import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.DiffBundle; @@ -57,6 +56,7 @@ import com.intellij.ui.scale.JBUIScale; import com.intellij.util.EventDispatcher; import com.intellij.util.ObjectUtils; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBUI; @@ -373,7 +373,7 @@ protected void applyRequest(@NotNull DiffRequest request, boolean force, @Nullab @RequiresEdt protected void applyRequest(@NotNull DiffRequest request, boolean force, @Nullable ScrollToPolicy scrollToChangePolicy, boolean sync) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myIterationState = IterationState.NONE; force = force || (myQueuedApplyRequest != null && myQueuedApplyRequest.force); diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java b/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java index 8648a419ec20e..f7f81c1b56ccd 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java @@ -37,6 +37,7 @@ import com.intellij.util.Function; import com.intellij.util.SmartList; import com.intellij.util.concurrency.NonUrgentExecutor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; @@ -150,7 +151,7 @@ public void install(@Nullable final Data data, @Nullable final UserDataHolder context, @NotNull final Settings settings) { if (!myEnabled) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (FoldedBlock folding : getFoldedBlocks()) { folding.destroyHighlighter(); @@ -771,7 +772,7 @@ private FoldedGroupState getCachedState(int start, int end, int index) { @RequiresEdt public void updateContext(@NotNull UserDataHolder context, @NotNull final Settings settings) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myFoldings.isEmpty()) return; // do not rewrite cache by initial state context.putUserData(CACHE_KEY, getFoldingCache(settings)); } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/base/DiffViewerBase.java b/platform/diff-impl/src/com/intellij/diff/tools/util/base/DiffViewerBase.java index 6174667ff6a5b..691b1eba76340 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/base/DiffViewerBase.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/base/DiffViewerBase.java @@ -31,6 +31,7 @@ import com.intellij.pom.Navigatable; import com.intellij.util.Alarm; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.ui.UIUtil; @@ -103,7 +104,7 @@ public void hideNotify() { @RequiresEdt public final void dispose() { if (myDisposed) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); UIUtil.invokeLaterIfNeeded(() -> { if (myDisposed) return; diff --git a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index e01bbd81b1b33..847dd613cd448 100644 --- a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -34,6 +34,7 @@ import com.intellij.ui.components.JBLoadingPanel; import com.intellij.ui.table.JBTable; import com.intellij.util.TimeoutUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.StatusText; import org.jetbrains.annotations.Nls; @@ -629,7 +630,7 @@ public void performCopyTo(final DirDiffElementImpl element) { } protected void refreshAfterCopyTo(DirDiffElementImpl element, DiffElement newElement) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myDisposed) return; if (newElement == null && element.getTarget() != null) { final int row = myElements.indexOf(element); @@ -677,7 +678,7 @@ public void performCopyFrom(@NotNull DirDiffElementImpl element) { protected void refreshAfterCopyFrom(@NotNull DirDiffElementImpl element, DiffElement newElement) { if (myDisposed) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); refreshElementAfterCopyFrom(element, newElement); } diff --git a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/DocumentTracker.kt b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/DocumentTracker.kt index 1d1bad905bc2f..ef701fa7f4531 100644 --- a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/DocumentTracker.kt +++ b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/DocumentTracker.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vcs.ex.DocumentTracker.Block import com.intellij.openapi.vcs.ex.DocumentTracker.Handler +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.containers.PeekableIteratorWrapper import org.jetbrains.annotations.ApiStatus @@ -78,7 +79,7 @@ class DocumentTracker( @RequiresEdt override fun dispose() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isDisposed) return isDisposed = true diff --git a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt index 59416800a776f..6712a4f044dbe 100644 --- a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt +++ b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt @@ -20,6 +20,7 @@ import com.intellij.openapi.util.NlsContexts import com.intellij.openapi.vcs.ex.DocumentTracker.Block import com.intellij.openapi.vcs.ex.LineStatusTrackerBlockOperations.Companion.isSelectedByLine import com.intellij.openapi.vfs.VirtualFile +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import java.util.* @@ -72,7 +73,7 @@ abstract class LineStatusTrackerBase( @RequiresEdt protected open fun setBaseRevisionContent(vcsContent: CharSequence, beforeUnfreeze: (() -> Unit)?) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isReleased) return documentTracker.doFrozen(Side.LEFT) { @@ -91,7 +92,7 @@ abstract class LineStatusTrackerBase( @RequiresEdt fun dropBaseRevision() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isReleased || !isInitialized) return isInitialized = false diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/Editor.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/Editor.java index 9f5ec2eb9be7c..b7e968f640b92 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/Editor.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/Editor.java @@ -3,7 +3,6 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.EditorFontType; import com.intellij.openapi.editor.event.EditorMouseEventArea; @@ -16,6 +15,7 @@ import com.intellij.openapi.util.ProperTextRange; import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -421,7 +421,7 @@ default int getAscent() { * Can only be called from the EDT. */ default @NotNull ProperTextRange calculateVisibleRange() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Rectangle rect = getScrollingModel().getVisibleArea(); LogicalPosition startPosition = xyToLogicalPosition(new Point(rect.x, rect.y)); int visibleStart = logicalPositionToOffset(startPosition); diff --git a/platform/elevation/src/com/intellij/execution/process/elevation/settings/ElevationSettings.kt b/platform/elevation/src/com/intellij/execution/process/elevation/settings/ElevationSettings.kt index 88e10768de191..e4b0667d2873a 100644 --- a/platform/elevation/src/com/intellij/execution/process/elevation/settings/ElevationSettings.kt +++ b/platform/elevation/src/com/intellij/execution/process/elevation/settings/ElevationSettings.kt @@ -11,6 +11,7 @@ import com.intellij.openapi.ui.MessageDialogBuilder import com.intellij.openapi.ui.Messages.CANCEL import com.intellij.openapi.ui.Messages.YES import com.intellij.openapi.util.SystemInfo +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.messages.Topic import kotlin.time.Duration.Companion.minutes @@ -81,7 +82,7 @@ class ElevationSettings : PersistentStateComponentWithModificationTracker) -> Unit) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() assert(ApplicationManager.getApplication().isUnitTestMode) for (operationsState in operationsStates) { stateConsumer.invoke(operationsState) diff --git a/platform/ide-core-impl/src/com/intellij/ide/impl/DataManagerImpl.java b/platform/ide-core-impl/src/com/intellij/ide/impl/DataManagerImpl.java index 242f0e1f41053..8a571ea6fe4f2 100644 --- a/platform/ide-core-impl/src/com/intellij/ide/impl/DataManagerImpl.java +++ b/platform/ide-core-impl/src/com/intellij/ide/impl/DataManagerImpl.java @@ -24,6 +24,7 @@ import com.intellij.openapi.wm.impl.FloatingDecoratorMarker; import com.intellij.util.KeyedLazyInstance; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.ApiStatus; @@ -258,7 +259,7 @@ else if (component instanceof JComponent) { @Override public @NotNull DataContext getDataContext(Component component) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (ourGetDataLevel.get()[0] > 0) { LOG.error("DataContext shall not be created and queried inside another getData() call."); } diff --git a/platform/ide-core/src/com/intellij/util/Alarm.java b/platform/ide-core/src/com/intellij/util/Alarm.java index 55901a07f67fc..13be9d580ca19 100644 --- a/platform/ide-core/src/com/intellij/util/Alarm.java +++ b/platform/ide-core/src/com/intellij/util/Alarm.java @@ -177,13 +177,13 @@ public void addRequest(@NotNull Runnable request, int delayMillis) { } public void addComponentRequest(@NotNull Runnable request, int delayMillis) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert myActivationComponent != null; _addRequest(request, delayMillis, ModalityState.stateForComponent(myActivationComponent)); } public void addComponentRequest(@NotNull Runnable request, long delayMillis) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert myActivationComponent != null; _addRequest(request, delayMillis, ModalityState.stateForComponent(myActivationComponent)); } @@ -220,7 +220,7 @@ else if (!myPendingRequests.contains(requestToSchedule)) { } private boolean isActivationComponentShowing() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert myActivationComponent != null; return myActivationComponent.isShowing(); } @@ -429,7 +429,7 @@ public String toString() { @Deprecated(forRemoval = true) public @NotNull Alarm setActivationComponent(@NotNull JComponent component) { PluginException.reportDeprecatedUsage("Alarm#setActivationComponent", "Please use `#Alarm(JComponent, Disposable)` instead"); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myActivationComponent = component; //noinspection ResultOfObjectAllocationIgnored UiNotifyConnector.installOn(component, new Activatable() { diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingPanel.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingPanel.kt index 79f56102e8e81..86e268c3ae6b4 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingPanel.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingPanel.kt @@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.Alarm.ThreadToUse import com.intellij.util.SingleAlarm import com.intellij.util.concurrency.AppExecutorUtil +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.tree.TreeUtil import org.jetbrains.annotations.Nls import org.jetbrains.concurrency.CancellablePromise @@ -37,7 +38,7 @@ class HighlightingPanel(project: Project, state: ProblemsViewState) private var previousStatus: Status? = null init { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() tree.showsRootHandles = false project.messageBus.connect(this) .subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, this) diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemsView.java b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemsView.java index 76a2094eaed19..260795fcff213 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemsView.java +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemsView.java @@ -21,6 +21,7 @@ import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.ContentManagerEvent; import com.intellij.ui.content.ContentManagerListener; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -140,7 +141,7 @@ public static void removePanel(Project project, String id) { @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow window) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ProblemsViewState state = ProblemsViewState.getInstance(project); state.setShowToolbar(ToggleToolbarAction.isToolbarVisible(window, project)); ContentManager manager = window.getContentManager(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupControllerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupControllerImpl.java index d83493ac68f80..3fbda2881018c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupControllerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupControllerImpl.java @@ -25,6 +25,7 @@ import com.intellij.testFramework.TestModeFlags; import com.intellij.util.Alarm; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -114,7 +115,7 @@ public void cancelAllRequests() { public void autoPopupParameterInfo(@NotNull final Editor editor, @Nullable final PsiElement highlightedMethod) { if (PowerSaveMode.isEnabled()) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final CodeInsightSettings settings = CodeInsightSettings.getInstance(); if (settings.AUTO_POPUP_PARAMETER_INFO) { AtomicInteger offset = new AtomicInteger(-1); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java index 15ac6cadcbbbc..5be743cc0ac2a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java @@ -20,6 +20,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.codeStyle.CoreCodeStyleUtil; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -88,7 +89,7 @@ protected FutureTask prepareTask(@NotNull PsiFile file, boolean process ? Collections.emptyList() : collectAutoImports(file); return new FutureTask<>(() -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); CoreCodeStyleUtil.setSequentialProcessingAllowed(false); try { for (Runnable runnable : runnables) { @@ -141,7 +142,7 @@ public void visitElement(@NotNull PsiElement element) { } private static void fixAllImportsSilently(@NotNull PsiFile file, @NotNull List actions) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (actions.isEmpty()) return; Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document == null) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeVision/EditorCodeVisionContext.kt b/platform/lang-impl/src/com/intellij/codeInsight/codeVision/EditorCodeVisionContext.kt index 5a74cfd9e1819..d2fe50e60c98e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/codeVision/EditorCodeVisionContext.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeVision/EditorCodeVisionContext.kt @@ -2,7 +2,6 @@ package com.intellij.codeInsight.codeVision import com.intellij.codeInsight.codeVision.ui.CodeVisionView -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.logger @@ -13,6 +12,7 @@ import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.rd.createLifetime import com.intellij.openapi.util.Key import com.intellij.openapi.util.TextRange +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.jetbrains.rd.util.first import com.jetbrains.rd.util.lifetime.SequentialLifetimes @@ -52,7 +52,7 @@ open class EditorCodeVisionContext( @RequiresEdt fun notifyPendingLenses() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (!hasPendingLenses) { LOG.trace("Have pending lenses") } @@ -66,7 +66,7 @@ open class EditorCodeVisionContext( @RequiresEdt fun setResults(lenses: List>) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() LOG.trace("Have new frontend lenses ${lenses.size}") frontendResults.forEach { it.dispose() } frontendResults = lenses.mapNotNull { (range, entry) -> diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/CodeVisionView.kt b/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/CodeVisionView.kt index c28cfb70c2810..b379da2b1f397 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/CodeVisionView.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/CodeVisionView.kt @@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.rd.createLifetime import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.TextRange -import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.lifetime.LifetimeDefinition import com.jetbrains.rd.util.lifetime.isAlive @@ -42,7 +42,7 @@ class CodeVisionView(val project: Project) { private fun isLensValid(lenses: Map>): Boolean = lenses.values.any { it.isNotEmpty() } fun runWithReusingLenses(action: () -> Unit) { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() usingTrueFlag(CodeVisionView::delayInlayRemoval) { //inlaysToDelete are filled here in action() method action() diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/popup/layouter/EditorAnchoringRect.kt b/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/popup/layouter/EditorAnchoringRect.kt index 2e961ab6a9bdc..c4e8ba34c512c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/popup/layouter/EditorAnchoringRect.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/popup/layouter/EditorAnchoringRect.kt @@ -10,7 +10,7 @@ import com.intellij.openapi.editor.event.VisibleAreaListener import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.rd.createLifetime import com.intellij.openapi.util.TextRange -import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.JBUI import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.lifetime.intersect @@ -94,7 +94,7 @@ class EditorAnchoringRect( } private fun calculateRectangle(): Rectangle? { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() require(!editor.isDisposed) val range = if (rangeMarker.isValid) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 9a4da6508aa2b..d192e45a67b6c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -58,6 +58,7 @@ import com.intellij.util.ObjectUtils; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.indexing.DumbModeAccessType; import com.intellij.util.messages.SimpleMessageBusConnection; import com.intellij.util.ui.update.MergingUpdateQueue; @@ -162,7 +163,7 @@ public void lookupCanceled(@NotNull final LookupEvent event) { myQueue = new MergingUpdateQueue("completion lookup progress", ourShowPopupAfterFirstItemGroupingTime, true, myEditor.getContentComponent()); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (hasModifiers && !ApplicationManager.getApplication().isUnitTestMode()) { trackModifiers(); @@ -370,7 +371,7 @@ void withSingleUpdate(Runnable action) { } private void updateLookup() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isOutdated() || !shouldShowLookup()) return; while (true) { @@ -505,7 +506,7 @@ public void closeAndFinish(boolean hideLookup) { private void finishCompletionProcess(boolean disposeOffsetMap) { cancel(); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Disposer.dispose(myQueue); LookupManager.getInstance(getProject()).removePropertyChangeListener(myLookupManagerListener); @@ -747,7 +748,7 @@ public static boolean shouldRestartCompletion(@NotNull Editor editor, @Override public void scheduleRestart() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myHandler.isTestingMode() && !TestModeFlags.is(CompletionAutoPopupHandler.ourTestingAutopopup)) { closeAndFinish(false); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java index 677c9121ee16e..558423fae804e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java @@ -25,6 +25,7 @@ import com.intellij.psi.Weigher; import com.intellij.util.Consumer; import com.intellij.util.ExceptionUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.SimpleMessageBusConnection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,7 +68,7 @@ public void dispose() { public void setCompletionPhase(@NotNull CompletionPhase phase) { // wrap explicitly with client id for the case when some called API depends on ClientId.current try (AccessToken ignored = ClientId.withClientId(myAppSession.getClientId())) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); CompletionPhase oldPhase = getCompletionPhase(); CompletionProgressIndicator oldIndicator = oldPhase.indicator; if (oldIndicator != null && 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 b2d3b743f1e2b..600766dc0e2b4 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,6 +66,7 @@ import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.*; import com.intellij.util.concurrency.EdtExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.gist.GistManager; import com.intellij.util.gist.GistManagerImpl; @@ -210,7 +211,7 @@ private void assertMyFile(@NotNull Project project, @NotNull PsiFile file) { @Override public void cleanFileLevelHighlights(int group, @NotNull PsiFile psiFile) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertMyFile(psiFile.getProject(), psiFile); VirtualFile vFile = BackedVirtualFile.getOriginFileIfBacked(psiFile.getViewProvider().getVirtualFile()); for (FileEditor fileEditor : getFileEditorManager().getAllEditors(vFile)) { @@ -237,14 +238,14 @@ public boolean hasFileLevelHighlights(int group, @NotNull PsiFile psiFile) { private static final int ANY_GROUP = -409423948; void cleanAllFileLevelHighlights() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (FileEditor fileEditor : getFileEditorManager().getAllEditors()) { cleanFileLevelHighlights(fileEditor, ANY_GROUP); } } private void cleanFileLevelHighlights(@NotNull FileEditor fileEditor, int group) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); List infos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS); if (infos == null || infos.isEmpty()) { return; @@ -270,7 +271,7 @@ private void cleanFileLevelHighlights(@NotNull FileEditor fileEditor, int group) @Override public void addFileLevelHighlight(int group, @NotNull HighlightInfo info, @NotNull PsiFile psiFile) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertMyFile(psiFile.getProject(), psiFile); VirtualFile vFile = BackedVirtualFile.getOriginFileIfBacked(psiFile.getViewProvider().getVirtualFile()); FileEditorManager fileEditorManager = getFileEditorManager(); @@ -368,7 +369,7 @@ public void runPasses(@NotNull PsiFile file, int @NotNull [] passesToIgnore, boolean canChangeDocument, @Nullable Runnable callbackWhileWaiting) throws ProcessCanceledException { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert !myDisposed; assertMyFile(file.getProject(), file); assert textEditor.getEditor().getDocument() == document : "Expected document "+document+" but one of the passed TextEditors points to a different document: "+textEditor.getEditor().getDocument(); @@ -487,7 +488,7 @@ private void doRunPasses(@NotNull TextEditor textEditor, @TestOnly private void waitInOtherThread(int millis, boolean canChangeDocument, @NotNull ThrowableComputable runWhile) throws Throwable { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Disposable disposable = Disposer.newDisposable(); AtomicBoolean assertOnModification = new AtomicBoolean(); // last hope protection against PsiModificationTrackerImpl.incCounter() craziness (yes, Kotlin) @@ -575,7 +576,7 @@ public synchronized void setUpdateByTimerEnabled(boolean value) { public void disableUpdateByTimer(@NotNull Disposable parentDisposable) { setUpdateByTimerEnabled(false); myDisableCount.incrementAndGet(); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Disposer.register(parentDisposable, () -> { if (myDisableCount.decrementAndGet() == 0) { @@ -710,7 +711,7 @@ public synchronized boolean isRunning() { @TestOnly public boolean isRunningOrPending() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return isRunning() || !myUpdateRunnableFuture.isDone() || GeneralHighlightingPass.isRestartPending(); } @@ -953,7 +954,7 @@ private void clearFieldsOnDispose() { } private static void runUpdate(@Nullable Project project, @NotNull UpdateRunnable updateRunnable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); DaemonCodeAnalyzerImpl dca; if (project == null || project.isDefault() || @@ -1046,7 +1047,7 @@ private HighlightingSession queuePassesCreation(@NotNull FileEditor fileEditor, @NotNull VirtualFile virtualFile, @NotNull PsiFile psiFile, int @NotNull [] passesToIgnore) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); BackgroundEditorHighlighter highlighter; try (AccessToken ignored = ClientId.withClientId(ClientFileEditorManager.getClientId(fileEditor))) { @@ -1223,7 +1224,7 @@ public void autoImportReferenceAtCursor(@NotNull Editor editor, @NotNull PsiFile private @NotNull Collection getSelectedEditors() { Application application = ApplicationManager.getApplication(); - application.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); // editors in modal context List editors = EditorTracker.getInstance(myProject).getActiveEditors(); @@ -1271,7 +1272,7 @@ private static boolean isInActiveProject(@NotNull FileEditor editor) { */ @ApiStatus.Internal public void serializeCodeInsightPasses(boolean flag) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); setUpdateByTimerEnabled(false); try { cancelAllUpdateProgresses(false, "serializeCodeInsightPasses"); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index dc652ea312790..c83923f3fbfbc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -75,6 +75,7 @@ import com.intellij.ui.AppUIUtil; import com.intellij.util.KeyedLazyInstance; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.io.storage.HeavyProcessLatch; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.SimpleMessageBusConnection; @@ -505,7 +506,7 @@ public void dispose() { */ public static boolean canChangeFileSilently(@NotNull PsiFileSystemItem file, boolean isInContent, @NotNull ThreeState extensionsAllowToChangeFileSilently) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Project project = file.getProject(); DaemonListeners listeners = getInstance(project); if (listeners == null) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java index 2107da3dd19be..a283342733f85 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java @@ -23,6 +23,7 @@ import com.intellij.psi.PsiFile; import com.intellij.util.Alarm; import com.intellij.util.SlowOperations; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,7 +63,7 @@ public void highlightsInsideVisiblePartAreProduced(@NotNull HighlightingSession private static void showAutoImportHints(@NotNull ProgressIndicator progressIndicator, @Nullable TextEditorHighlightingPass showAutoImportPass) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (showAutoImportPass != null) { ProgressManager.getInstance().executeProcessUnderProgress(() -> showAutoImportPass.doApplyInformationToEditor(), progressIndicator); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ErrorStripeUpdateManager.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ErrorStripeUpdateManager.java index 3c0ef90a3d6e6..b1928cfdffb65 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ErrorStripeUpdateManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ErrorStripeUpdateManager.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.registry.RegistryValueListener; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +55,7 @@ public void dispose() { } public void repaintErrorStripePanel(@NotNull Editor editor, @Nullable PsiFile psiFile) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myProject.isInitialized()) return; EditorMarkupModel markup = (EditorMarkupModel) editor.getMarkupModel(); @@ -67,7 +68,7 @@ public void repaintErrorStripePanel(@NotNull Editor editor, @Nullable PsiFile ps } void setOrRefreshErrorStripeRenderer(@NotNull EditorMarkupModel editorMarkupModel, @NotNull PsiFile file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!editorMarkupModel.isErrorStripeVisible()) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java index 212d866f736da..7fa443e46fe74 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java @@ -13,6 +13,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiFile; import com.intellij.testFramework.TestModeFlags; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -39,7 +40,7 @@ public static boolean isEnabled() { @TestOnly public static void doWithHighlightingEnabled(@NotNull Project project, @NotNull Disposable parentDisposable, @NotNull Runnable r) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); BackgroundHighlightingUtil.enableListenersInTest(project, parentDisposable); TestModeFlags.set(ourTestingIdentifierHighlighting, true); try { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java index b8576300bcc5c..3badd9c1b8154 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java @@ -16,6 +16,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -130,7 +131,7 @@ public void dispose() { } private void scheduleRendererUpdate(@NotNull Editor editor, @NotNull Inlay inlay) { - ApplicationManager.getApplication().assertIsDispatchThread(); // to avoid race conditions in "new AnimationStep" + ThreadingAssertions.assertEventDispatchThread(); // to avoid race conditions in "new AnimationStep" AnimationStep step = editor.getUserData(ANIMATION_STEP); if (step == null) { editor.putUserData(ANIMATION_STEP, step = new AnimationStep(editor)); @@ -146,7 +147,7 @@ private void scheduleAnimationStep(@NotNull AnimationStep step) { @TestOnly public boolean isAnimationInProgress(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return editor.getUserData(ANIMATION_STEP) != null; } 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 aecab0c4fd189..de86d827b2f88 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 @@ -31,6 +31,7 @@ import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.SlowOperations; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -119,7 +120,7 @@ public void doApplyInformationToEditor() { } private void importUnambiguousImports() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!mayAutoImportNow(myFile, true, ThreeState.UNSURE)) return; for (BooleanSupplier autoImportAction : autoImportActions) { autoImportAction.getAsBoolean(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java index 0f862343f9afa..9799f258bb318 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInsight.daemon.impl; import com.intellij.codeHighlighting.TextEditorHighlightingPass; @@ -13,7 +13,6 @@ import com.intellij.lang.Language; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ex.EditorEx; @@ -31,6 +30,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtilBase; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.CommonProcessors; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import kotlin.sequences.SequencesKt; import org.jetbrains.annotations.ApiStatus; @@ -253,7 +253,7 @@ public void doCollectInformation(@NotNull ProgressIndicator progress) { @Override public void doApplyInformationToEditor() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); CachedIntentions cachedIntentions = myCachedIntentions; boolean actionsChanged = myActionsChanged; @@ -287,7 +287,7 @@ public void doApplyInformationToEditor() { */ @ApiStatus.Internal public static void getActionsToShowSync(@NotNull Editor hostEditor, @NotNull PsiFile hostFile, @NotNull IntentionsInfo intentions) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); EditorNotificationActions.collectActions(hostEditor, intentions); intentions.filterActions(hostFile); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java index fbb4a077df18d..b7310d21110e1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java @@ -8,7 +8,6 @@ import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.DumbAwareAction; @@ -22,6 +21,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.util.PsiUtilBase; import com.intellij.ui.content.*; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.Activatable; import com.intellij.util.ui.update.UiNotifyConnector; @@ -258,11 +258,11 @@ void restartAutoUpdate(final boolean state) { } public void muteAutoUpdateTill(@NotNull Disposable disposable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myAutoUpdateMuted = true; resetAutoUpdateState(); Disposer.register(disposable, () -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myAutoUpdateMuted = false; resetAutoUpdateState(); }); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderManager.java index f79fca36613a1..c032b417c61f1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderManager.java @@ -3,7 +3,6 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.ClientEditorManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorKind; @@ -11,6 +10,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.util.Key; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,7 +24,7 @@ public final class DocRenderManager { * the global setting again. */ public static void setDocRenderingEnabled(@NotNull Editor editor, @Nullable Boolean value) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean enabledBefore = isDocRenderingEnabled(editor); editor.putUserData(DOC_RENDER_ENABLED, value); boolean enabledAfter = isDocRenderingEnabled(editor); @@ -54,7 +54,7 @@ public static boolean isDocRenderingEnabled(@NotNull Editor editor) { * @see #isDocRenderingEnabled(Editor) */ public static void resetAllEditorsToDefaultState() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (Editor editor : ClientEditorManager.getCurrentInstance().editors().toList()) { DocRenderItemManager.getInstance().resetToDefaultState(editor); DocRenderPassFactory.forceRefreshOnNextPass(editor); @@ -70,7 +70,7 @@ public static void resetAllEditorsToDefaultState() { * @see #isDocRenderingEnabled(Editor) */ public static void resetEditorToDefaultState(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); DocRenderItemManager.getInstance().resetToDefaultState(editor); DocRenderPassFactory.forceRefreshOnNextPass(editor); Project project = editor.getProject(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java index 96b19c3b4a3f2..9dc2d9f739793 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java @@ -30,6 +30,7 @@ import com.intellij.psi.PsiFile; import com.intellij.util.KeyedLazyInstance; import com.intellij.util.SlowOperations; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.WeakList; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -95,7 +96,7 @@ public void dispose() { @Override public void releaseFoldings(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); EditorFoldingInfo.disposeForEditor(editor); } @@ -138,7 +139,7 @@ public CodeFoldingState buildInitialFoldings(@NotNull final Document document) { List regionInfos = FoldingUpdate.getFoldingsFor(file, true); return editor -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myProject.isDisposed() || editor.isDisposed()) return; final FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); if (!foldingModel.isFoldingEnabled()) return; @@ -233,7 +234,7 @@ private Runnable updateFoldRegions(@NotNull Editor editor, boolean applyDefaultS @Override public CodeFoldingState saveFoldingState(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); DocumentFoldingInfo info = getDocumentFoldingInfo(editor.getDocument()); if (isFoldingsInitializedInEditor(editor)) { info.loadFromEditor(editor); @@ -243,7 +244,7 @@ public CodeFoldingState saveFoldingState(@NotNull Editor editor) { @Override public void restoreFoldingState(@NotNull Editor editor, @NotNull CodeFoldingState state) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isFoldingsInitializedInEditor(editor)) { state.setToEditor(editor); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java index 9c428712b3de2..6ae4211d914ca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java @@ -26,6 +26,7 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.formatter.WhiteSpaceFormattingStrategy; import com.intellij.psi.formatter.WhiteSpaceFormattingStrategyFactory; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.StringTokenizer; import com.intellij.xml.util.XmlStringUtil; @@ -58,7 +59,7 @@ final class DocumentFoldingInfo implements CodeFoldingState { } void loadFromEditor(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LOG.assertTrue(!editor.isDisposed()); clear(); @@ -86,7 +87,7 @@ void loadFromEditor(@NotNull Editor editor) { @Override public void setToEditor(@NotNull final Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final PsiManager psiManager = PsiManager.getInstance(myProject); if (psiManager.isDisposed()) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java index dc253bd5329ad..c226f7144b840 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java @@ -36,6 +36,7 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.util.Alarm; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -158,7 +159,7 @@ private void submitUpdateHighlighted(@NotNull Project project, @NotNull Editor e } private void updateHighlighted(@NotNull Project project, @NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (editor.getDocument().isInBulkUpdate()) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlightingUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlightingUtil.java index 3b09867cc3d16..5d57f52929fca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlightingUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlightingUtil.java @@ -7,7 +7,6 @@ import com.intellij.injected.editor.EditorWindow; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.editor.Editor; @@ -22,6 +21,7 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.util.TriConsumer; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -38,7 +38,7 @@ static void lookForInjectedFileInOtherThread(@NotNull Project project, @NotNull Editor editor, @NotNull BiFunction backgroundProcessor, @NotNull TriConsumer edtProcessor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert !(editor instanceof EditorWindow) : editor; if (!isValidEditor(editor)) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java index f97d6004cf895..43af4758d9ad0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java @@ -7,7 +7,6 @@ import com.intellij.codeInsight.hint.EditorFragmentComponent; import com.intellij.injected.editor.EditorWindow; import com.intellij.lang.Language; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.editor.Document; @@ -36,6 +35,7 @@ import com.intellij.psi.util.PsiUtilCore; import com.intellij.ui.LightweightHint; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; @@ -112,7 +112,7 @@ public int getEnd() { } void updateBraces() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); clearBraceHighlighters(); @@ -389,7 +389,7 @@ public static void lineMarkFragment(@NotNull EditorEx editor, @NotNull Document } private static void removeLineMarkers(@NotNull EditorEx editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); RangeHighlighter marker = editor.getUserData(LINE_MARKER_IN_EDITOR_KEY); if (marker != null && editor.getMarkupModel().containsHighlighter(marker)) { marker.dispose(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java index ee5c025fe9471..bbbc8d65b8fd4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java @@ -11,7 +11,6 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.actionSystem.Shortcut; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.SelectionModel; @@ -33,6 +32,7 @@ import com.intellij.pom.PsiDeclaredTarget; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtilBase; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -92,7 +92,7 @@ private static void handleNoUsageTargets(@NotNull PsiFile file, @Nullable public static HighlightUsagesHandlerBase createCustomHandler(@NotNull Editor editor, @NotNull PsiFile file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ProperTextRange visibleRange = editor.calculateVisibleRange(); return createCustomHandler(editor, file, visibleRange); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoControllerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoControllerBase.java index 3da209e61aefb..cbb40c99ca982 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoControllerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoControllerBase.java @@ -29,6 +29,7 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.ui.UIUtil; @@ -109,7 +110,7 @@ public ParameterInfoControllerBase(@NotNull Project project, PsiElement parameterOwner, @NotNull ParameterInfoHandler handler, boolean showHint) { - ApplicationManager.getApplication().assertIsDispatchThread(); // DEXP-575205 + ThreadingAssertions.assertEventDispatchThread(); // DEXP-575205 myProject = project; myEditor = editor; @@ -521,7 +522,7 @@ public UserDataHolderEx getCustomContext() { } public void applyUIChanges() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (int index = 0, len = getObjects().length; index < len; index++) { boolean enabled = isUIComponentEnabled(index); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowExpressionTypeHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowExpressionTypeHandler.java index 4fd3627ba1b3a..baedaef503d0b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowExpressionTypeHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowExpressionTypeHandler.java @@ -26,6 +26,7 @@ import com.intellij.refactoring.IntroduceTargetChooser; import com.intellij.ui.LightweightHint; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.JBIterable; import com.intellij.util.ui.accessibility.AccessibleContextUtil; @@ -51,7 +52,7 @@ public boolean startInWriteAction() { @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset()); final Set handlers = getHandlers(project, language, file.getViewProvider().getBaseLanguage()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java index c40d8a1f5ae1b..ab6964172e9f2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java @@ -55,6 +55,7 @@ import com.intellij.util.ObjectUtils; import com.intellij.util.ThreeState; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.EmptyIcon; @@ -750,7 +751,7 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { } Disposer.register(popup, popup.myListPopup); - Disposer.register(popup.myListPopup, ApplicationManager.getApplication()::assertIsDispatchThread); + Disposer.register(popup.myListPopup, ThreadingAssertions::assertEventDispatchThread); } private static void highlightOnHover(@NotNull IntentionActionWithTextCaching actionWithCaching, @NotNull HighlightingContext context, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index f1027826666a0..4cf0332d0dc30 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -59,6 +59,7 @@ import com.intellij.util.PairProcessor; import com.intellij.util.SlowOperations; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -145,7 +146,7 @@ private static void showEmptyMenuFeedback(@NotNull Editor editor, boolean showFe public static @NotNull ShowIntentionsPass.IntentionsInfo calcIntentions(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (ApplicationManager.getApplication().isWriteAccessAllowed()) { throw new IllegalStateException("must not wait for intentions inside write action"); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index d053dd03419d3..c1265c59a19c8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -51,6 +51,7 @@ import com.intellij.ui.scale.JBUIScale; import com.intellij.util.CollectConsumer; import com.intellij.util.ExceptionUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.*; import com.intellij.util.ui.accessibility.AccessibleContextUtil; @@ -210,7 +211,7 @@ public void setCalculating(boolean calculating) { public void markSelectionTouched() { if (!ApplicationManager.getApplication().isUnitTestMode()) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } mySelectionTouched = true; myList.repaint(); @@ -299,7 +300,7 @@ public void updateLookupWidth() { } public void requestResize() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myResizePending = true; } @@ -415,7 +416,7 @@ void moveToCaretPosition() { private boolean updateList(boolean onExplicitAction, boolean reused) { if (!ApplicationManager.getApplication().isUnitTestMode()) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } checkValid(); @@ -679,13 +680,13 @@ public boolean isAvailableToUser() { @Override public boolean isShown() { if (!ApplicationManager.getApplication().isUnitTestMode()) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } return myShown; } public boolean showLookup() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); checkValid(); LOG.assertTrue(!myShown); myShown = true; @@ -1095,7 +1096,7 @@ public int getLastVisibleIndex() { } public List getVisibleItems() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); var itemsCount = myList.getItemsCount(); if (!myShown || itemsCount == 0) return Collections.emptyList(); @@ -1122,7 +1123,7 @@ public void hide(){ @Override public void hideLookup(boolean explicitly) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myHidden) return; @@ -1165,7 +1166,7 @@ protected void onPopupCancel() { @Override public void dispose() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert myHidden; myOffsets.disposeMarkers(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java index 1edfd4b9b2eb3..42fef9afe0b94 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java @@ -6,7 +6,6 @@ import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.lookup.*; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -18,6 +17,7 @@ import com.intellij.openapi.util.Key; import com.intellij.ui.LightweightHint; import com.intellij.util.BitUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -115,7 +115,7 @@ public LookupImpl createLookup(@NotNull final Editor editor, final LookupImpl lookup = createLookup(editor, arranger, myProject); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myActiveLookup = lookup; myActiveLookupEditor = editor; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTaskBase.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTaskBase.java index 411a96f37532b..7c93c52f67d37 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTaskBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTaskBase.java @@ -1,7 +1,6 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.navigation; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.progress.ProgressIndicator; @@ -17,6 +16,7 @@ import com.intellij.usages.impl.UsageViewImpl; import com.intellij.util.Alarm; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -129,7 +129,7 @@ public boolean updateComponent(@NotNull T element) { } private void refreshModelImmediately() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myCanceled) return; if (myPopup.isDisposed()) return; List data; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java index 612186ab27f3d..7431f2bddfada 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java @@ -16,7 +16,6 @@ import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -34,6 +33,7 @@ import com.intellij.psi.PsiReference; import com.intellij.psi.search.PsiElementProcessor; import com.intellij.ui.awt.RelativePoint; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -69,7 +69,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { } static @NotNull List<@NotNull EventPair> getCurrentEventData() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return Objects.requireNonNull(ourCurrentEventData); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java index 31fa9f93ad870..9f88d8c382619 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java @@ -32,6 +32,7 @@ import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.templateLanguages.TemplateLanguageUtil; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -114,7 +115,7 @@ public boolean supportsMultiCaret() { @Override public void expand(@NotNull final String key, @NotNull final CustomTemplateCallback callback) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = callback.getEditor(); PsiFile file = callback.getContext().getContainingFile(); @@ -138,7 +139,7 @@ public static void expandTemplate(@NotNull String key, @NotNull Editor editor, @NotNull PostfixTemplateProvider provider, @NotNull PostfixTemplate postfixTemplate) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.postfix"); final PsiFile file = callback.getContext().getContainingFile(); if (isApplicableTemplate(provider, key, file, editor, postfixTemplate)) { @@ -251,7 +252,7 @@ private static void expandTemplate(@NotNull final PostfixTemplate template, private static int deleteTemplateKey(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final String key) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final int currentOffset = editor.getCaretModel().getOffset(); final int newOffset = currentOffset - key.length(); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index aaf0b1ccfed1d..3069da5449d6e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -78,6 +78,7 @@ import com.intellij.ui.content.ContentManager; import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import io.opentelemetry.api.trace.Span; @@ -239,7 +240,7 @@ protected void launchInspections(@NotNull AnalysisScope scope) { protected void notifyInspectionsFinished(@NotNull AnalysisScope scope) { //noinspection TestOnlyProblems if (ApplicationManager.getApplication().isUnitTestMode() && !TESTING_VIEW) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); long elapsed = System.currentTimeMillis() - myInspectionStartedTimestamp; runToolsSpan.end(); LOG.info("Code inspection finished. Took " + elapsed + " ms"); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index 0541bc4c19e07..bf3f4592304eb 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -55,6 +55,7 @@ import com.intellij.util.Alarm; import com.intellij.util.ThreeState; import com.intellij.util.concurrency.SequentialTaskExecutor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.EdtInvocationManager; import com.intellij.util.ui.JBUI; @@ -644,7 +645,7 @@ void addProblemDescriptors(InspectionToolWrapper wrapper, RefEntity refElem } public void update() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Collection tools = new ArrayList<>(myGlobalInspectionContext.getTools().values()); updateTree(() -> updateResults(tools)); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java index eadb5a38e13bd..ca6686ccd486d 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -37,6 +37,7 @@ import com.intellij.ui.treeStructure.Tree; import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.containers.TreeTraversal; @@ -335,7 +336,7 @@ public List getSelectedDescriptorPacks(boolean sorted boolean allowResolved, TreePath[] paths) { if (paths == null) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); paths = getSelectionPaths(); } if (paths == null) return Collections.emptyList(); @@ -387,7 +388,7 @@ private List getSelectedDescriptors(boolean sortedByP @Override public TreePath @Nullable [] getSelectionPaths() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return super.getSelectionPaths(); } @@ -463,7 +464,7 @@ private static boolean isNodeValidAndIncluded(ProblemDescriptionNode node, boole } public void removeSelectedProblems() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); TreePath[] selected = getSelectionPaths(); if (selected == null) return; if (!getContext().getUIOptions().FILTER_RESOLVED_ITEMS) { diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 111a2a6bb7e62..174da0b79bda3 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -12,7 +12,6 @@ import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.EmptyAction; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.command.undo.UndoUtil; import com.intellij.openapi.editor.*; @@ -53,6 +52,7 @@ import com.intellij.ui.components.JBScrollPane.Alignment; import com.intellij.util.DocumentUtil; import com.intellij.util.FileContentUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -283,7 +283,7 @@ else if (clearInput) { } protected @NotNull String addToHistoryInner(final @NotNull TextRange textRange, final @NotNull EditorEx editor, boolean erase, final boolean preserveMarkup) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); String result = addTextRangeToHistory(textRange, editor, preserveMarkup); if (erase) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleTokenUtil.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleTokenUtil.java index fcb4a86955006..89a8b0164f48e 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleTokenUtil.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleTokenUtil.java @@ -3,7 +3,6 @@ import com.intellij.execution.filters.HyperlinkInfo; import com.intellij.execution.ui.ConsoleViewContentType; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.ex.MarkupModelEx; @@ -18,6 +17,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -108,7 +108,7 @@ private static void saveTokenType(@NotNull RangeMarker m, @NotNull ConsoleViewCo // finds range marker the [offset..offset+1) belongs to static RangeMarker findTokenMarker(@NotNull Editor editor, @NotNull Project project, int offset) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); RangeMarker[] marker = new RangeMarker[1]; MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(editor.getDocument(), project, true); model.processRangeHighlightersOverlappingWith(offset, offset, m->{ @@ -126,7 +126,7 @@ static void createTokenRangeHighlighter(@NotNull Editor editor, int startOffset, int endOffset, boolean mergeWithThePreviousSameTypeToken) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(editor.getDocument(), project, true); int layer = HighlighterLayer.SYNTAX + 1; // make custom filters able to draw their text attributes over the default ones if (mergeWithThePreviousSameTypeToken && startOffset > 0) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 4a0ed630ccb63..04e9a46145e1e 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -64,6 +64,7 @@ import com.intellij.ui.awt.RelativePoint; import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.ui.UIUtil; @@ -206,7 +207,7 @@ public void exitDumbMode() { }); ApplicationManager.getApplication().getMessageBus().connect(this) .subscribe(EditorColorsManager.TOPIC, __ -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; ConsoleTokenUtil.updateAllTokenTextAttributes(getEditor(), project); }); @@ -264,13 +265,13 @@ public Editor getEditor() { } public EditorHyperlinkSupport getHyperlinks() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = getEditor(); return editor == null ? null : EditorHyperlinkSupport.get(editor); } public void scrollToEnd() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = getEditor(); if (editor == null) return; boolean hasSelection = editor.getSelectionModel().hasSelection(); @@ -282,13 +283,13 @@ public void scrollToEnd() { } private void scrollToEnd(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); EditorUtil.scrollToTheEnd(editor, true); myCancelStickToEnd = false; } public void foldImmediately() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myFlushAlarm.isEmpty()) { cancelAllFlushRequests(); flushDeferredText(); @@ -406,7 +407,7 @@ public boolean hasDeferredOutput() { @Override public void performWhenNoDeferredOutput(@NotNull Runnable runnable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!hasDeferredOutput()) { runnable.run(); return; @@ -427,7 +428,7 @@ public void performWhenNoDeferredOutput(@NotNull Runnable runnable) { @Override @NotNull public JComponent getComponent() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myMainPanel == null) { myMainPanel = new JPanel(new BorderLayout()); myJLayeredPane = new MyDiffContainer(myMainPanel, createCompositeFilter().getUpdateMessage()); @@ -460,7 +461,7 @@ protected CompositeFilter createCompositeFilter() { * @param component component to add */ public final void addLayerToPane(@NotNull JComponent component) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); getComponent(); // Make sure component exists component.setOpaque(false); component.setVisible(true); @@ -469,7 +470,7 @@ public final void addLayerToPane(@NotNull JComponent component) { @NotNull private EditorEx initConsoleEditor() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); EditorEx editor = createConsoleEditor(); registerConsoleEditorActions(editor); editor.getScrollPane().setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT)); @@ -507,7 +508,7 @@ public void mouseWheelMoved(MouseWheelEvent e) { } private void updateStickToEndState(@NotNull EditorEx editor, boolean useImmediatePosition) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean vScrollAtBottom = isVScrollAtTheBottom(editor, useImmediatePosition); boolean caretAtTheLastLine = isCaretAtTheLastLine(editor); if (!vScrollAtBottom && caretAtTheLastLine) { @@ -517,7 +518,7 @@ private void updateStickToEndState(@NotNull EditorEx editor, boolean useImmediat @NotNull protected JComponent createCenterComponent() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return getEditor().getComponent(); } @@ -546,7 +547,7 @@ private void cancelAllFlushRequests() { @TestOnly public void waitAllRequests() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert ApplicationManager.getApplication().isUnitTestMode(); Future future = ApplicationManager.getApplication().executeOnPooledThread(() -> { while (true) { @@ -625,7 +626,7 @@ protected void print(@NotNull String text, @NotNull ConsoleViewContentType conte // send text which was typed in the console to the running process private void sendUserInput(@NotNull CharSequence typedText) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myState.isRunning() && NEW_LINE_MATCHER.indexIn(typedText) >= 0) { CharSequence textToSend = ConsoleTokenUtil.computeTextToSend(getEditor(), getProject()); if (textToSend.length() != 0) { @@ -674,7 +675,7 @@ public boolean canPause() { } public void flushDeferredText() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; EditorEx editor = (EditorEx)getEditor(); boolean shouldStickToEnd = !myCancelStickToEnd && isStickingToEnd(editor); @@ -758,7 +759,7 @@ private boolean isDisposed() { } protected void doClear() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; @@ -795,7 +796,7 @@ private static boolean isVScrollAtTheBottom(@NotNull EditorEx editor, boolean us } private void clearHyperlinkAndFoldings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = getEditor(); for (RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) { if (highlighter.getUserData(ConsoleTokenUtil.MANUAL_HYPERLINK) == null) { @@ -872,7 +873,7 @@ public void printHyperlink(@NotNull String hyperlinkText, @Nullable HyperlinkInf @NotNull private EditorEx createConsoleEditor() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); EditorEx editor = doCreateConsoleEditor(); LOG.assertTrue(UndoUtil.isUndoDisabledFor(editor.getDocument()), "Undo must be disabled in console for performance reasons"); LOG.assertTrue(!((DocumentImpl)editor.getDocument()).isWriteThreadOnly(), "Console document must support background modifications, see e.g. ConsoleViewUtil.setupConsoleEditor() "+getClass()); @@ -896,7 +897,7 @@ protected EditorEx doCreateConsoleEditor() { } private void registerConsoleEditorActions(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Shortcut[] shortcuts = KeymapUtil.getActiveKeymapShortcuts(IdeActions.ACTION_GOTO_DECLARATION).getShortcuts(); CustomShortcutSet shortcutSet = new CustomShortcutSet(ArrayUtil.mergeArrays(shortcuts, CommonShortcuts.ENTER.getShortcuts())); new HyperlinkNavigationAction().registerCustomShortcutSet(shortcutSet, editor.getContentComponent()); @@ -912,13 +913,13 @@ private void registerConsoleEditorActions(@NotNull Editor editor) { } private static void registerActionHandler(@NotNull Editor editor, @NotNull String actionId) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); AnAction action = ActionManager.getInstance().getAction(actionId); action.registerCustomShortcutSet(action.getShortcutSet(), editor.getContentComponent()); } private static void registerActionHandler(@NotNull Editor editor, @NotNull String actionId, @NotNull AnAction action) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); Shortcut[] shortcuts = keymap.getShortcuts(actionId); action.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), editor.getContentComponent()); @@ -926,7 +927,7 @@ private static void registerActionHandler(@NotNull Editor editor, @NotNull Strin @NotNull private ActionGroup getPopupGroup(@NotNull EditorMouseEvent event) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ActionManager actionManager = ActionManager.getInstance(); HyperlinkInfo info = getHyperlinks() != null ? getHyperlinks().getHyperlinkInfoByEvent(event) : null; ActionGroup group = null; @@ -946,7 +947,7 @@ private ActionGroup getPopupGroup(@NotNull EditorMouseEvent event) { } private void highlightHyperlinksAndFoldings(int startLine, @NotNull Expirable expirableToken) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); CompositeFilter compositeFilter = createCompositeFilter(); boolean canHighlightHyperlinks = !compositeFilter.isEmpty(); @@ -975,7 +976,7 @@ public void invalidateFiltersExpirableTokens() { } public void rehighlightHyperlinksAndFoldings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; invalidateFiltersExpirableTokens(); clearHyperlinkAndFoldings(); @@ -983,7 +984,7 @@ public void rehighlightHyperlinksAndFoldings() { } private void runHeavyFilters(@NotNull CompositeFilter compositeFilter, int line1, int endLine) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int startLine = Math.max(0, line1); Document document = getEditor().getDocument(); @@ -1025,7 +1026,7 @@ public void doRun() { } protected void updateFoldings(int startLine, int endLine) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = getEditor(); editor.getFoldingModel().runBatchFoldingOperation(() -> { Document document = editor.getDocument(); @@ -1178,7 +1179,7 @@ public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext } void type(@NotNull Editor editor, @NotNull String text) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); flushDeferredText(); SelectionModel selectionModel = editor.getSelectionModel(); @@ -1211,7 +1212,7 @@ void type(@NotNull Editor editor, @NotNull String text) { private abstract static class ConsoleAction extends AnAction implements DumbAware { @Override public void actionPerformed(@NotNull AnActionEvent e) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); DataContext context = e.getDataContext(); ConsoleViewImpl console = getRunningConsole(context); if (console != null) { @@ -1432,7 +1433,7 @@ public void addChangeListener(@NotNull ChangeListener listener, @NotNull Disposa } private void insertUserText(int offset, @NotNull String text) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); List> result = myInputMessageFilter.applyFilter(text, ConsoleViewContentType.USER_INPUT); if (result == null) { doInsertUserInput(offset, text); @@ -1453,7 +1454,7 @@ private void insertUserText(int offset, @NotNull String text) { } private void doInsertUserInput(int offset, @NotNull String text) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = getEditor(); Document document = editor.getDocument(); @@ -1471,14 +1472,14 @@ private void doInsertUserInput(int offset, @NotNull String text) { } private static void moveScrollRemoveSelection(@NotNull Editor editor, int offset) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); editor.getCaretModel().moveToOffset(offset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); } private void deleteUserText(int startOffset, int length) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Editor editor = getEditor(); Document document = editor.getDocument(); @@ -1499,7 +1500,7 @@ public boolean isRunning() { } public void addNotificationComponent(@NotNull JComponent notificationComponent) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); add(notificationComponent, BorderLayout.NORTH); } diff --git a/platform/lang-impl/src/com/intellij/find/FindUtil.java b/platform/lang-impl/src/com/intellij/find/FindUtil.java index 8e2515612fb2c..16b84e87a5b6a 100644 --- a/platform/lang-impl/src/com/intellij/find/FindUtil.java +++ b/platform/lang-impl/src/com/intellij/find/FindUtil.java @@ -47,6 +47,7 @@ import com.intellij.usages.impl.UsageViewImpl; import com.intellij.util.Consumer; import com.intellij.util.Function; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -218,7 +219,7 @@ public static void findWordAtCaret(Project project, @NotNull Editor editor, @Not } public static void find(@NotNull final Project project, @NotNull final Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); PsiUtilBase.assertEditorAndProjectConsistent(project, editor); final FindManager findManager = FindManager.getInstance(project); String s = getSelectedText(editor); diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index 10b2c07b9d617..00e622c37fdb4 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -78,6 +78,7 @@ import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.EdtScheduledExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.*; @@ -430,7 +431,7 @@ static void showElementUsages(@NotNull ShowUsagesParameters parameters, @NotNull static Future> showElementUsagesWithResult(@NotNull ShowUsagesParameters parameters, @NotNull ShowUsagesActionHandler actionHandler) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Span findUsageSpan = myFindUsagesTracer.spanBuilder("findUsages").startSpan(); Scope opentelemetryScope = findUsageSpan.makeCurrent(); @@ -778,7 +779,7 @@ private static boolean showPopupIfNeedTo(@NotNull JBPopup popup, @NotNull Relati @NotNull ShowUsagesPopupData showUsagesPopupData, @NotNull Runnable itemChoseCallback, @NotNull Consumer tableResizer) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); @NotNull JTable table = showUsagesPopupData.table; @NotNull AtomicReference popupRef = showUsagesPopupData.popupRef; @@ -1213,7 +1214,7 @@ private static void rebuildTable(@NotNull Project project, @NotNull RelativePoint popupPosition, @NotNull IntRef minWidth, @NotNull AtomicBoolean manuallyResized) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ShowUsagesTable.MyModel tableModel = table.setTableModel(data); List existingData = tableModel.getItems(); diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTable.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTable.java index a33d5e3e43bcf..83102b174a54f 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTable.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTable.java @@ -2,9 +2,10 @@ package com.intellij.find.actions; import com.intellij.ide.util.gotoByName.ModelDiff; -import com.intellij.internal.statistic.eventLog.events.EventPair; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.actionSystem.PlatformCoreDataKeys; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.util.PopupUtil; @@ -21,6 +22,7 @@ import com.intellij.usages.UsageView; import com.intellij.usages.impl.*; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.ui.JBUI; @@ -220,7 +222,7 @@ private static int calcColumnCount(@NotNull List data) { @NotNull MyModel setTableModel(@NotNull final List data) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final int columnCount = calcColumnCount(data); MyModel model = getModel() instanceof MyModel ? (MyModel)getModel() : null; if (model == null || model.getColumnCount() != columnCount) { diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index 5462bffcd6c49..7bf4fa88445f1 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -12,7 +12,6 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -26,8 +25,8 @@ import com.intellij.openapi.progress.Task; import com.intellij.openapi.progress.impl.ProgressManagerImpl; import com.intellij.openapi.progress.util.ProgressIndicatorBase; -import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.DumbModeBlockedFunctionality; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; @@ -51,6 +50,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.CommonProcessors; import com.intellij.util.Processor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -104,7 +104,7 @@ public boolean canFindUsages(@NotNull PsiElement element) { } public void clearFindingNextUsageInFile() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLastSearchInFileData = null; } @@ -117,7 +117,7 @@ public boolean findPreviousUsageInFile(@NotNull Editor editor) { } private boolean findUsageInFile(@NotNull Editor editor, @NotNull FileSearchScope direction) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myLastSearchInFileData == null) return false; PsiElement[] primaryElements = myLastSearchInFileData.getPrimaryElements(); @@ -144,7 +144,7 @@ private boolean findUsageInFile(@NotNull Editor editor, @NotNull FileSearchScope private void initLastSearchElement(@NotNull FindUsagesOptions findUsagesOptions, PsiElement @NotNull [] primaryElements, PsiElement @NotNull [] secondaryElements) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLastSearchInFileData = new LastSearchData(primaryElements, secondaryElements, findUsagesOptions); } @@ -189,7 +189,7 @@ public FindUsagesHandler getNewFindUsagesHandler(@NotNull PsiElement element, bo } public void findUsages(@NotNull PsiElement psiElement, @Nullable PsiFile scopeFile, FileEditor editor, boolean showDialog, @Nullable("null means default (stored in options)") SearchScope searchScope) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FindUsagesHandler handler = getFindUsagesHandler(psiElement, showDialog ? OperationMode.DEFAULT : OperationMode.USAGES_WITH_DEFAULT_OPTIONS); if (handler == null) return; @@ -217,7 +217,7 @@ public void findUsages(@NotNull PsiElement psiElement, @Nullable PsiFile scopeFi } public void startFindUsages(@NotNull PsiElement psiElement, @NotNull FindUsagesOptions findUsagesOptions) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); FindUsagesHandler handler = getFindUsagesHandler(psiElement, false); if (handler == null) return; startFindUsages(findUsagesOptions, handler, null, null); @@ -227,7 +227,7 @@ private void startFindUsages(@NotNull FindUsagesOptions findUsagesOptions, @NotNull FindUsagesHandler handler, PsiFile scopeFile, FileEditor fileEditor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean singleFile = scopeFile != null; clearFindingNextUsageInFile(); @@ -302,7 +302,7 @@ public static void startProcessUsages(@NotNull ProgressIndicator indicator, @NotNull UsageSearcher usageSearcher, @NotNull Processor processor, @NotNull Runnable onComplete) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Task.Backgroundable task = new Task.Backgroundable(project, FindBundle.message("progress.title.finding.usages")) { @Override public void run(@NotNull ProgressIndicator indicator) { @@ -497,7 +497,7 @@ private void findUsagesInEditor(PsiElement @NotNull [] primaryElements, @NotNull FileSearchScope direction, @NotNull FindUsagesOptions findUsagesOptions, @NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); initLastSearchElement(findUsagesOptions, primaryElements, secondaryElements); clearStatusBar(); diff --git a/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingPopupUI.java b/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingPopupUI.java index 577d0d8773df1..f01e4472af4d5 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingPopupUI.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingPopupUI.java @@ -54,6 +54,7 @@ import com.intellij.util.Consumer; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.SequentialTaskExecutor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.*; import org.jetbrains.annotations.Nls; @@ -343,7 +344,7 @@ public static RunAnythingSearchListModel getSearchingModel(@NotNull JBList list) } private void rebuildList() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myListRenderingAlarm.cancelAllRequests(); myResultsList.getEmptyText().setText(FindBundle.message("empty.text.searching")); diff --git a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java index 9f5f7196adc37..60a3951ac695a 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java @@ -71,6 +71,7 @@ import com.intellij.util.Alarm; import com.intellij.util.Processor; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.messages.Topic; @@ -646,7 +647,7 @@ private void scheduleRebuildList(SearchRestartReason reason) { } private void rebuildList(SearchRestartReason reason) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); stopSearching(); diff --git a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/ThrottlingListenerWrapper.java b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/ThrottlingListenerWrapper.java index 54825a1cf0081..3649eb3951e6b 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/ThrottlingListenerWrapper.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/ThrottlingListenerWrapper.java @@ -2,8 +2,8 @@ package com.intellij.ide.actions.searcheverywhere; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -77,10 +77,10 @@ public void contributorFinished(@NotNull SearchEverywhereContributor contribu } private void scheduleFlushBuffer() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Runnable flushTask = () -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!flushScheduled) return; flushScheduled = false; buffer.flushBuffer(delegateListener); @@ -93,7 +93,7 @@ private void scheduleFlushBuffer() { } private void cancelScheduledFlush() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); flushAlarm.cancelAllRequests(); flushScheduled = false; } diff --git a/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkManager.java b/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkManager.java index fd56cc5e887d5..c9cc6203223c2 100644 --- a/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkManager.java +++ b/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkManager.java @@ -31,6 +31,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.messages.MessageBusConnection; @@ -91,7 +92,7 @@ public BookmarkManager(@NotNull Project project) { @NotNull public Bookmark addTextBookmark(@NotNull VirtualFile file, int lineIndex, @NotNull @NlsSafe String description) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Bookmark b = new Bookmark(myProject, file, lineIndex, description); // increment all other indices and put new bookmark at index 0 @@ -179,7 +180,7 @@ public boolean hasBookmarksWithMnemonics() { } public void removeBookmark(@NotNull Bookmark bookmark) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); VirtualFile file = bookmark.getFile(); if (myBookmarks.remove(file, bookmark)) { int index = bookmark.index; @@ -350,7 +351,7 @@ private void writeExternal(Element element) { * Try to move bookmark one position up in the list */ public void moveBookmarkUp(@NotNull Bookmark bookmark) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final int index = bookmark.index; if (index > 0) { Bookmark other = ContainerUtil.find(myBookmarks.values(), b -> b.index == index - 1); @@ -367,7 +368,7 @@ public void moveBookmarkUp(@NotNull Bookmark bookmark) { * Try to move bookmark one position down in the list */ public void moveBookmarkDown(@NotNull Bookmark bookmark) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final int index = bookmark.index; if (index < myBookmarks.values().size() - 1) { Bookmark other = ContainerUtil.find(myBookmarks.values(), b -> b.index == index + 1); @@ -401,7 +402,7 @@ public void deleteMnemonic(@NotNull Bookmark bookmark) { } public void setMnemonic(@NotNull Bookmark bookmark, char c) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final Bookmark old = findBookmarkForMnemonic(c); if (old != null) removeBookmark(old); updateMnemonic(bookmark, c); @@ -414,7 +415,7 @@ private void updateMnemonic(@NotNull Bookmark bookmark, char c) { } public void setDescription(@NotNull Bookmark bookmark, @NotNull @NlsSafe String description) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); bookmark.setDescription(description); getPublisher().bookmarkChanged(bookmark); } diff --git a/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyBrowserBaseEx.java b/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyBrowserBaseEx.java index 73ec290278f08..6f2e24874a900 100644 --- a/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyBrowserBaseEx.java +++ b/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyBrowserBaseEx.java @@ -48,6 +48,7 @@ import com.intellij.util.EditSourceOnDoubleClickHandler; import com.intellij.util.EditSourceOnEnterKeyHandler; import com.intellij.util.SingleAlarm; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; @@ -357,7 +358,7 @@ public void changeView(@Nls @NotNull String typeName) { } public void changeView(@Nls @NotNull String typeName, boolean requestFocus) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Sheet sheet = myType2Sheet.get(typeName); myCurrentSheet.set(sheet); @@ -501,7 +502,7 @@ public String getPreviousOccurenceActionName() { @NotNull public StructureTreeModel getTreeModel(@NotNull String viewType) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myType2Sheet.get(viewType).myStructureTreeModel; } @@ -573,7 +574,7 @@ private void disposeSheet(@NotNull Sheet sheet) { } protected void doRefresh(boolean currentBuilderOnly) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (currentBuilderOnly) LOG.assertTrue(getCurrentViewType() != null); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 36c1f4289e184..eaadaa359d697 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -76,6 +76,7 @@ import com.intellij.util.IJSwingUtilities; import com.intellij.util.PlatformUtils; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.JBIterable; import com.intellij.util.ui.UIUtil; @@ -724,7 +725,7 @@ public synchronized void addProjectPane(@NotNull final AbstractProjectViewPane p @Override public synchronized void removeProjectPane(@NotNull AbstractProjectViewPane pane) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myUninitializedPanes.remove(pane); //assume we are completely initialized here @NotNull String idToRemove = pane.getId(); @@ -796,7 +797,7 @@ private synchronized void doAddUninitializedPanes() { } private void doAddPane(@NotNull final AbstractProjectViewPane newPane) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int index; final ContentManager manager = getContentManager(); for (index = 0; index < manager.getContentCount(); index++) { @@ -924,7 +925,7 @@ public synchronized void setupImpl(@NotNull ToolWindow toolWindow) { // public for tests public synchronized void setupImpl(@NotNull ToolWindow toolWindow, final boolean loadPaneExtensions) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isInitialized) return; myActionGroup = new DefaultActionGroup(); diff --git a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java index df2f17750356b..633aa7a7eab81 100644 --- a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java +++ b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java @@ -49,6 +49,7 @@ import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure; import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.JBIterable; import com.intellij.util.containers.JBTreeTraverser; @@ -456,7 +457,7 @@ private Promise expandSelectFocusInner(Object element, boolean select, } }; Function> action = path -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (select) { TreeUtil.selectPath(myTree, path); @@ -567,7 +568,7 @@ private void cancelScrollToSelectedElement() { } private void scrollToSelectedElementLater() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); cancelScrollToSelectedElement(); if (isDisposed()) return; @@ -618,7 +619,7 @@ public void centerSelectedRow() { @Override public void setActionActive(String name, boolean state) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); storeState(); StructureViewFactoryEx.getInstanceEx(myProject).setActiveAction(name, state); ourSettingsModificationCount.incrementAndGet(); diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 40abc1391dfbe..f5e358f8382b5 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -67,6 +67,7 @@ import com.intellij.usages.*; import com.intellij.usages.impl.UsageViewManagerImpl; import com.intellij.util.*; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.DumbModeAccessType; import com.intellij.util.text.Matcher; @@ -748,7 +749,7 @@ protected boolean closeForbidden(boolean ok) { } void cancelListUpdater() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (checkDisposed()) return; final CalcElementsThread calcElementsThread = myCalcElementsThread; @@ -878,7 +879,7 @@ void rebuildList(@NotNull SelectionPolicy pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myInitialized) { return; } @@ -913,7 +914,7 @@ void rebuildList(@NotNull SelectionPolicy pos, MatcherHolder.associateMatcher(myList, matcher); scheduleCalcElements(text, myCheckBox.isSelected(), modalityState, pos, elements -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (postRunnable != null) { postRunnable.run(); @@ -1321,7 +1322,7 @@ private class CalcElementsThread extends ReadTask { private final Alarm myUpdateListAlarm = new Alarm(); void scheduleThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCalcElementsThread = this; showCard(SEARCHING_CARD, 200); ProgressIndicatorUtils.scheduleWithWriteActionPriority(myProgress, this); @@ -1471,7 +1472,7 @@ protected boolean isOverflow(@NotNull Set elementsArray) { } private void cancel() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myProgress.cancel(); } diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/SmartPointerListModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/SmartPointerListModel.java index 3a1c527948508..d2e8f91f1fde4 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/SmartPointerListModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/SmartPointerListModel.java @@ -2,8 +2,8 @@ package com.intellij.ide.util.gotoByName; import com.intellij.ide.util.treeView.TreeAnchorizer; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.ui.CollectionListModel; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import javax.swing.*; @@ -40,7 +40,7 @@ public int getSize() { @Override public T getElementAt(int index) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return unwrap(myDelegate.getElementAt(index)); } @@ -55,19 +55,19 @@ private T unwrap(Object at) { @Override public void addToModel(int idx, T element) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myDelegate.add(Math.min(idx, getSize()), wrap(element)); } @Override public void addAllToModel(int index, List elements) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myDelegate.addAll(Math.min(index, getSize()), ContainerUtil.map(elements, this::wrap)); } @Override public void removeRangeFromModel(int start, int end) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (start < getSize() && !isEmpty()) { myDelegate.removeRange(start, Math.min(end, getSize() - 1)); } diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java index 8a5f576a62fbf..c0bd6e5ddf418 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java @@ -32,6 +32,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.Consumer; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.SimpleMessageBusConnection; import com.intellij.util.messages.Topic; @@ -448,7 +449,7 @@ public void waitForCompletion() { } private void rebuild(final boolean updateText, @Nullable final Runnable runnable, final boolean requestFocus, final int delayMillis) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myRebuildRequired = false; cancelCurrentProgress(); PanelProgressIndicator progress = createProgressIndicator(requestFocus); @@ -570,7 +571,7 @@ private PanelProgressIndicator createProgressIndicator(final boolean requestFocu } public void cancelCurrentProgress(){ - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myUpdateAlarm.cancel(false); if (myCurrentProgress != null) { myCurrentProgress.cancel(); diff --git a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java index f692dabdb4037..5e2f401ed5e21 100644 --- a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java +++ b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java @@ -13,6 +13,7 @@ import com.intellij.openapi.util.NlsContexts; import com.intellij.platform.templates.github.GeneratorException; import com.intellij.platform.templates.github.GithubTagInfo; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,7 +37,7 @@ public GithubTagListProvider(@NotNull String userName, @NotNull String repositor @Nullable public ImmutableSet getCachedTags() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); File cacheFile = getTagsCacheFile(); if (cacheFile.isFile()) { try { diff --git a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/TestEditorTabGroup.java b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/TestEditorTabGroup.java index 173c37e5cbfec..4b13bcc1e735b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/TestEditorTabGroup.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/TestEditorTabGroup.java @@ -1,11 +1,11 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.fileEditor.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorProvider; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.Nullable; import java.util.LinkedHashMap; @@ -25,7 +25,7 @@ public String getName() { } public void openTab(VirtualFile virtualFile, FileEditor fileEditor, FileEditorProvider fileEditorProvider) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myOpenedTabs.put(virtualFile, Pair.pair(fileEditor, fileEditorProvider)); myOpenedFile = virtualFile; @@ -43,17 +43,17 @@ public Pair getOpenedEditor(){ @Nullable public VirtualFile getOpenedFile() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myOpenedFile; } public void setOpenedFile(VirtualFile file) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myOpenedFile = file; } public void closeTab(VirtualFile virtualFile) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myOpenedFile = null; myOpenedTabs.remove(virtualFile); } diff --git a/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java b/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java index 9488815099a67..ce1863c18dd43 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java @@ -30,6 +30,7 @@ import com.intellij.ui.components.JBList; import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBTabbedPane; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.Nls; @@ -586,7 +587,7 @@ void selectFileType(@NotNull FileType fileType) { @Override public void selectFileType(@NotNull FileType fileType) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myRecognizedFileType == null) { myFileTypeToPreselect = fileType; } diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownInvalidSdkFixLocal.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownInvalidSdkFixLocal.java index edb5a9541eadb..67a11281f5d7f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownInvalidSdkFixLocal.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownInvalidSdkFixLocal.java @@ -1,12 +1,12 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.projectRoots.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ui.configuration.SdkListPresenter; import com.intellij.openapi.roots.ui.configuration.UnknownSdkLocalSdkFix; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,7 +55,7 @@ final class UnknownInvalidSdkFixLocal extends UnknownSdkFixActionLocalBase imple @NotNull @Override protected Sdk applyLocalFix() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { String sdkFixVersionString = myFix.getVersionString(); String sdkHome = myFix.getExistingSdkHome(); diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownMissingSdkFixLocal.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownMissingSdkFixLocal.java index 4239f3366e37e..608fa57831172 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownMissingSdkFixLocal.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownMissingSdkFixLocal.java @@ -1,7 +1,6 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.projectRoots.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.Sdk; @@ -10,6 +9,7 @@ import com.intellij.openapi.roots.ui.configuration.UnknownSdk; import com.intellij.openapi.roots.ui.configuration.UnknownSdkLocalSdkFix; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -80,7 +80,7 @@ UnknownSdk getUnknownSdk() { @NotNull @Override protected Sdk applyLocalFix() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { String actualSdkName = mySdk.getSdkName(); diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownSdkFixActionLocalBase.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownSdkFixActionLocalBase.java index 7b26d01b48111..0eba972d19d31 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownSdkFixActionLocalBase.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/UnknownSdkFixActionLocalBase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.projectRoots.impl; import com.intellij.openapi.application.ApplicationManager; @@ -10,6 +10,7 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,7 +27,7 @@ public abstract class UnknownSdkFixActionLocalBase extends UnknownSdkFixActionBa @NotNull private Sdk runWithEvents() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Listener multicaster = getMulticaster(); try { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBox.kt b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBox.kt index 661dbcf933c90..c758a03cb6a29 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBox.kt +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBox.kt @@ -1,11 +1,11 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.roots.ui.configuration import com.intellij.openapi.Disposable -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.util.Disposer import com.intellij.ui.PopupMenuListenerAdapter +import com.intellij.util.concurrency.ThreadingAssertions import javax.swing.event.PopupMenuEvent class SdkComboBox(model: SdkComboBoxModel) : SdkComboBoxBase(model.modelBuilder) { @@ -84,7 +84,7 @@ class SdkComboBox(model: SdkComboBoxModel) : SdkComboBoxBase(model. } private fun setReloadDisposable(parentDisposable: Disposable?) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() parentDisposable?.let { Disposer.register(model.project, it) } disposable?.let { Disposer.dispose(it) } disposable = parentDisposable diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/projectRoot/SdkDownloadTracker.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/projectRoot/SdkDownloadTracker.java index 863c2a8364715..1baded4cc5944 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/projectRoot/SdkDownloadTracker.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/projectRoot/SdkDownloadTracker.java @@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.wm.ex.ProgressIndicatorEx; import com.intellij.util.Consumer; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -67,7 +68,7 @@ public void onSdkRemoved(@NotNull Sdk sdk) { } private void removeTask(@NotNull PendingDownload task) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myPendingTasks.remove(task); } @@ -93,7 +94,7 @@ public void registerEditableSdk(@NotNull Sdk original, public void registerSdkDownload(@NotNull Sdk originalSdk, @NotNull SdkDownloadTask item) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LOG.assertTrue(findTask(originalSdk) == null, "Download is already running for the SDK " + originalSdk); PendingDownload pd = new PendingDownload(originalSdk, item, new SmartPendingDownloadModalityTracker()); @@ -112,7 +113,7 @@ public void tryRegisterSdkDownloadFailureHandler(@NotNull Sdk originalSdk, } public void startSdkDownloadIfNeeded(@NotNull Sdk sdkFromTable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); PendingDownload task = findTask(sdkFromTable); if (task == null) return; @@ -162,7 +163,7 @@ public boolean tryRegisterDownloadingListener(@NotNull Sdk sdk, @NotNull Disposable lifetime, @NotNull ProgressIndicator indicator, @NotNull Consumer onDownloadCompleteCallback) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); PendingDownload pd = findTask(sdk); if (pd == null) return false; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/impl/rename.kt b/platform/lang-impl/src/com/intellij/refactoring/rename/impl/rename.kt index 59905989063d5..9f60ddf000f0f 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/impl/rename.kt +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/impl/rename.kt @@ -21,8 +21,12 @@ import com.intellij.refactoring.RefactoringBundle import com.intellij.refactoring.rename.api.* import com.intellij.refactoring.rename.api.ModifiableRenameUsage.* import com.intellij.refactoring.rename.impl.FileUpdates.Companion.createFileUpdates -import com.intellij.refactoring.rename.ui.* +import com.intellij.refactoring.rename.ui.RenameDialog +import com.intellij.refactoring.rename.ui.commandName +import com.intellij.refactoring.rename.ui.progressTitle +import com.intellij.refactoring.rename.ui.withBackgroundIndicator import com.intellij.util.Query +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.UIUtil import kotlinx.coroutines.* import kotlinx.coroutines.channels.ReceiveChannel @@ -41,7 +45,7 @@ internal typealias UsagePointer = Pointer * Entry point to perform rename with a dialog initialized with [targetName]. */ internal fun showDialogAndRename(project: Project, target: RenameTarget, targetName: String = target.targetName) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val initOptions = RenameDialog.Options( targetName = targetName, renameOptions = renameOptions(project, target) @@ -300,7 +304,7 @@ private suspend fun previewInDialog(project: Project, fileUpdates: FileUpdates): @TestOnly fun renameAndWait(project: Project, target: RenameTarget, newName: String) { val application = ApplicationManager.getApplication() - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() require(application.isUnitTestMode) val targetPointer = target.createPointer() diff --git a/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringAvailabilityIndicator.kt b/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringAvailabilityIndicator.kt index e8c63dd06a5ec..e4ecfc4eda8de 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringAvailabilityIndicator.kt +++ b/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringAvailabilityIndicator.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.refactoring.suggested import com.intellij.codeInsight.daemon.GutterMark @@ -19,6 +19,7 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.refactoring.RefactoringBundle +import com.intellij.util.concurrency.ThreadingAssertions import org.jetbrains.annotations.Nls import org.jetbrains.annotations.TestOnly import javax.swing.Icon @@ -72,7 +73,7 @@ class SuggestedRefactoringAvailabilityIndicator(private val project: Project) { refactoringEnabled: Boolean, @NlsContexts.Tooltip tooltip: String ) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val newData = Data( document, @@ -91,7 +92,7 @@ class SuggestedRefactoringAvailabilityIndicator(private val project: Project) { } fun clear() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (data == null) return data = null @@ -103,7 +104,7 @@ class SuggestedRefactoringAvailabilityIndicator(private val project: Project) { } fun disable() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val data = data ?: return if (data.refactoringEnabled) { show( @@ -128,7 +129,7 @@ class SuggestedRefactoringAvailabilityIndicator(private val project: Project) { } private fun updateHighlighter(editor: Editor) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val prevHighlighter = editorsAndHighlighters[editor] if (prevHighlighter != null) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringChangeCollector.kt b/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringChangeCollector.kt index f39ac0343d73b..f3c86a2413977 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringChangeCollector.kt +++ b/platform/lang-impl/src/com/intellij/refactoring/suggested/SuggestedRefactoringChangeCollector.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.refactoring.suggested @@ -12,6 +12,7 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.refactoring.suggested.SuggestedRefactoringState.ErrorLevel import com.intellij.util.concurrency.AppExecutorUtil +import com.intellij.util.concurrency.ThreadingAssertions import org.jetbrains.annotations.TestOnly class SuggestedRefactoringChangeCollector( @@ -22,7 +23,7 @@ class SuggestedRefactoringChangeCollector( private set override fun editingStarted(declaration: PsiElement, refactoringSupport: SuggestedRefactoringSupport) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() require(declaration.isValid) state = refactoringSupport.stateChanges.createInitialState(declaration) updateAvailabilityIndicator() @@ -35,7 +36,7 @@ class SuggestedRefactoringChangeCollector( } override fun nextSignature(anchor: PsiElement, refactoringSupport: SuggestedRefactoringSupport) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() require(anchor.isValid) state = state?.let { refactoringSupport.stateChanges.updateState(it, anchor) } updateAvailabilityIndicator() @@ -43,19 +44,19 @@ class SuggestedRefactoringChangeCollector( } override fun inconsistentState() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() state = state?.withErrorLevel(ErrorLevel.INCONSISTENT) updateAvailabilityIndicator() } override fun reset() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() state = null updateAvailabilityIndicator() } fun undoToState(state: SuggestedRefactoringState) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() this.state = state updateAvailabilityIndicator() amendStateInBackground() diff --git a/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java b/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java index 1776690776ecf..68a39faffb5ef 100644 --- a/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java +++ b/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java @@ -10,7 +10,6 @@ import com.intellij.lang.LangBundle; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Disposer; @@ -30,6 +29,7 @@ import com.intellij.usages.UsageViewSettings; import com.intellij.usages.impl.UsagePreviewPanel; import com.intellij.util.EditSourceOnDoubleClickHandler; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.ApiStatus; @@ -77,7 +77,7 @@ protected SlicePanel(@NotNull final Project project, super(new BorderLayout()); myProvider = rootNode.getProvider(); myToolWindow = toolWindow; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myProject = project; myProject.getMessageBus().connect(this).subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener() { diff --git a/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java b/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java index 2732e86fa654b..297e5bc9fe371 100644 --- a/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java +++ b/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.NlsContexts; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,7 +41,7 @@ private AnalyzeStacktraceUtil() { } public static void printStacktrace(@NotNull ConsoleView consoleView, @NotNull String unscrambledTrace) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); consoleView.clear(); consoleView.print(unscrambledTrace + "\n", ConsoleViewContentType.ERROR_OUTPUT); consoleView.scrollTo(0); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexTumbler.kt b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexTumbler.kt index fd6785f4d3e38..091ce9cdd6c15 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexTumbler.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexTumbler.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.registry.Registry import com.intellij.psi.stubs.StubIndexExtension import com.intellij.util.concurrency.Semaphore +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.indexing.IndexingFlag.cleanupProcessedFlag import org.jetbrains.annotations.NonNls import java.util.* @@ -31,7 +32,7 @@ class FileBasedIndexTumbler(private val reason: @NonNls String) { fun turnOff() { val app = ApplicationManager.getApplication() - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() LOG.assertTrue(!app.isWriteAccessAllowed) try { if (nestedLevelCount == 0) { diff --git a/platform/lang-impl/src/com/intellij/util/ui/Advertiser.java b/platform/lang-impl/src/com/intellij/util/ui/Advertiser.java index 8949d9ca7ae1f..410bc8ce58768 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/Advertiser.java +++ b/platform/lang-impl/src/com/intellij/util/ui/Advertiser.java @@ -2,10 +2,10 @@ package com.intellij.util.ui; import com.intellij.codeInsight.CodeInsightBundle; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.NlsContexts.PopupAdvertisement; import com.intellij.ui.ClickListener; import com.intellij.ui.RelativeFont; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -79,7 +79,7 @@ public void showRandomText() { } public void clearAdvertisements() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myTexts.clear(); myCurrentItem.set(0); updateAdvertisements(); @@ -92,7 +92,7 @@ protected Font adFont() { } public void addAdvertisement(@PopupAdvertisement @NotNull String text, @Nullable Icon icon) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myTexts.add(new Item(text, icon)); updateAdvertisements(); } @@ -102,7 +102,7 @@ public void setBorder(@Nullable Border border) { } public void setForeground(@Nullable Color foreground) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (foreground != null) { myForeground = foreground; diff --git a/platform/lang-impl/src/com/intellij/util/ui/tree/PerFileConfigurableBase.java b/platform/lang-impl/src/com/intellij/util/ui/tree/PerFileConfigurableBase.java index bed11f7de8cd8..9cf16fd2f4063 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/tree/PerFileConfigurableBase.java +++ b/platform/lang-impl/src/com/intellij/util/ui/tree/PerFileConfigurableBase.java @@ -41,6 +41,7 @@ import com.intellij.util.Function; import com.intellij.util.IconUtil; import com.intellij.util.ObjectUtils; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.AbstractTableCellEditor; import com.intellij.util.ui.JBInsets; @@ -146,7 +147,7 @@ private S param(@NotNull Key key) { @NotNull @Override public JComponent createComponent() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); //todo multi-editing, separate project/ide combos _if_ needed by specific configurable (SQL, no Web) myPanel = new JPanel(new BorderLayout()); myModel = new MyModel<>(param(TARGET_TITLE), param(MAPPING_TITLE)); @@ -389,7 +390,7 @@ protected void selectRows(int[] rows, boolean convertModelRowsToView) { } protected Map getNewMappings() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myModel == null) { throw new AssertionError("createComponent() was not called first on " + getClass().getName()); } diff --git a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java index 979260e427e5f..015718092854f 100644 --- a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java +++ b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java @@ -912,7 +912,7 @@ public static void moveSelectedRow(final @NotNull JTree tree, final int directio } public static @NotNull List listChildren(final @NotNull TreeNode node) { - //ApplicationManager.getApplication().assertIsDispatchThread(); + //ThreadingAssertions.assertEventDispatchThread(); int size = node.getChildCount(); ArrayList result = new ArrayList<>(size); for(int i = 0; i < size; i++){ diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java index a52149885cdb3..0c312319d994d 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java @@ -19,6 +19,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.accessibility.AccessibleContextUtil; import org.jetbrains.annotations.ApiStatus; @@ -141,7 +142,7 @@ public void showGutterHint(final LightweightHint hint, * So, first of all, editor will be scrolled to make the caret position visible. */ public void showEditorHint(final LightweightHint hint, final Editor editor, @PositionFlags final short constraint, @HideFlags final int flags, final int timeout, final boolean reviveOnEditorChange) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); editor.getScrollingModel().runActionOnScrollingFinished(() -> { LogicalPosition pos = editor.getCaretModel().getLogicalPosition(); @@ -694,7 +695,7 @@ public void projectOpened(@NotNull Project project) { @Override public void projectClosed(@NotNull Project project) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); // avoid leak through com.intellij.codeInsight.hint.TooltipController.myCurrentTooltip TooltipController.getInstance().cancelTooltips(); diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/LocalHintManager.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/LocalHintManager.java index 9a46b73db1513..9820213fe54bc 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/LocalHintManager.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/LocalHintManager.java @@ -29,6 +29,7 @@ import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Alarm; import com.intellij.util.BitUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.EDT; @@ -62,7 +63,7 @@ public final class LocalHintManager implements ClientHintManager { @Override public boolean canShowQuestionAction(QuestionAction action) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myQuestionAction == null || HintManagerImpl.getPriority(myQuestionAction) <= HintManagerImpl.getPriority(action); } @@ -144,7 +145,7 @@ public void setRequestFocusForNextHint(boolean requestFocus) { @Override public boolean performCurrentQuestionAction() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myQuestionAction != null && myQuestionHint != null) { if (myQuestionHint.isVisible()) { if (LOG.isDebugEnabled()) { @@ -407,7 +408,7 @@ public void showQuestionHint(final @NotNull Editor editor, int flags, final @NotNull QuestionAction action, @HintManager.PositionFlags short constraint) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); hideQuestionHint(); RangeHighlighter highlighter; if (offset1 != offset2) { @@ -443,7 +444,7 @@ public void hintHidden(@NotNull EventObject event) { } private void hideQuestionHint() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myQuestionHint != null) { myQuestionHint.hide(); myQuestionHint = null; diff --git a/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java b/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java index 772b56187b177..231364983422e 100644 --- a/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java +++ b/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java @@ -16,6 +16,7 @@ import com.intellij.openapi.util.Expirable; import com.intellij.util.TimeoutUtil; import com.intellij.util.concurrency.SequentialTaskExecutor; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.concurrency.Promise; @@ -114,7 +115,7 @@ private void addLineResult(@Nullable FilterResult result) { } void waitForPendingFilters(long timeoutMs) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); long started = System.currentTimeMillis(); while (true) { diff --git a/platform/platform-impl/src/com/intellij/ide/customize/transferSettings/TransferSettingsFacade.kt b/platform/platform-impl/src/com/intellij/ide/customize/transferSettings/TransferSettingsFacade.kt index 06396a2810009..7c247306ee418 100644 --- a/platform/platform-impl/src/com/intellij/ide/customize/transferSettings/TransferSettingsFacade.kt +++ b/platform/platform-impl/src/com/intellij/ide/customize/transferSettings/TransferSettingsFacade.kt @@ -9,9 +9,8 @@ import com.intellij.ide.customize.transferSettings.providers.vscode.VSCodeTransf import com.intellij.ide.customize.transferSettings.ui.TransferSettingsProgressIndicatorBase import com.intellij.ide.customize.transferSettings.ui.TransferSettingsView import com.intellij.openapi.project.Project -import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import javax.swing.JButton -import javax.swing.JComponent import javax.swing.JLabel import javax.swing.JProgressBar @@ -30,7 +29,7 @@ class TransferSettingsFacade(private val project: Project?) { val view by lazy { initView() } private fun initView(): TransferSettingsView { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val view = TransferSettingsView(config, model) diff --git a/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditTabs.java b/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditTabs.java index be282a518a593..94b1f2a1fe033 100644 --- a/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditTabs.java +++ b/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditTabs.java @@ -32,6 +32,7 @@ import com.intellij.ui.tabs.impl.JBEditorTabs; import com.intellij.util.BitUtil; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; @@ -308,7 +309,7 @@ else if (CloseAction.CloseTarget.KEY.is(dataId)) { } private void asyncUpdateTab(@NotNull TabInfo tabInfo) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LightEditorInfo editorInfo = getEditorInfo(tabInfo); if (editorInfo == null) return; EditorNotifications.getInstance(myProject).updateNotifications(editorInfo.getFile()); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/StandalonePluginUpdateChecker.kt b/platform/platform-impl/src/com/intellij/ide/plugins/StandalonePluginUpdateChecker.kt index 8478670cf0c5b..1e7f144a3ccea 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/StandalonePluginUpdateChecker.kt +++ b/platform/platform-impl/src/com/intellij/ide/plugins/StandalonePluginUpdateChecker.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.plugins import com.intellij.ide.IdeBundle @@ -25,6 +25,7 @@ import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.vfs.CharsetToolkit import com.intellij.util.Alarm +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.io.HttpRequests import com.intellij.util.text.VersionComparatorUtil import java.io.IOException @@ -119,7 +120,7 @@ open class StandalonePluginUpdateChecker( } protected fun queueUpdateCheck(callback: (PluginUpdateStatus) -> Boolean) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (checkQueued.compareAndSet(/* expectedValue = */ false, /* newValue = */ true)) { alarm.addRequest( { diff --git a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.kt b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.kt index 15c199724bc81..b1dfeab8ec90e 100644 --- a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.kt @@ -36,6 +36,7 @@ import com.intellij.platform.diagnostic.telemetry.Scope import com.intellij.platform.diagnostic.telemetry.TelemetryManager import com.intellij.serviceContainer.ComponentManagerImpl import com.intellij.util.ModalityUiUtil +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.EDT import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.common.Attributes @@ -469,7 +470,7 @@ private fun launchActivity(activity: ProjectActivity, project: Project, pluginId // allow `invokeAndWait` inside startup activities private suspend fun waitAndProcessInvocationEventsInIdeEventQueue(startupManager: StartupManagerImpl) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val eventQueue = IdeEventQueue.getInstance() if (startupManager.postStartupActivityPassed()) { withContext(Dispatchers.EDT) { diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.kt index d26b412c6a217..1154b2324a564 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.kt @@ -59,6 +59,7 @@ import com.intellij.util.ReflectionUtil import com.intellij.util.childScope import com.intellij.util.concurrency.AppExecutorUtil import com.intellij.util.concurrency.ChildContext +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.createChildContext import com.intellij.util.containers.ContainerUtil import com.intellij.util.ui.StartupUiUtil.addAwtListener @@ -1214,7 +1215,7 @@ open class ActionManagerImpl protected constructor(private val coroutineScope: C contextComponent: Component?, place: String?, now: Boolean): ActionCallback { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val result = ActionCallback() val doRunnable = { tryToExecuteNow(action = action, inputEvent = inputEvent, contextComponent = contextComponent, place = place, result = result) diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java index ce270121e05cf..e915d6680a7fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java @@ -39,6 +39,7 @@ import com.intellij.util.animation.AlphaAnimated; import com.intellij.util.animation.AlphaAnimationContext; import com.intellij.util.concurrency.EdtScheduledExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.Topic; @@ -111,7 +112,7 @@ public static void updateAllToolbarsImmediately() { @ApiStatus.Internal public static void updateAllToolbarsImmediately(boolean includeInvisible) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (ActionToolbarImpl toolbar : new ArrayList<>(ourToolbars)) { toolbar.updateActionsImmediately(includeInvisible); for (Component c : toolbar.getComponents()) { @@ -126,7 +127,7 @@ public static void updateAllToolbarsImmediately(boolean includeInvisible) { @ApiStatus.Internal public static void resetAllToolbars() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Utils.clearAllCachesAndUpdates(); boolean isTestMode = ApplicationManager.getApplication().isUnitTestMode(); for (ActionToolbarImpl toolbar : new ArrayList<>(ourToolbars)) { diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/PreCachedDataContext.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/PreCachedDataContext.java index 7f736f7b2a5eb..7561badb0649e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/PreCachedDataContext.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/PreCachedDataContext.java @@ -24,6 +24,7 @@ import com.intellij.ui.speedSearch.SpeedSearchSupply; import com.intellij.util.SlowOperations; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.*; import com.intellij.util.keyFMap.KeyFMap; import com.intellij.util.ui.EDT; @@ -79,7 +80,7 @@ class PreCachedDataContext implements AsyncDataContext, UserDataHolder, AnAction return; } - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try (AccessToken ignored = ProhibitAWTEvents.start("getData")) { int count = ActivityTracker.getInstance().getCount(); if (ourPrevMapEventCount != count || ApplicationManager.getApplication().isUnitTestMode()) { diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index a74626e46b3a2..4a9d635bf0360 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -1048,13 +1048,13 @@ public void assertIsDispatchThread(@Nullable JComponent component) { } if (Boolean.TRUE.equals(component.getClientProperty(WAS_EVER_SHOWN))) { - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } else { JRootPane root = component.getRootPane(); if (root != null) { component.putClientProperty(WAS_EVER_SHOWN, Boolean.TRUE); - assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java index 4ed1b8157b3eb..1c272802572c6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java @@ -37,10 +37,8 @@ import com.intellij.psi.PsiElement; import com.intellij.util.ArrayUtil; import com.intellij.util.RunnableCallable; -import com.intellij.util.concurrency.AppExecutorUtil; -import com.intellij.util.concurrency.ChildContext; -import com.intellij.util.concurrency.Propagation; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.*; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import io.opentelemetry.api.metrics.Meter; @@ -745,7 +743,7 @@ public String toString() { */ @TestOnly public static void waitForAsyncTaskCompletion() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert !ApplicationManager.getApplication().isWriteAccessAllowed(); for (Submission task : ourTasks) { waitForTask(task); @@ -754,7 +752,7 @@ public static void waitForAsyncTaskCompletion() { @TestOnly private static void waitForTask(@NotNull Submission task) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (ContextConstraint constraint : task.builder.myConstraints) { if (constraint instanceof InSmartMode && !constraint.isCorrectContext()) { return; diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/CommandMerger.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/CommandMerger.java index 86147a45088de..a639dc3113585 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/CommandMerger.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/CommandMerger.java @@ -1,7 +1,6 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.command.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.UndoConfirmationPolicy; import com.intellij.openapi.command.undo.*; @@ -15,6 +14,7 @@ import com.intellij.testFramework.LightVirtualFile; import com.intellij.util.ArrayUtil; import com.intellij.util.ObjectUtils; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -115,7 +115,7 @@ private static boolean isMergeGlobalCommandsAllowed() { // remove all references to document to avoid memory leaks void clearDocumentReferences(@NotNull Document document) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); // DocumentReference for document is not equal to the DocumentReference from the file of that doc, so try both DocumentReference refByFile = DocumentReferenceManager.getInstance().create(document); DocumentReference refByDoc = new DocumentReferenceByDocument(document); diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java index a7bd344d71ca9..5902f372775fa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java @@ -33,6 +33,7 @@ import com.intellij.psi.ExternalChangeAction; import com.intellij.util.ObjectUtils; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -802,7 +803,7 @@ public void clearUndoRedoQueueInTests(@NotNull Document document) { @ApiStatus.Internal public void clearDocumentReferences(@NotNull Document document) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (ClientState state : getAllClientStates()) { state.myUndoStacksHolder.clearDocumentReferences(document); state.myRedoStacksHolder.clearDocumentReferences(document); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java index f733411f2e722..0d6baab605b90 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java @@ -38,6 +38,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.DocumentUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.UIUtil; import org.intellij.lang.annotations.JdkConstants; @@ -908,7 +909,7 @@ public static boolean isCurrentCaretPrimary(@NotNull Editor editor) { } public static void disposeWithEditor(@NotNull Editor editor, @NotNull Disposable disposable) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (editor.isDisposed()) { Disposer.dispose(disposable); return; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java index c7c89f260d596..c11a876dcdbf4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java @@ -29,6 +29,7 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.util.DocumentUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.diff.FilesTooBigForDiffException; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NonNls; @@ -924,7 +925,7 @@ public int getSelectionStart() { @Override public @NotNull VisualPosition getSelectionStartPosition() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); VisualPosition position; SelectionMarker marker = mySelectionMarker; if (hasSelection()) { @@ -946,7 +947,7 @@ public int getSelectionStart() { } LogicalPosition getSelectionStartLogicalPosition() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LogicalPosition position; SelectionMarker marker = mySelectionMarker; if (hasSelection()) { @@ -977,7 +978,7 @@ public int getSelectionEnd() { @Override public @NotNull VisualPosition getSelectionEndPosition() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); VisualPosition position; SelectionMarker marker = mySelectionMarker; if (hasSelection()) { @@ -999,7 +1000,7 @@ public int getSelectionEnd() { } LogicalPosition getSelectionEndLogicalPosition() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LogicalPosition position; SelectionMarker marker = mySelectionMarker; if (hasSelection()) { @@ -1091,7 +1092,7 @@ void doSetSelection(final @NotNull VisualPosition startPosition, myUnknownDirection = false; final Document doc = myEditor.getDocument(); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int textLength = doc.getTextLength(); if (startOffset < 0 || startOffset > textLength) { @@ -1193,7 +1194,7 @@ public void removeSelection() { return; } myCaretModel.doWithCaretMerging(() -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myUnknownDirection = false; RangeMarker marker = mySelectionMarker; if (marker != null && marker.isValid()) { @@ -1276,13 +1277,13 @@ else if (foldRegion.getEndOffset() == endOffset) { @Override public void selectLineAtCaret() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCaretModel.doWithCaretMerging(() -> EditorActionUtil.selectEntireLines(this, true)); } @Override public void selectWordAtCaret(final boolean honorCamelWordsSettings) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCaretModel.doWithCaretMerging(() -> { removeSelection(); final EditorSettings settings = myEditor.getSettings(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CustomFoldRegionImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CustomFoldRegionImpl.java index 07cba993b9136..08e2bfc09f85b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CustomFoldRegionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CustomFoldRegionImpl.java @@ -1,10 +1,10 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.editor.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.util.DocumentUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,7 +64,7 @@ public int getHeightInPixels() { @Override public void update() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myEditor.isDisposed() || !isValid()) return; if (myEditor.myDocumentChangeInProgress) { throw new IllegalStateException("Custom fold region shouldn't be updated during document change"); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java index 7f8dc7adba2d5..11e8c795258fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java @@ -49,6 +49,7 @@ import com.intellij.ui.paint.PaintUtil; import com.intellij.ui.paint.PaintUtil.RoundingMode; import com.intellij.util.ArrayUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.ui.EdtInvocationManager; import com.intellij.util.ui.JBSwingUtilities; @@ -1195,7 +1196,7 @@ public void caretPositionChanged(@NotNull CaretEvent e) { int dot = caret.getOffset(); int mark = caret.getLeadSelectionOffset(); if (myCaretPos != dot) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); firePropertyChange(ACCESSIBLE_CARET_PROPERTY, Integer.valueOf(myCaretPos), Integer.valueOf(dot)); @@ -1203,7 +1204,7 @@ public void caretPositionChanged(@NotNull CaretEvent e) { } if (mark != dot) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); firePropertyChange(ACCESSIBLE_SELECTION_PROPERTY, null, getSelectedText()); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java index acc3f8eac4915..254ef2ff0c259 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java @@ -3,7 +3,6 @@ import com.intellij.codeInsight.editorActions.TextBlockTransferable; import com.intellij.codeInsight.editorActions.TextBlockTransferableData; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actions.BasePasteHandler; import com.intellij.openapi.editor.ex.util.EditorUtil; @@ -12,6 +11,7 @@ import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.DocumentUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,7 +37,7 @@ public final class EditorCopyPasteHelperImpl extends EditorCopyPasteHelper { public @Nullable Transferable getSelectionTransferable(@NotNull Editor editor, @NotNull CopyPasteOptions options) { if (editor.getContentComponent() instanceof JPasswordField) return null; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); List extraData = new ArrayList<>(); String s = editor.getCaretModel().supportsMultipleCarets() ? getSelectedTextForClipboard(editor, options, extraData) : editor.getSelectionModel().getSelectedText(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorEmbeddedComponentManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorEmbeddedComponentManager.java index 9f88fe7a4483e..561c3e814760a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorEmbeddedComponentManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorEmbeddedComponentManager.java @@ -14,6 +14,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.ui.components.JBScrollPane; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.NotNull; @@ -38,7 +39,7 @@ private EditorEmbeddedComponentManager() { } public @Nullable Inlay addComponent(@NotNull EditorEx editor, @NotNull JComponent component, @NotNull Properties properties) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ComponentInlays inlays = getComponentInlaysFor(editor); return inlays.add(component, properties.resizePolicy, properties.rendererFactory, diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java index 3ce693967f938..6e982573bbfaf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java @@ -31,6 +31,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.EventDispatcher; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.text.CharArrayCharSequence; import org.jetbrains.annotations.ApiStatus; @@ -226,7 +227,7 @@ private EditorImpl doCreateEditor(@Nullable Project project, @Override public void releaseEditor(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { EditorFactoryEvent event = new EditorFactoryEvent(this, editor); myEditorFactoryEventDispatcher.getMulticaster().editorReleased(event); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 2a4e824bca891..9e4e60258abce 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -79,6 +79,7 @@ import com.intellij.ui.scale.JBUIScale; import com.intellij.util.*; import com.intellij.util.concurrency.EdtExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.*; @@ -1683,7 +1684,7 @@ private void bulkUpdateFinished() { } private void beforeChangedUpdate(@NotNull DocumentEvent e) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myDocumentChangeInProgress = true; if (isStickySelection()) { @@ -3445,7 +3446,7 @@ private static void logSchemeChangeIfNeeded(@NotNull EditorColorsScheme scheme) } static void assertIsDispatchThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } private static void assertReadAccess() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java index 26096dd2f9fe6..67345b2b86495 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java @@ -54,6 +54,7 @@ import com.intellij.util.Alarm; import com.intellij.util.ObjectUtils; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.*; @@ -490,7 +491,7 @@ public void repaintTrafficLightIcon() { } private void changeStatus(@NotNull AnalyzerStatus newStatus) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!isErrorStripeVisible() || resourcesDisposable.isDisposed()) { return; } @@ -564,7 +565,7 @@ private LightweightHint getCurrentHint() { } // true if tooltip shown private boolean showToolTipByMouseMove(@NotNull MouseEvent e) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LightweightHint currentHint = getCurrentHint(); if (currentHint != null && (myKeepHint || myMouseMovementTracker.isMovingTowards(e, getBoundsOnScreen(currentHint)))) { return true; @@ -775,7 +776,7 @@ public void setErrorStripeVisible(boolean val) { @Override public void setErrorPanelPopupHandler(@NotNull PopupHandler handler) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); MyErrorPanel errorPanel = getErrorPanel(); if (errorPanel != null) { errorPanel.setPopupHandler(handler); @@ -799,7 +800,7 @@ public void setErrorStripTooltipRendererProvider(@NotNull ErrorStripTooltipRende @Override public void setErrorStripeRenderer(@Nullable ErrorStripeRenderer renderer) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myErrorStripeRenderer instanceof Disposable) { Disposer.dispose((Disposable)myErrorStripeRenderer); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMouseHoverPopupControl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMouseHoverPopupControl.java index b8b831a9669da..f33a0d011be73 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMouseHoverPopupControl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMouseHoverPopupControl.java @@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolder; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -55,7 +56,7 @@ public static void enablePopups(@NotNull Project project) { } private static void setTrackingDisabled(@NotNull UserDataHolder holder, boolean value) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Integer userData = holder.getUserData(MOUSE_TRACKING_DISABLED_COUNT); int count = (userData == null ? 0 : userData) + (value ? 1 : -1); if (count < 0) { @@ -72,7 +73,7 @@ private static void setTrackingDisabled(@NotNull UserDataHolder holder, boolean } public static boolean arePopupsDisabled(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Project project = editor.getProject(); return editor.getUserData(MOUSE_TRACKING_DISABLED_COUNT) != null || editor.getDocument().getUserData(MOUSE_TRACKING_DISABLED_COUNT) != null || diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkersModel.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkersModel.java index c99a91a709593..c5ffb8eb340b3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkersModel.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkersModel.java @@ -2,7 +2,6 @@ package com.intellij.openapi.editor.impl; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.ex.*; import com.intellij.openapi.editor.impl.event.MarkupModelListener; import com.intellij.openapi.editor.markup.HighlighterTargetArea; @@ -10,6 +9,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.ProperTextRange; import com.intellij.openapi.util.TextRange; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.EdtInvocationManager; import org.jetbrains.annotations.NotNull; @@ -45,7 +45,7 @@ final class ErrorStripeMarkersModel { } void setActive(boolean value) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (value == (myActiveDisposable != null)) return; @@ -63,7 +63,7 @@ void setActive(boolean value) { } void rebuild() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myActiveDisposable == null) return; @@ -87,7 +87,7 @@ void addErrorMarkerListener(ErrorStripeListener listener, Disposable parent) { } void fireErrorMarkerClicked(RangeHighlighter highlighter, MouseEvent e) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ErrorStripeEvent event = new ErrorStripeEvent(myEditor, e, highlighter); myListeners.forEach(listener -> listener.errorMarkerClicked(event)); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index ecde295e89b37..6b9225be60f5a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -20,6 +20,7 @@ import com.intellij.util.DocumentEventUtil; import com.intellij.util.DocumentUtil; import com.intellij.util.IntPair; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashingStrategy; @@ -197,7 +198,7 @@ void onPlaceholderTextChanged(FoldRegionImpl region) { } private static void assertIsDispatchThreadForEditor() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } private static void assertReadAccess() { ApplicationManager.getApplication().assertReadAccessAllowed(); @@ -381,7 +382,7 @@ public void removeFoldRegion(@NotNull FoldRegion region) { } void removeRegionFromTree(@NotNull FoldRegionImpl region) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myEditor.getFoldingModel().isInBatchFoldingOperation()) { LOG.error("Fold regions must be added or removed inside batchFoldProcessing() only."); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java index 1fc406b2084a3..e25870881a2ce 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java @@ -26,6 +26,7 @@ import com.intellij.ui.EditorNotifications; import com.intellij.util.DocumentEventUtil; import com.intellij.util.DocumentUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -225,7 +226,7 @@ public void forceAdditionalColumnsUsage() { @Override public boolean isSoftWrappingEnabled() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myUseSoftWraps && !myEditor.isPurePaintingMode(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java index f0576bbc4fcdb..50eab919529ef 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java @@ -26,6 +26,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import org.intellij.lang.annotations.JdkConstants; import org.jetbrains.annotations.NotNull; @@ -693,7 +694,7 @@ int getBidiFlags() { } private static void assertIsDispatchThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } private static void assertIsReadAccess() { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java index ef473ff7b6e32..f947a340fc321 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java @@ -3,7 +3,6 @@ import com.intellij.codeHighlighting.BackgroundEditorHighlighter; import com.intellij.ide.structureView.StructureViewBuilder; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.impl.DocumentImpl; @@ -17,6 +16,7 @@ import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.pom.Navigatable; import com.intellij.util.EventDispatcher; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -147,7 +147,7 @@ else if (isValid()) { } protected final void contentLoaded() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Navigatable navigatable = myPendingNavigatable; if (navigatable != null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorComposite.kt b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorComposite.kt index beefeae5e923d..0eaa35143a592 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorComposite.kt +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorComposite.kt @@ -11,7 +11,6 @@ import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.DataProvider import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.actionSystem.PlatformCoreDataKeys -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColorsManager @@ -33,6 +32,7 @@ import com.intellij.ui.components.panels.Wrapper import com.intellij.ui.tabs.JBTabs import com.intellij.ui.tabs.impl.JBTabsImpl import com.intellij.util.EventDispatcher +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.EDT import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -313,7 +313,7 @@ open class EditorComposite internal constructor( } private fun manageTopOrBottomComponent(editor: FileEditor, component: JComponent, top: Boolean, remove: Boolean) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val container = (if (top) topComponents.get(editor) else bottomComponents.get(editor))!! selfBorder = false if (remove) { @@ -426,7 +426,7 @@ open class EditorComposite internal constructor( } fun addEditor(editor: FileEditor, provider: FileEditorProvider) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val editorWithProvider = FileEditorWithProvider(editor, provider) editorsWithProviders.add(editorWithProvider) FileEditor.FILE_KEY.set(editor, file) diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.kt b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.kt index 039f6f34ded9f..9c71e21aa8595 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.kt +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.kt @@ -6,7 +6,6 @@ package com.intellij.openapi.fileEditor.impl import com.intellij.ide.ui.UISettings.Companion.getInstance import com.intellij.ide.ui.UISettingsListener import com.intellij.openapi.Disposable -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.extensions.ExtensionPointListener @@ -21,6 +20,7 @@ import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiDocumentManager +import com.intellij.util.concurrency.ThreadingAssertions import org.jdom.Element import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.VisibleForTesting @@ -89,7 +89,7 @@ class EditorHistoryManager internal constructor(private val project: Project) : * Makes file most recent one */ private fun fileOpenedImpl(file: VirtualFile, fallbackEditor: FileEditor?, fallbackProvider: FileEditorProvider?) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() // don't add files that cannot be found via VFM (light & etc.) if (file !is IncludeInEditorHistoryFile && VirtualFileManager.getInstance().findFileByUrl(file.url) == null) { return diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java index 8f184fe361743..6d8f471b13aa9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java @@ -56,6 +56,7 @@ import com.intellij.util.FileContentUtilCore; import com.intellij.util.Processor; import com.intellij.util.ReflectionUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -272,7 +273,7 @@ public void saveDocuments(@NotNull Predicate filter) { } private void saveDocuments(@Nullable Predicate filter, boolean isExplicit) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ((TransactionGuardImpl)TransactionGuard.getInstance()).assertWriteActionAllowed(); myMultiCaster.beforeAllDocumentsSaving(); @@ -313,7 +314,7 @@ public void saveDocument(@NotNull Document document) { } public void saveDocument(@NotNull Document document, boolean explicit) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ((TransactionGuardImpl)TransactionGuard.getInstance()).assertWriteActionAllowed(); myMultiCaster.beforeAnyDocumentSaving(document, explicit); @@ -706,7 +707,7 @@ public void contentsChanged(@NotNull VFileContentChangeEvent event) { @Override public void reloadFromDisk(@NotNull Document document, @Nullable Project project) { try (AccessToken ignored = ClientId.withClientId(ClientId.getLocalId())) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); VirtualFile file = getFile(document); assert file != null; diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java index 609176738ebbb..1c477c4e23ddf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java @@ -45,6 +45,7 @@ import com.intellij.testFramework.LightVirtualFile; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.concurrency.SynchronizedClearableLazy; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.io.*; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; @@ -127,7 +128,7 @@ public void documentChanged(@NotNull DocumentEvent e) { Document document = e.getDocument(); final VirtualFile file = getFileDocumentManager().getFile(document); if (file != null && !(file instanceof LightVirtualFile) && !ApplicationManager.getApplication().hasWriteAction(ExternalChangeAction.class)) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCurrentCommandHasChanges = true; myChangedFilesInCurrentCommand.add(file); } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/EditorHighlighterUpdater.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/EditorHighlighterUpdater.java index f740d7e2fce4b..ac7adef98a9e1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/EditorHighlighterUpdater.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/EditorHighlighterUpdater.java @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.KeyedLazyInstance; import com.intellij.util.concurrency.NonUrgentExecutor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -165,7 +166,7 @@ public static void completeAsyncTasks() { private final class MyFileTypeListener implements FileTypeListener { @Override public void fileTypesChanged(final @NotNull FileTypeEvent event) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); // File can be invalid after file type changing. The editor should be removed // by the FileEditorManager if it's invalid. FileType type = event.getRemovedFileType(); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.kt b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.kt index 90771dd43c293..d27a624fa897e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.kt +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.kt @@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VirtualFileEvent import com.intellij.openapi.vfs.VirtualFileListener import com.intellij.openapi.vfs.VirtualFilePropertyEvent import com.intellij.util.FileContentUtilCore +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.JBSwingUtilities import org.jetbrains.annotations.ApiStatus.Experimental import org.jetbrains.annotations.ApiStatus.Internal @@ -248,7 +249,7 @@ open class TextEditorComponent( override fun contentsChanged(event: VirtualFileEvent) { // commit if (event.isFromSave) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val file = event.file LOG.assertTrue(file.isValid) if (file == this@TextEditorComponent.file) { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index 183222d92cafe..f2a349cd15fba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -40,6 +40,7 @@ import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile; import com.intellij.openapi.vfs.newvfs.impl.StubVirtualFile; import com.intellij.util.*; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import kotlinx.coroutines.CoroutineScope; @@ -643,7 +644,7 @@ private void tryToResolveMapping(@NotNull String typeName, @NotNull FileNameMatc } public void removePlainTextAssociationsForFile(@NotNull CharSequence fileName) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myPendingInitializationLock.writeLock().lock(); try { makeFileTypesChange("removePlainTextAssociationsForFile("+fileName+")", () -> diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/PotemkinProgress.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/PotemkinProgress.java index b7f269ee700bf..79568a12c25b2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/PotemkinProgress.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/PotemkinProgress.java @@ -13,6 +13,7 @@ import com.intellij.openapi.util.NlsContexts; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,7 +48,7 @@ public PotemkinProgress(@NotNull @NlsContexts.ProgressTitle String title, @Nullable @Nls(capitalization = Nls.Capitalization.Title) String cancelText) { super(cancelText != null,false, project, parentComponent, cancelText); setTitle(title); - myApp.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myApp.getService(DialogWrapperPeerFactory.class); // make sure the service is created myEventStealer = startStealingInputEvents(this::dispatchInputEvent, this); } @@ -142,7 +143,7 @@ private void paintProgress() { /** Executes the action in EDT, paints itself inside checkCanceled calls. */ public void runInSwingThread(@NotNull Runnable action) { - myApp.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { ProgressManager.getInstance().runProcess(action, this); } @@ -155,7 +156,7 @@ public void runInSwingThread(@NotNull Runnable action) { /** Executes the action in a background thread, block Swing thread, handles selected input events and paints itself periodically. */ public void runInBackground(@NotNull Runnable action) { - myApp.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { executeInModalContext(() -> { diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindow.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindow.java index c012beb4c1622..af90bc02711b1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindow.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindow.java @@ -31,6 +31,7 @@ import com.intellij.ui.ComponentUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.concurrency.EdtScheduledExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.Topic; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.ApiStatus.Internal; @@ -97,7 +98,7 @@ public ProgressWindow(boolean shouldShowCancel, } myDialogInitialization = () -> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Window parentWindow = calcParentWindow(parentComponent, myProject); myDialog = new ProgressDialog(this, shouldShowBackground, cancelText, parentWindow); Disposer.register(this, myDialog); @@ -110,12 +111,12 @@ public ProgressWindow(boolean shouldShowCancel, } protected void initializeOnEdtIfNeeded() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); initializeDialog(); } private void initializeDialog() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Runnable initialization = myDialogInitialization; if (initialization == null) return; myDialogInitialization = null; @@ -200,7 +201,7 @@ final void executeInModalContext(@NotNull Runnable modalAction) { @Override public void startBlocking(@NotNull Runnable init, @NotNull CompletableFuture stopCondition) { ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - app.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); synchronized (getLock()) { LOG.assertTrue(!isRunning()); LOG.assertTrue(!myStoppedAlready); @@ -241,7 +242,7 @@ final boolean isCancellationEvent(@NotNull AWTEvent event) { protected void showDialog() { ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - app.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!isRunning() || isCanceled()) { return; } @@ -287,12 +288,12 @@ public void stop() { } @Nullable ProgressDialog getDialog() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myDialog; } public void background() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myDialog != null) { myBackgrounded = true; myDialog.background(); @@ -357,7 +358,7 @@ public void setTitle(@NotNull @ProgressTitle String title) { @Override public void dispose() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myDialogInitialization = null; stopSystemActivity(); if (isRunning()) { @@ -367,7 +368,7 @@ public void dispose() { @Override public boolean isPopupWasShown() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myDialog != null && myDialog.getPopup() != null && myDialog.getPopup().isShowing(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/SmoothProgressAdapter.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/SmoothProgressAdapter.java index f988d04c5d233..45ecc54430412 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/SmoothProgressAdapter.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/SmoothProgressAdapter.java @@ -2,7 +2,6 @@ package com.intellij.openapi.progress.util; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.StandardProgressIndicator; @@ -13,6 +12,7 @@ import com.intellij.openapi.wm.ex.ProgressIndicatorEx; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -92,7 +92,7 @@ public void start() { } public void startBlocking() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); start(); if (isModal()) { showDialog(); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceBalloon.kt b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceBalloon.kt index f19a0e4cb3d0a..e10b9df5ffc1e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceBalloon.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceBalloon.kt @@ -10,7 +10,6 @@ import com.intellij.internal.statistic.service.fus.collectors.UIEventLogger.Dumb import com.intellij.internal.statistic.service.fus.collectors.UIEventLogger.DumbModeBalloonShown import com.intellij.internal.statistic.service.fus.collectors.UIEventLogger.DumbModeBalloonWasNotNeeded import com.intellij.openapi.actionSystem.DataContext -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.ui.MessageType import com.intellij.openapi.ui.popup.Balloon @@ -22,6 +21,7 @@ import com.intellij.openapi.util.NlsContexts import com.intellij.ui.awt.RelativePoint import com.intellij.ui.scale.JBUIScale.scale import com.intellij.util.TimeoutUtil +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.JBInsets class DumbServiceBalloon(private val myProject: Project, @@ -44,7 +44,7 @@ class DumbServiceBalloon(private val myProject: Project, runWhenSmartAndBalloonStillShowing: Runnable, runWhenCancelled: Runnable) { if (LightEdit.owns(myProject)) return - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (!myService.isDumb) { DumbModeBalloonWasNotNeeded.log(myProject) runWhenSmartAndBalloonStillShowing.run() diff --git a/platform/platform-impl/src/com/intellij/openapi/project/SmartModeScheduler.kt b/platform/platform-impl/src/com/intellij/openapi/project/SmartModeScheduler.kt index c040d63418df3..faf5fa4996032 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/SmartModeScheduler.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/SmartModeScheduler.kt @@ -18,6 +18,7 @@ import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.startup.ProjectActivity import com.intellij.util.childScope +import com.intellij.util.concurrency.ThreadingAssertions import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @@ -119,7 +120,7 @@ class SmartModeScheduler(private val project: Project, sc: CoroutineScope) : Dis // We need EDT or WriteLock to make sure that dumb mode does not start while the method is in progress (see DumbServiceImpl.updateFinished). // Note that neither write lock nor EDT are enough to protect against switching to "almost smart": scanning can start at any moment // (it does not need write lock nor EDT), so the code should be ready for scanning to start at any moment. - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() // It may happen that one of the pending runWhenSmart actions triggers new dumb mode; // in this case we should quit processing pending actions and postpone them until the newly started dumb mode finishes. diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt index b4a531f629ff2..355b8d5e346f5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt @@ -69,6 +69,7 @@ import com.intellij.util.BitUtil import com.intellij.util.EventDispatcher import com.intellij.util.SingleAlarm import com.intellij.util.SystemProperties +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.messages.SimpleMessageBusConnection import com.intellij.util.ui.EDT @@ -531,7 +532,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( @Deprecated("Use {{@link #registerToolWindow(RegisterToolWindowTask)}}") fun initToolWindow(bean: ToolWindowEP) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() runWithModalProgressBlocking(project, "") { initToolWindow(bean, bean.pluginDescriptor) } @@ -618,7 +619,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( } open fun activateToolWindow(id: String, runnable: Runnable?, autoFocusContents: Boolean, source: ToolWindowEventSource? = null) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val activity = UiActivity.Focus("toolWindow:$id") UiActivityMonitor.getInstance().addActivity(project, activity, ModalityState.nonModal()) @@ -1025,7 +1026,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( } override fun registerToolWindow(task: RegisterToolWindowTask): ToolWindow { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() // Try to get a previously saved tool window pane, if possible val toolWindowPane = this.getLayout().getInfo(task.id)?.toolWindowPaneId?.let { getToolWindowPane(it) } @@ -1163,7 +1164,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( private fun doUnregisterToolWindow(id: String) { LOG.debug { "unregisterToolWindow($id)" } - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() ActivateToolWindowAction.unregister(id) val entry = idToEntry.remove(id) ?: return @@ -1250,7 +1251,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( } override fun getLayout(): DesktopLayout { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() return layoutState } @@ -1263,7 +1264,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( } override fun setLayout(newLayout: DesktopLayout) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (idToEntry.isEmpty()) { layoutState = newLayout @@ -1637,7 +1638,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( return } - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() setToolWindowAnchorImpl(entry, info, getRegisteredMutableInfoOrLogError(id), info.safeToolWindowPaneId, anchor, order, layoutState) getToolWindowPane(info.safeToolWindowPaneId).validateAndRepaint() fireStateChanged(ToolWindowManagerEventType.SetToolWindowAnchor, entry.toolWindow) @@ -1836,7 +1837,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( } fun setToolWindowType(id: String, type: ToolWindowType) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val entry = idToEntry.get(id)!! if (entry.readOnlyWindowInfo.type == type) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerState.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerState.kt index a03bcc6dc35e0..9a33b4ee9a3cd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerState.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerState.kt @@ -1,7 +1,6 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.wm.impl -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.components.State import com.intellij.openapi.components.Storage @@ -13,6 +12,7 @@ import com.intellij.openapi.wm.IdeFocusManager import com.intellij.openapi.wm.ToolWindowAnchor import com.intellij.ui.ComponentUtil import com.intellij.ui.ExperimentalUI +import com.intellij.util.concurrency.ThreadingAssertions import org.jdom.Element import org.jetbrains.annotations.ApiStatus import java.util.* @@ -50,7 +50,7 @@ class ToolWindowManagerStateImpl : ToolWindowManagerState { override val isEditorComponentActive: Boolean get() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() return ComponentUtil.getParentOfType(EditorsSplitters::class.java, IdeFocusManager.getGlobalInstance().focusOwner) != null } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.kt index 1421b9d60d154..68fe972ef3d17 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.kt @@ -45,6 +45,7 @@ import com.intellij.ui.awt.RelativePoint import com.intellij.ui.components.ActionLink import com.intellij.ui.components.JBPanel import com.intellij.ui.components.panels.NonOpaquePanel +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.containers.JBIterable import com.intellij.util.flow.throttle @@ -233,7 +234,7 @@ class InfoAndProgressPanel internal constructor(private val statusBar: IdeStatus @RequiresEdt fun addProgress(original: ProgressIndicatorEx, info: TaskInfo) { // `openProcessPopup` may require the dispatch thread - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() synchronized(originals) { if (originals.isEmpty()) { mainPanel.updateNavBarAutoscrollToSelectedLimit(AutoscrollLimit.ALLOW_ONCE) @@ -266,7 +267,7 @@ class InfoAndProgressPanel internal constructor(private val statusBar: IdeStatus @RequiresEdt private fun removeProgress(progress: MyInlineProgressIndicator) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() synchronized(originals) { // already disposed if (!inlineToOriginal.containsKey(progress)) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java index fe1be74e21955..085b9fc3a9751 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java @@ -9,7 +9,6 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.JBMenuItem; @@ -21,6 +20,7 @@ import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.ClickListener; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.text.DateFormatUtil; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; @@ -150,7 +150,7 @@ public boolean isEnabled() { // Returns the alarm used for displaying status messages in the status bar, or null if the status bar is attached to a floating // editor window. private @Nullable Alarm getAlarm() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myLogAlarm == null || myLogAlarm.isDisposed()) { myLogAlarm = null; //Welcome screen Project project = getActiveProject(); @@ -162,7 +162,7 @@ public boolean isEnabled() { } public boolean updateText(@Nullable @NlsContexts.StatusBarText String nonLogText) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Project project = getActiveProject(); StatusMessage statusMessage = NotificationsToolWindowFactory.Companion.getStatusMessage(project); diff --git a/platform/platform-impl/src/com/intellij/platform/ide/menu/GlobalMenuLinux.java b/platform/platform-impl/src/com/intellij/platform/ide/menu/GlobalMenuLinux.java index 0581bc45682c9..2f4bf63ef2efd 100644 --- a/platform/platform-impl/src/com/intellij/platform/ide/menu/GlobalMenuLinux.java +++ b/platform/platform-impl/src/com/intellij/platform/ide/menu/GlobalMenuLinux.java @@ -27,6 +27,7 @@ import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.impl.LinuxGlobalMenuEventHandler; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.system.CpuArch; import com.intellij.util.ui.ImageUtil; import com.sun.jna.Callback; @@ -383,7 +384,7 @@ public void setRoots(List roots) { return; } - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int[] stats = new int[]{0, 0, 0}; final int size = roots == null ? 0 : roots.size(); diff --git a/platform/platform-impl/src/com/intellij/ui/ActionCenterBalloonLayout.kt b/platform/platform-impl/src/com/intellij/ui/ActionCenterBalloonLayout.kt index b28ca7887792d..9a5c2c1de9f48 100644 --- a/platform/platform-impl/src/com/intellij/ui/ActionCenterBalloonLayout.kt +++ b/platform/platform-impl/src/com/intellij/ui/ActionCenterBalloonLayout.kt @@ -8,13 +8,13 @@ import com.intellij.notification.Notification import com.intellij.notification.impl.NotificationsManagerImpl import com.intellij.notification.impl.ui.NotificationsUtil import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.ui.popup.Balloon import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.util.Disposer import com.intellij.openapi.wm.impl.IdeRootPane import com.intellij.ui.components.labels.LinkLabel import com.intellij.ui.components.labels.LinkListener +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.JBFont import com.intellij.util.ui.JBInsets import com.intellij.util.ui.JBUI @@ -36,7 +36,7 @@ internal class ActionCenterBalloonLayout(parent: IdeRootPane, insets: Insets) : } override fun add(newBalloon: Balloon, layoutData: Any?) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (layoutData is BalloonLayoutData) { if (layoutData.collapseType == null) { diff --git a/platform/platform-impl/src/com/intellij/ui/SpeedSearchBase.java b/platform/platform-impl/src/com/intellij/ui/SpeedSearchBase.java index 8e9e08793aa70..11573e3226bd7 100644 --- a/platform/platform-impl/src/com/intellij/ui/SpeedSearchBase.java +++ b/platform/platform-impl/src/com/intellij/ui/SpeedSearchBase.java @@ -26,7 +26,7 @@ import com.intellij.ui.speedSearch.SpeedSearch; import com.intellij.ui.speedSearch.SpeedSearchSupply; import com.intellij.util.ReflectionUtil; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.text.NameUtilCore; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; @@ -45,8 +45,6 @@ import java.awt.event.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -import java.util.Comparator; -import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; @@ -204,7 +202,7 @@ public void setClearSearchOnNavigateNoMatch(boolean clearSearchOnNavigateNoMatch @Override public boolean isPopupActive() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return mySearchPopup != null && mySearchPopup.isVisible() || isStickySearch() && Strings.isNotEmpty(myComponent == null ? null : ClientProperty.get(myComponent, SEARCH_TEXT_KEY)); diff --git a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java index d2c4adc0947d6..78dc2ddb3a81e 100644 --- a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java @@ -19,6 +19,7 @@ import com.intellij.ui.content.*; import com.intellij.util.EventDispatcher; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NonNls; @@ -171,7 +172,7 @@ public void addContent(@NotNull Content content) { } private void doAddContent(final @NotNull Content content, final int index) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myContents.contains(content)) { myContents.remove(content); myContents.add(index < 0 ? myContents.size() : index, content); @@ -239,7 +240,7 @@ public boolean removeContent(@NotNull Content content, boolean dispose) { } private @NotNull ActionCallback doRemoveContent(@NotNull Content content, boolean dispose) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int indexToBeRemoved = getIndexOfContent(content); if (indexToBeRemoved == -1) { return ActionCallback.REJECTED; diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index 72fc738603322..3543b59c6971f 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -49,6 +49,7 @@ import com.intellij.ui.speedSearch.ListWithFilter; import com.intellij.ui.speedSearch.SpeedSearch; import com.intellij.util.*; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.WeakList; import com.intellij.util.ui.*; @@ -972,7 +973,7 @@ public void show(@NotNull Component owner, int aScreenX, int aScreenY, final boo throw new IllegalStateException("Popup was already disposed. Recreate a new instance to show again"); } - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert myState == State.INIT : "Popup was already shown. Recreate a new instance to show again."; debugState("show popup", State.INIT); @@ -1681,7 +1682,7 @@ public Project getProject() { @Override public void dispose() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myState == State.SHOWN) { LOG.debug("shown popup must be cancelled"); cancel(); diff --git a/platform/platform-impl/src/com/intellij/util/PendingEventDispatcher.java b/platform/platform-impl/src/com/intellij/util/PendingEventDispatcher.java index d6bff546e66b9..0f0a9cacc8f4c 100644 --- a/platform/platform-impl/src/com/intellij/util/PendingEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/util/PendingEventDispatcher.java @@ -6,6 +6,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Disposer; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NonNls; @@ -145,7 +146,7 @@ public void run() { private void assertDispatchThread() { Application application = ApplicationManager.getApplication(); if (myAssertDispatchThread && !application.isUnitTestMode()) { - application.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } } diff --git a/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java b/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java index d1a86a8f137ef..4579be561af76 100644 --- a/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/concurrency/JobUtilTest.java @@ -40,6 +40,7 @@ import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.EdtScheduledExecutorService; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -191,7 +192,7 @@ private void checkProgressAndReadAction(@NotNull List objects, ThrowableRunnable runnable = () -> { try { if (objects.size() <= 1 || JobSchedulerImpl.getJobPoolParallelism() <= JobLauncherImpl.CORES_FORK_THRESHOLD) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } else { // generally, we know nothing about the current thread since FJP can help other tasks to execute while in the current context diff --git a/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java b/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java index d92a28a5ab671..b3e9ccf955cf2 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java @@ -37,6 +37,7 @@ import com.intellij.util.Consumer; import com.intellij.util.LineSeparator; import com.intellij.util.TimeoutUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -141,7 +142,7 @@ public void testConsolePrintsSomethingAfterClearPrintScroll() { } public void testClearAndPrintWhileAnotherClearExecution() throws Exception { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ConsoleViewImpl console = myConsole; for (int i = 0; i < 100; i++) { // To speed up test execution, set -Dconsole.flush.delay.ms=5 to reduce ConsoleViewImpl.DEFAULT_FLUSH_DELAY diff --git a/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java b/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java index d52cb2d5c9ecb..9c6fa833b9678 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java @@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.BusyObject; import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -113,7 +114,7 @@ public void testReadyWithWatchActivities() { public void testModalityState() { assumeFalse("Test cannot be run in headless environment", GraphicsEnvironment.isHeadless()); assertTrue(ApplicationManager.getApplication().getClass().getName().contains("ApplicationImpl")); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertReady(null); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/AppUIExecutorTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/AppUIExecutorTest.kt index 11dd63f5b87af..3d2b41dad6046 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/AppUIExecutorTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/AppUIExecutorTest.kt @@ -11,6 +11,7 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFileFactory import com.intellij.testFramework.LightPlatformTestCase import com.intellij.util.ThrowableRunnable +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.UIUtil import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel @@ -92,7 +93,7 @@ class AppUIExecutorTest : LightPlatformTestCase() { fun `test coroutine onUiThread`() { val executor = AppUIExecutor.onUiThread(ModalityState.any()) GlobalScope.async(executor.coroutineDispatchingContext()) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() }.joinNonBlocking() } @@ -109,7 +110,7 @@ class AppUIExecutorTest : LightPlatformTestCase() { queue.add("start") launch(executor.coroutineDispatchingContext()) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() queue.add("coroutine start") Disposer.dispose(disposable) @@ -119,7 +120,7 @@ class AppUIExecutorTest : LightPlatformTestCase() { queue.add("coroutine after yield") } catch (e: Exception) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() queue.add("coroutine yield caught ${e.javaClass.simpleName}") throw e } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java index c5c84480bca6b..a1353861be03c 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java @@ -25,6 +25,7 @@ import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -71,7 +72,7 @@ private void runReadWrites(final int readIterations, final int writeIterations, final ApplicationImpl application = (ApplicationImpl)ApplicationManager.getApplication(); Disposable disposable = Disposer.newDisposable(); application.disableEventsUntil(disposable); - application.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); try { PlatformTestUtil.startPerformanceTest("lock/unlock "+getTestName(false), expectedMs, () -> { @@ -125,7 +126,7 @@ private void checkTimeout() throws Throwable { public void testAppLockReadWritePreference() throws Throwable { ApplicationImpl application = (ApplicationImpl)ApplicationManager.getApplication(); - application.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertFalse(application.isWriteAccessAllowed()); assertFalse(application.isWriteActionPending()); @@ -455,7 +456,7 @@ public void testRunProcessWithProgressFromPooledThread() throws Throwable { public void testRWLockPerformance() throws Throwable { pumpEventsFor(2, TimeUnit.SECONDS); int readIterations = 200_000_000; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ReadMostlyRWLock lock = new ReadMostlyRWLock(Thread.currentThread()); final int numOfThreads = JobSchedulerImpl.getJobPoolParallelism(); final Field myThreadLocalsField = Objects.requireNonNull(ReflectionUtil.getDeclaredField(Thread.class, "threadLocals")); @@ -475,7 +476,7 @@ public Void call() { }); PlatformTestUtil.startPerformanceTest("RWLock/unlock", 27_000, ()-> { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertFalse(ApplicationManager.getApplication().isWriteAccessAllowed()); List> futures = AppExecutorUtil.getAppExecutorService().invokeAll(callables); ConcurrencyUtil.getAll(futures); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/EdtCoroutineDispatcherTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/EdtCoroutineDispatcherTest.kt index a9be627cd9726..87972e7da3045 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/EdtCoroutineDispatcherTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/EdtCoroutineDispatcherTest.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.progress.runBlockingMaybeCancellable import com.intellij.testFramework.LeakHunter import com.intellij.testFramework.common.timeoutRunBlocking import com.intellij.testFramework.junit5.TestApplication +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.UIUtil import kotlinx.coroutines.* import org.junit.jupiter.api.Assertions.assertSame @@ -25,7 +26,7 @@ class EdtCoroutineDispatcherTest { @Test fun `dispatch thread`(): Unit = timeoutRunBlocking { withContext(Dispatchers.EDT) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaterInvocatorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaterInvocatorTest.java index c8f3fedc048ed..01756cecea1cd 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaterInvocatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaterInvocatorTest.java @@ -13,6 +13,7 @@ import com.intellij.testFramework.*; import com.intellij.util.ObjectUtils; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ref.GCWatcher; import com.intellij.util.ui.UIUtil; import junit.framework.TestCase; @@ -352,7 +353,7 @@ static void flushSwingQueue() { } private void blockSwingThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); SwingUtilities.invokeLater(new Lock(this)); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkupModelTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkupModelTest.java index 40a987c86fdb3..e2b08d423ec93 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkupModelTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkupModelTest.java @@ -12,6 +12,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.SeparatorPlacement; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -25,7 +26,7 @@ public class MarkupModelTest extends AbstractEditorTest { public void testMarkupModelListenersDoWork() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); initText(" ".repeat(100)); Document document = getDocument(getFile()); MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, getProject(), true); @@ -78,7 +79,7 @@ public void attributesChanged(@NotNull RangeHighlighterEx highlighter, boolean r } public void testMarkupModelListenersMustWorkInBGT() throws ExecutionException, InterruptedException { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); initText(" ".repeat(100)); Document document = getDocument(getFile()); List events = ContainerUtil.createLockFreeCopyOnWriteList(); @@ -100,7 +101,7 @@ private void assertEventsFired(List expected, List actualEvents, } public void testRangeMarkerTreeClearMustFireRemoveEvents() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); initText(" ".repeat(100)); Document document = getDocument(getFile()); MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, getProject(), true); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java index 39c3352ae9785..3ef33927d8ffc 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java @@ -23,6 +23,7 @@ import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.Semaphore; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import it.unimi.dsi.fastutil.longs.LongArrayList; @@ -233,7 +234,7 @@ public void onSuccess() { } }, myIndicator, null); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); while (!future.isDone()) { if (System.currentTimeMillis() < warmupEnd) { @@ -1038,7 +1039,7 @@ public void testComplexCheckCanceledHookDoesntInterfereWithReadLockAcquire() thr ProgressIndicator indicator = new ProgressIndicatorBase(false); indicator.start(); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); AtomicReference> future = new AtomicReference<>(); doReadAction(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/project/DumbServiceImplTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/project/DumbServiceImplTest.kt index dcf4b1abd8563..5f91f7184d048 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/project/DumbServiceImplTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/project/DumbServiceImplTest.kt @@ -22,6 +22,7 @@ import com.intellij.util.ArrayUtil import com.intellij.util.SystemProperties import com.intellij.util.application import com.intellij.util.concurrency.Semaphore +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.indexing.FileBasedIndex import com.intellij.util.indexing.FileBasedIndexImpl import com.intellij.util.indexing.contentQueue.IndexUpdateRunner @@ -242,7 +243,7 @@ class DumbServiceImplTest { runInEdtAndWait { dumbService.runWhenSmart { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() assertFalse(application.isWriteAccessAllowed) invocations++ phaser.arriveAndDeregister() //3 diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java index a4ed2cf158a6a..35f72096d9e86 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java @@ -46,6 +46,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtilRt; import com.intellij.util.TimeoutUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.text.ByteArrayCharSequence; import com.intellij.util.text.XmlCharsetDetector; import com.intellij.util.ui.UIUtil; @@ -1074,7 +1075,7 @@ public Charset extractCharsetFromFileContent(@Nullable Project project, @Nullabl UIUtil.dispatchAllInvocationEvents(); FileEditorManager.getInstance(getProject()).closeFile(file); - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (exception.get() != null) { throw exception.get(); diff --git a/platform/platform-tests/testSrc/com/intellij/util/concurrency/QueueProcessorTest.kt b/platform/platform-tests/testSrc/com/intellij/util/concurrency/QueueProcessorTest.kt index 2c724c119950b..f044ccd58a1c1 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/concurrency/QueueProcessorTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/util/concurrency/QueueProcessorTest.kt @@ -85,7 +85,7 @@ class QueueProcessorTest : LightPlatformTestCase() { fun `test it's a bad idea to wait in EDT`() { val processor = QueueProcessor({ _, r -> r.run()}, true, QueueProcessor.ThreadToUse.AWT, { _ -> false }) processor.add("") - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() assertThrows(Exception::class.java) { processor.waitFor() } assertThrows(Exception::class.java) { processor.waitFor(1) } PlatformTestUtil.waitForFuture(ApplicationManager.getApplication().executeOnPooledThread { processor.waitFor() }, 100_000) diff --git a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java index 2c3ec792085da..c82c9641b1431 100644 --- a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java @@ -56,6 +56,7 @@ import com.intellij.util.SmartList; import com.intellij.util.ThrowableRunnable; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import junit.framework.TestCase; @@ -987,7 +988,7 @@ public static void saveEncodingsIn(@NotNull Project projec } public static void buildInitialFoldingsInBackground(@NotNull Editor editor) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assert !ApplicationManager.getApplication().isWriteAccessAllowed(); CodeFoldingState foldingState; try { diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 4fe71128835ac..1e635a1ad3776 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -67,6 +67,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.LocalTimeCounter; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.PathKt; import com.intellij.util.messages.MessageBusConnection; @@ -250,7 +251,7 @@ protected void setUp() throws Exception { Ref reusedProject = new Ref<>(true); app.invokeAndWait(() -> { IdeaLogger.ourErrorsOccurred = null; - app.assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myOldSdks = new SdkLeakTracker(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index a96ed1c0f40aa..111e27373144d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -69,6 +69,7 @@ import com.intellij.util.*; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.AppScheduledExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.Decompressor; import com.intellij.util.lang.JavaVersion; @@ -302,7 +303,7 @@ private static void assertDispatchThreadWithoutWriteAccess() { } else { assert !application.isWriteAccessAllowed() : "do not wait under write action to avoid possible deadlock"; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/ThreadTracker.java b/platform/testFramework/src/com/intellij/testFramework/ThreadTracker.java index 290eb583a7f03..0fbaac6c6895f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ThreadTracker.java +++ b/platform/testFramework/src/com/intellij/testFramework/ThreadTracker.java @@ -1,12 +1,12 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.testFramework; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.psi.stubs.StubIndex; import com.intellij.psi.stubs.StubIndexImpl; import com.intellij.testFramework.common.ThreadLeakTracker; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileBasedIndexEx; @@ -30,7 +30,7 @@ public ThreadTracker() { @TestOnly public void checkLeak() throws AssertionError { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ((FileBasedIndexEx)FileBasedIndex.getInstance()).waitUntilIndicesAreInitialized(); ((StubIndexImpl)StubIndex.getInstance()).waitUntilStubIndexedInitialized(); ThreadLeakTracker.awaitQuiescence(); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java index 616b32b5c66f1..cdf472f7943cd 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsProgressAnimator.java @@ -1,26 +1,12 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.execution.testframework.ui; import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.icons.AllIcons; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Disposer; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -103,13 +89,13 @@ public void stopMovie() { @Override public synchronized void dispose() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCurrentTestCase = null; Disposer.dispose(myAlarm); } private void repaintSubTree() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); AbstractTestProxy testProxy = myCurrentTestCase; if (testProxy != null) { myTreeBuilder.repaintWithParents(testProxy); diff --git a/platform/usageView-impl/src/com/intellij/usages/actions/RemoveUsageAction.java b/platform/usageView-impl/src/com/intellij/usages/actions/RemoveUsageAction.java index 4e8d188efec4a..794a00ea7ed5b 100644 --- a/platform/usageView-impl/src/com/intellij/usages/actions/RemoveUsageAction.java +++ b/platform/usageView-impl/src/com/intellij/usages/actions/RemoveUsageAction.java @@ -18,10 +18,10 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.usages.Usage; import com.intellij.usages.UsageView; import com.intellij.usages.impl.UsageViewImpl; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -41,7 +41,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { } private static void process(Usage @NotNull [] usages, @NotNull UsageView usageView) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (usages.length == 0) return; Arrays.sort(usages, UsageViewImpl.USAGE_COMPARATOR_BY_FILE_AND_OFFSET); final Usage nextToSelect = getNextToSelect(usageView, usages[usages.length - 1]); diff --git a/platform/usageView-impl/src/com/intellij/usages/impl/GroupNode.java b/platform/usageView-impl/src/com/intellij/usages/impl/GroupNode.java index 6a0a147204cc5..ef8af33b667c7 100644 --- a/platform/usageView-impl/src/com/intellij/usages/impl/GroupNode.java +++ b/platform/usageView-impl/src/com/intellij/usages/impl/GroupNode.java @@ -4,7 +4,6 @@ import com.intellij.ide.tags.TagManager; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vcs.FileStatus; @@ -21,6 +20,7 @@ import com.intellij.util.IconUtil; import com.intellij.util.ObjectUtils; import com.intellij.util.SmartList; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; @@ -125,7 +125,7 @@ private static int getNodeInsertionIndex(@NotNull Node node, @NotNull List usages, @NotNull DefaultTreeModel treeModel) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int removed = 0; synchronized (this) { List removedNodes = new SmartList<>(); @@ -262,7 +262,7 @@ UsageNode addOrGetUsage(@NotNull Usage usage, } void incrementUsageCount(int i) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); GroupNode groupNode = this; while (true) { groupNode.myRecursiveUsageCount += i; @@ -335,7 +335,7 @@ public synchronized UsageGroup getGroup() { } int getRecursiveUsageCount() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myRecursiveUsageCount; } diff --git a/platform/usageView-impl/src/com/intellij/usages/impl/Node.java b/platform/usageView-impl/src/com/intellij/usages/impl/Node.java index 5f7c57e40fbeb..2cf00e6712457 100644 --- a/platform/usageView-impl/src/com/intellij/usages/impl/Node.java +++ b/platform/usageView-impl/src/com/intellij/usages/impl/Node.java @@ -5,6 +5,7 @@ import com.intellij.usages.UsageNodePresentation; import com.intellij.util.BitUtil; import com.intellij.util.Consumer; +import com.intellij.util.concurrency.ThreadingAssertions; import org.intellij.lang.annotations.MagicConstant; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -141,7 +142,7 @@ protected void updateNotify() { // same as DefaultMutableTreeNode.insert() except it doesn't try to remove the newChild from its parent since we know it's new void insertNewNode(@NotNull Node newChild, int childIndex) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (children == null) { //obsolete type is required by platform superclass //noinspection UseOfObsoleteCollectionType diff --git a/platform/usageView-impl/src/com/intellij/usages/impl/UsagePreviewPanel.kt b/platform/usageView-impl/src/com/intellij/usages/impl/UsagePreviewPanel.kt index a472d61d427d2..6cfe2fb5515bc 100644 --- a/platform/usageView-impl/src/com/intellij/usages/impl/UsagePreviewPanel.kt +++ b/platform/usageView-impl/src/com/intellij/usages/impl/UsagePreviewPanel.kt @@ -12,7 +12,10 @@ import com.intellij.lang.injection.InjectedLanguageManager import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.DataProvider import com.intellij.openapi.actionSystem.PlatformCoreDataKeys -import com.intellij.openapi.application.* +import com.intellij.openapi.application.EDT +import com.intellij.openapi.application.ModalityState +import com.intellij.openapi.application.asContextElement +import com.intellij.openapi.application.readAction import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.* import com.intellij.openapi.editor.colors.EditorColors @@ -49,6 +52,7 @@ import com.intellij.usages.UsageView import com.intellij.usages.UsageViewPresentation import com.intellij.usages.similarity.clustering.ClusteringSearchSession import com.intellij.util.childScope +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.concurrency.annotations.RequiresReadLock @@ -160,7 +164,7 @@ open class UsagePreviewPanel @JvmOverloads constructor(project: Project, var lineHeight: Int get() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() return myLineHeight } private set(lineHeight) { @@ -221,7 +225,7 @@ open class UsagePreviewPanel @JvmOverloads constructor(project: Project, } fun releaseEditor() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (myEditor != null) { EditorFactory.getInstance().releaseEditor(myEditor!!) myEditor = null @@ -375,7 +379,7 @@ open class UsagePreviewPanel @JvmOverloads constructor(project: Project, project: Project, highlightOnlyNameElements: Boolean, highlightLayer: Int) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() LOG.assertTrue(PsiDocumentManager.getInstance(project).isCommitted(editor.document)) val markupModel = editor.markupModel for (highlighter in markupModel.allHighlighters) { @@ -457,7 +461,7 @@ open class UsagePreviewPanel @JvmOverloads constructor(project: Project, private val REPLACEMENT_BALLOON_KEY = Key.create("REPLACEMENT_BALLOON_KEY") private fun showBalloon(project: Project, editor: Editor, range: TextRange, findModel: FindModel) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() try { val replacementPreviewText = FindManager.getInstance(project) .getStringToReplace(editor.document.getText(range), findModel, range.startOffset, @@ -562,7 +566,7 @@ open class UsagePreviewPanel @JvmOverloads constructor(project: Project, } private fun insideVisibleArea(e: Editor, r: TextRange): Boolean { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val textLength = e.document.textLength if (r.startOffset > textLength) return false if (r.endOffset > textLength) return false diff --git a/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewImpl.java index b74c57e11c375..00d3bc6d34c5b 100644 --- a/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewImpl.java @@ -53,6 +53,7 @@ import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.concurrency.BoundedTaskExecutor; import com.intellij.util.concurrency.EdtExecutorService; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.JBIterable; import com.intellij.util.containers.MultiMap; @@ -290,7 +291,7 @@ public boolean isActionEnabled(boolean isExcludeAction) { @Override public void onDone(boolean isExcludeAction) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myRootPanel.hasNextOccurence()) { myRootPanel.goNextOccurence(); } @@ -306,7 +307,7 @@ public int getId() { } private void initInEDT() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; myTree = new Tree(myModel) { { @@ -505,7 +506,7 @@ public int hashCode() { * this method is called regularly every 50ms to fire events in batch */ private void fireEvents() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); syncModelWithSwingNodes(); fireEventsForChangedNodes(); @@ -639,12 +640,12 @@ public void cancelCurrentSearch() { } private int getVisibleRowCount() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return TreeUtil.getVisibleRowCount(myTree); } private void setupCentralPanel() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); JScrollPane treePane = ScrollPaneFactory.createScrollPane(myTree); myPreviewSplitter = new OnePixelSplitter(false, 0.5f, 0.1f, 0.9f); @@ -659,7 +660,7 @@ private void setupCentralPanel() { } private void updateUsagesContextPanels() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); disposeUsageContextPanels(); if (isPreviewUsages()) { myPreviewSplitter.setProportion(getUsageViewSettings().getPreviewUsagesSplitterProportion()); @@ -715,14 +716,14 @@ private void updateUsagesContextPanels() { } private void tabSelected(@NotNull UsageContextPanel.Provider provider) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myCurrentUsageContextProvider = provider; updateUsagesContextPanels(); updateOnSelectionChanged(); } private void disposeUsageContextPanels() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myAllUsageContextPanels.isEmpty()) { saveSplitterProportions(); for (UsageContextPanel panel : myAllUsageContextPanels) { @@ -775,7 +776,7 @@ void setPreviewUsages(boolean state) { } private void initTree() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myTree.setShowsRootHandles(true); SmartExpander.installOn(myTree); TreeUtil.installActions(myTree); @@ -816,7 +817,7 @@ public void treeCollapsed(TreeExpansionEvent event) { @NotNull private JComponent createActionsToolbar() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); DefaultActionGroup group = new DefaultActionGroup() { @Override @@ -847,7 +848,7 @@ public boolean isDumbAware() { @NotNull private JComponent toUsageViewToolbar(@NotNull DefaultActionGroup group) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, group, false); actionToolbar.setTargetComponent(myRootPanel); return actionToolbar.getComponent(); @@ -859,7 +860,7 @@ protected boolean isPreviewUsageActionEnabled() { } public void addFilteringActions(@NotNull DefaultActionGroup group) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); addFilteringActions(group, true); } @@ -923,7 +924,7 @@ public boolean canCollapse() { }; protected AnAction @NotNull [] createActions() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); CommonActionsManager actionsManager = CommonActionsManager.getInstance(); @@ -1031,14 +1032,14 @@ protected void sortGroupingActions(@NotNull List actions) { } private boolean shouldTreeReactNowToRuleChanges() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myPresentation.isDetachedMode() || myTree.isShowing(); } private boolean rulesChanged; // accessed in EDT only private void rulesChanged() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!shouldTreeReactNowToRuleChanges()) { rulesChanged = true; return; @@ -1081,7 +1082,7 @@ private void rulesChanged() { } private void captureUsagesExpandState(@NotNull TreePath pathFrom, @NotNull Collection states) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!myTree.isExpanded(pathFrom)) { return; } @@ -1100,7 +1101,7 @@ private void captureUsagesExpandState(@NotNull TreePath pathFrom, @NotNull Colle } private void restoreUsageExpandState(@NotNull Collection states) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); //always expand the last level group DefaultMutableTreeNode root = (DefaultMutableTreeNode)myTree.getModel().getRoot(); for (int i = root.getChildCount() - 1; i >= 0; i--) { @@ -1126,7 +1127,7 @@ private void expandTree(int levels) { private void doExpandingCollapsing(@NotNull Runnable task) { if (isDisposed()) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); fireEvents(); // drain all remaining insertion events in the queue myExpandingCollapsing = true; @@ -1151,12 +1152,12 @@ public void expandRoot() { @NotNull DefaultMutableTreeNode getModelRoot() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return (DefaultMutableTreeNode)myTree.getModel().getRoot(); } public void select() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); // can be null during ctr execution if (myTree != null) { myTree.requestFocusInWindow(); @@ -1241,7 +1242,7 @@ protected UsageView doReRun() { } private void reset() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myUsageNodes.clear(); myModel.reset(); synchronized (modelToSwingNodeChanges) { @@ -1416,7 +1417,7 @@ private Stream usagesToNodes(@NotNull Stream usages) @Override public void selectUsages(Usage @NotNull [] usages) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); TreePath[] paths = usagesToNodes(Arrays.stream(usages)) .map(node -> new TreePath(node.getPath())) .toArray(TreePath[]::new); @@ -1428,14 +1429,14 @@ public void selectUsages(Usage @NotNull [] usages) { @NotNull @Override public JComponent getPreferredFocusableComponent() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myTree != null ? myTree : getComponent(); } @Override @NotNull public JComponent getComponent() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myRootPanel == null ? new JLabel() : myRootPanel; } @@ -1456,7 +1457,7 @@ void setContent(@NotNull Content content) { } private void updateImmediately() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; TreeNode root = (TreeNode)myTree.getModel().getRoot(); List toUpdate = new ArrayList<>(); @@ -1483,7 +1484,7 @@ private void queueUpdateBulk(@NotNull List toUpdate, @NotNull Ru } private void updateImmediatelyNodesUpToRoot(@NotNull Collection nodes) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) return; TreeNode root = (TreeNode)myTree.getModel().getRoot(); Set queued = new HashSet<>(); @@ -1506,7 +1507,7 @@ private void updateImmediatelyNodesUpToRoot(@NotNull Collection private void updateOnSelectionChanged() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myCurrentUsageContextPanel != null) { try { myCurrentUsageContextPanel.updateLayout(ContainerUtil.notNullize(getSelectedUsageInfos()), this); @@ -1517,7 +1518,7 @@ private void updateOnSelectionChanged() { } private void checkNodeValidity(@NotNull TreeNode node, @NotNull TreePath path, @NotNull List result) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean shouldCheckChildren = true; if (myTree.isCollapsed(path)) { if (node instanceof Node) { @@ -1557,13 +1558,13 @@ public void close() { } private void saveSplitterProportions() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); getUsageViewSettings().setPreviewUsagesSplitterProportion(myPreviewSplitter.getProportion()); } @Override public void dispose() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); disposeUsageContextPanels(); isDisposed = true; myUpdateAlarm.cancelAllRequests(); @@ -1636,7 +1637,7 @@ public boolean isDisposed() { } private void showNode(@NotNull Node node) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (!isDisposed() && !myPresentation.isDetachedMode()) { fireEvents(); TreePath usagePath = new TreePath(node.getPath()); @@ -1652,7 +1653,7 @@ public void setRerunAction(@NotNull Action rerunAction) { @Override public void addButtonToLowerPane(@NotNull Action action) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); int index = myButtonPanel.getComponentCount(); if (!SystemInfo.isMac && index > 0 && myPresentation.isShowCancelButton()) index--; myButtonPanel.addButtonAction(index, action); @@ -1796,7 +1797,7 @@ public Set getExcludedUsages() { @Nullable private Node getSelectedNode() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); TreePath path = myTree.getLeadSelectionPath(); Object node = path == null ? null : path.getLastPathComponent(); return node instanceof Node ? (Node)node : null; @@ -1804,7 +1805,7 @@ private Node getSelectedNode() { @NotNull private List selectedNodes() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); TreePath[] selectionPaths = myTree.getSelectionPaths(); return selectionPaths == null ? Collections.emptyList() : ContainerUtil.mapNotNull(selectionPaths, p-> ObjectUtils.tryCast(p.getLastPathComponent(), TreeNode.class)); } @@ -1816,7 +1817,7 @@ private List selectedNodes() { @Override @NotNull public Set getSelectedUsages() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return new HashSet<>(allUsagesRecursive(selectedNodes())); } @@ -2114,7 +2115,7 @@ private UsageState(@NotNull Usage usage, boolean isSelected) { } private void restore() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); UsageNode node = myUsageNodes.get(myUsage); if (node == NULL_NODE || node == null) { return; @@ -2191,7 +2192,7 @@ else if (answer == Messages.CANCEL) { } private List getSelectedUsageInfos() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return USAGE_INFO_LIST_KEY.getData(DataManager.getInstance().getDataContext(myRootPanel)); } @@ -2224,7 +2225,7 @@ private boolean isFilterDuplicateLines() { } public Usage getNextToSelect(@NotNull Usage toDelete) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); UsageNode usageNode = myUsageNodes.get(toDelete); if (usageNode == null || usageNode.getParent().getChildCount() == 0) return null; @@ -2235,7 +2236,7 @@ public Usage getNextToSelect(@NotNull Usage toDelete) { } public Usage getNextToSelect(@NotNull Collection toDelete) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); Usage toSelect = null; for (Usage usage : toDelete) { Usage next = getNextToSelect(usage); diff --git a/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewTreeModelBuilder.java b/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewTreeModelBuilder.java index c11de6171071d..2a840e82ca729 100644 --- a/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewTreeModelBuilder.java +++ b/platform/usageView-impl/src/com/intellij/usages/impl/UsageViewTreeModelBuilder.java @@ -1,9 +1,9 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.usages.impl; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.usages.UsageTarget; import com.intellij.usages.UsageViewPresentation; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,7 +63,7 @@ private void addTargetNodes() { if (myTargetsNode == null || myTargets.length == 0) { return; } - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myTargetNodes = new UsageTargetNode[myTargets.length]; myTargetsNode.removeAllChildren(); for (int i = 0; i < myTargets.length; i++) { @@ -121,55 +121,55 @@ public Object getRoot() { @Override public void nodeChanged(TreeNode node) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.nodeChanged(node); } @Override public void nodesWereInserted(TreeNode node, int[] childIndices) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.nodesWereInserted(node, childIndices); } @Override public void nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.nodesWereRemoved(node, childIndices, removedChildren); } @Override public void nodesChanged(TreeNode node, int[] childIndices) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.nodesChanged(node, childIndices); } @Override public void nodeStructureChanged(TreeNode node) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.nodeStructureChanged(node); } @Override protected void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.fireTreeNodesChanged(source, path, childIndices, children); } @Override protected void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.fireTreeNodesInserted(source, path, childIndices, children); } @Override protected void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.fireTreeNodesRemoved(source, path, childIndices, children); } @Override protected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); super.fireTreeStructureChanged(source, path, childIndices, children); } } diff --git a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java index 5f4223b841697..0ed45e5c40b52 100644 --- a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java +++ b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java @@ -30,6 +30,7 @@ import com.intellij.usages.impl.rules.UsageType; import com.intellij.usages.rules.*; import com.intellij.util.*; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -432,7 +433,7 @@ public boolean merge(@NotNull MergeableUsage other) { @Override public void reset() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myMergedUsageInfos = myUsageInfo; resetCachedPresentation(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java index 1c451b11a272c..b8326c18f1984 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java @@ -5,7 +5,6 @@ import com.intellij.idea.ActionsBundle; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.TextAnnotationGutterProvider; @@ -29,6 +28,7 @@ import com.intellij.ui.ExperimentalUI; import com.intellij.ui.LightColors; import com.intellij.util.ObjectUtils; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; @@ -130,7 +130,7 @@ private static void doAnnotate(@NotNull final Editor editor, @NotNull final AbstractVcs vcs, @NotNull final UpToDateLineNumberProvider upToDateLineNumbers, final boolean warnAboutSuspiciousAnnotations) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (project.isDisposed() || editor.isDisposed()) return; if (warnAboutSuspiciousAnnotations) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java index 40abfc1e67c24..befd591f44e53 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java @@ -11,7 +11,6 @@ import com.intellij.ide.util.treeView.TreeState; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; @@ -33,6 +32,7 @@ import com.intellij.ui.tree.ui.DefaultTreeUI; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.Processor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.TreeTraversal; @@ -435,7 +435,7 @@ protected void updateTreeModel(@NotNull DefaultTreeModel model) { protected void updateTreeModel(@NotNull DefaultTreeModel model, @SuppressWarnings("rawtypes") @NotNull TreeStateStrategy treeStateStrategy) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myModelUpdateInProgress = true; try { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeImpl.java index 34d8b2aa7514f..d1c0713b30272 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeImpl.java @@ -1,11 +1,11 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.ui; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import javax.swing.tree.DefaultTreeModel; @@ -40,7 +40,7 @@ public ChangesTreeImpl(@NotNull Project project, } public void setChangesToDisplay(@NotNull Collection changes) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myProject.isDisposed()) return; myChanges.clear(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index 046f2eea32aae..512963b9296f3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -44,6 +44,7 @@ import com.intellij.ui.content.ContentManager; import com.intellij.util.ContentUtilEx; import com.intellij.util.Processor; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.text.DateFormatUtil; import com.intellij.vcs.ViewUpdateInfoNotification; @@ -685,13 +686,13 @@ boolean isBackgroundTaskRunning(Object @NotNull ... keys) { @RequiresEdt void startBackgroundTask(Object @NotNull ... keys) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LOG.assertTrue(myBackgroundRunningTasks.add(new ActionKey(keys))); } @RequiresEdt void stopBackgroundTask(Object @NotNull ... keys) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); LOG.assertTrue(myBackgroundRunningTasks.remove(new ActionKey(keys))); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java index d63731fc8050e..c4dcd48011939 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java @@ -12,7 +12,6 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.ActionToolbar; import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -36,6 +35,7 @@ import com.intellij.psi.PsiFile; import com.intellij.ui.*; import com.intellij.ui.components.JBLoadingPanel; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.components.BorderLayoutPanel; @@ -279,7 +279,7 @@ public void requestFocusInMessage() { @RequiresEdt public void setChangesSupplier(@NotNull Supplier> changesSupplier) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myEditorField.getDocument().putUserData(CHANGES_SUPPLIER_KEY, changesSupplier); } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.kt b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.kt index 2990ca6494c36..74df82d26445f 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.kt +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.kt @@ -6,7 +6,6 @@ import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.MoreExecutors import com.google.common.util.concurrent.SettableFuture import com.intellij.ide.DataManager -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.vcs.changes.ui.ChangesViewContentEP @@ -15,11 +14,11 @@ import com.intellij.openapi.vcs.changes.ui.ChangesViewContentProvider import com.intellij.ui.components.JBPanel import com.intellij.ui.content.Content import com.intellij.util.Consumer +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.vcs.log.VcsLogBundle import com.intellij.vcs.log.impl.VcsLogTabsManager.Companion.generateDisplayName import com.intellij.vcs.log.impl.VcsProjectLog.Companion.getLogProviders -import com.intellij.vcs.log.impl.VcsProjectLog.ProjectLogListener import com.intellij.vcs.log.ui.MainVcsLogUi import com.intellij.vcs.log.ui.VcsLogPanel import org.jetbrains.annotations.NonNls @@ -67,7 +66,7 @@ class VcsLogContentProvider(project: Project) : ChangesViewContentProvider { @RequiresEdt internal fun addMainUi(logManager: VcsLogManager) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (ui == null) { ui = logManager.createLogUi(MAIN_LOG_ID, VcsLogTabLocation.TOOL_WINDOW, false) val panel = VcsLogPanel(logManager, ui!!) @@ -92,7 +91,7 @@ class VcsLogContentProvider(project: Project) : ChangesViewContentProvider { @RequiresEdt internal fun disposeMainUi() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() container.removeAll() DataManager.removeDataProvider(container) @@ -114,7 +113,7 @@ class VcsLogContentProvider(project: Project) : ChangesViewContentProvider { */ @RequiresEdt fun executeOnMainUiCreated(consumer: Consumer) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val future = waitMainUiCreation() future.addListener({ try { @@ -130,7 +129,7 @@ class VcsLogContentProvider(project: Project) : ChangesViewContentProvider { @RequiresEdt fun waitMainUiCreation(): ListenableFuture { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (ui != null) { return Futures.immediateFuture(ui) } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java index c456fc29d39e8..8f7cc9287f5ac 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java @@ -14,6 +14,7 @@ import com.intellij.openapi.vcs.VcsRoot; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.PairConsumer; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.MultiMap; @@ -157,7 +158,7 @@ MainVcsLogUi createLogUi(@NotNull String logId, @NotNull VcsLogTabLocation locat private @NotNull U createLogUi(@NotNull VcsLogUiFactory factory, @NotNull VcsLogTabLocation location, boolean isClosedOnDispose) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isDisposed()) { LOG.error("Trying to create new VcsLogUi on a disposed VcsLogManager instance"); throw new ProcessCanceledException(); @@ -232,7 +233,7 @@ private static void refreshLogOnVcsEvents(@NotNull Map addContentManagerListener(window, object : VcsLogTabsListener(project, window, mainDisposable) { override fun selectionChanged(tabId: String) { diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsProjectLog.kt b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsProjectLog.kt index e9d06ef1638ed..0c93bf13949b6 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsProjectLog.kt +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsProjectLog.kt @@ -30,6 +30,7 @@ import com.intellij.openapi.vcs.VcsMappingListener import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.awaitCancellationAndInvoke import com.intellij.util.childScope +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.messages.Topic @@ -214,7 +215,7 @@ class VcsProjectLog(private val project: Project, private val coroutineScope: Co @RequiresEdt private fun dropLogManager(): VcsLogManager? { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val oldValue = cachedLogManager ?: return null cachedLogManager = null LOG.debug { "Disposing Vcs Log for ${VcsLogUtil.getProvidersMapText(oldValue.dataManager.logProviders)}" } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/AbstractVcsLogUi.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/AbstractVcsLogUi.java index 2da987391831f..e94bacf714424 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/AbstractVcsLogUi.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/AbstractVcsLogUi.java @@ -4,7 +4,6 @@ import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; @@ -14,6 +13,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vcs.VcsNotifier; import com.intellij.util.PairFunction; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import com.intellij.vcs.log.*; @@ -79,7 +79,7 @@ public AbstractVcsLogUi(@NotNull String id, } public void setVisiblePack(@NotNull VisiblePack pack) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); boolean permGraphChanged = myVisiblePack.getDataPack() != pack.getDataPack(); @@ -203,18 +203,18 @@ protected void handleCommitNotFound(@NotNull T commitId, @Override public void addLogListener(@NotNull VcsLogListener listener) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLogListeners.add(listener); } @Override public void removeLogListener(@NotNull VcsLogListener listener) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLogListeners.remove(listener); } protected void fireFilterChangeEvent(@NotNull VisiblePack visiblePack, boolean refresh) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); for (VcsLogListener listener : myLogListeners) { listener.onChange(visiblePack, refresh); @@ -231,7 +231,7 @@ protected void invokeOnChange(@NotNull Runnable runnable, @NotNull Condition nodes) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); List ordinaryWatches = ContainerUtil.filter(nodes, node -> !(node instanceof InlineWatchNode)); List inlineWatches = ContainerUtil.filter(nodes, node -> node instanceof InlineWatchNode); @@ -564,7 +565,7 @@ public void removeWatches(List nodes) { @Override public void removeAllWatches() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (inlineWatchesEnabled) { List children = ((InlineWatchesRootNode)myRootNode).getInlineWatchChildren(); if (!children.isEmpty()) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerTitleInfoProvider.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerTitleInfoProvider.kt index 6b001b4875073..b17d49355047a 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerTitleInfoProvider.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerTitleInfoProvider.kt @@ -10,7 +10,7 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.wm.impl.TitleInfoProvider import com.intellij.openapi.wm.impl.simpleTitleParts.RegistryOption import com.intellij.openapi.wm.impl.simpleTitleParts.SimpleTitleInfoProvider -import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.EDT import com.intellij.xdebugger.* import javax.swing.SwingUtilities @@ -66,7 +66,7 @@ private class DebuggerTitleInfoProvider : SimpleTitleInfoProvider(RegistryOption fun checkState(provider: DebuggerTitleInfoProvider) { fun action() { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() debuggerSessionStarted = XDebuggerManager.getInstance(project)?.let { provider.isEnabled() && it.debugSessions.isNotEmpty() } ?: false @@ -89,7 +89,7 @@ private class DebuggerTitleInfoProvider : SimpleTitleInfoProvider(RegistryOption project.messageBus.connect(disposable).subscribe(XDebuggerManager.TOPIC, object : XDebuggerManagerListener { override fun processStarted(debugProcess: XDebugProcess) { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() debuggerSessionStarted = true debugProcess.session.addSessionListener(object : XDebugSessionListener { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java index 6bd63cbe0de72..7d36014cc438a 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.Navigatable; import com.intellij.ui.AppUIUtil; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.messages.MessageBusConnection; import com.intellij.xdebugger.XDebuggerUtil; import com.intellij.xdebugger.XSourcePosition; @@ -151,7 +152,7 @@ public void updateGutterIcon(@Nullable final GutterIconRenderer renderer) { } private void doShow(boolean navigate) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (ApplicationManager.getApplication().isUnitTestMode()) return; removeHighlighter(); @@ -220,7 +221,7 @@ private void addHighlighter() { } public boolean isFullLineHighlighter() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); return myRangeHighlighter != null && myRangeHighlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE; } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessDialogFactory.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessDialogFactory.kt index 375029a7c2366..2e3ac1fbc05ed 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessDialogFactory.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessDialogFactory.kt @@ -4,7 +4,7 @@ package com.intellij.xdebugger.impl.ui.attach.dialog import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.actionSystem.DataKey import com.intellij.openapi.project.Project -import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.UIUtil import com.intellij.xdebugger.attach.XAttachDebuggerProvider import com.intellij.xdebugger.attach.XAttachHost @@ -26,7 +26,7 @@ class AttachToProcessDialogFactory(private val project: Project) { fun showDialog(attachDebuggerProviders: List, attachHosts: List>, context: DataContext) { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val defaultViewHostType = getDefaultViewHostType(context) val currentDialogInstance = getOpenDialog() diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessView.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessView.kt index a12e99c00f8cb..f8e679a79bc7f 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessView.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessView.kt @@ -17,6 +17,7 @@ import com.intellij.ui.components.ActionLink import com.intellij.ui.components.JBLoadingPanel import com.intellij.ui.components.JBScrollPane import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.JBUI import com.intellij.xdebugger.attach.XAttachDebuggerProvider import com.intellij.xdebugger.attach.XAttachHost @@ -72,7 +73,7 @@ abstract class AttachToProcessView( fun getMainComponent() = centerPanel fun updateProcesses() { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (state.dialogDisposable.isNotAlive) return showLoadingPanel() updateJob?.cancel() diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessViewWithHosts.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessViewWithHosts.kt index bb212234ef962..9435eb36db64f 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessViewWithHosts.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/attach/dialog/AttachToProcessViewWithHosts.kt @@ -8,7 +8,7 @@ import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.util.text.StringUtil import com.intellij.ui.components.ActionLink -import com.intellij.util.application +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.ui.JBUI import com.intellij.xdebugger.XDebuggerBundle import com.intellij.xdebugger.attach.XAttachDebuggerProvider @@ -146,7 +146,7 @@ abstract class AttachToProcessViewWithHosts( fun getSelectedItem(): AttachHostItem = selectedHost ?: throw IllegalStateException("At least one host should be selected") fun updateState(newHosts: List): Boolean { - application.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val newHostsAsSet = newHosts.toSet() val addedHosts = newHostsAsSet.filter { !hosts.contains(it) } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeState.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeState.java index 1d676e2016a5b..9153b7b7ce631 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeState.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeState.java @@ -1,27 +1,28 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.xdebugger.impl.ui.tree; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.intellij.xdebugger.XNamedTreeNode; import com.intellij.xdebugger.impl.ui.tree.nodes.RestorableStateNode; import com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode; -import java.awt.Rectangle; -import java.util.List; -import java.util.Objects; -import javax.swing.JViewport; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.util.List; +import java.util.Objects; + public final class XDebuggerTreeState { private final NodeInfo myRootInfo; private Rectangle myLastVisibleNodeRect; private XDebuggerTreeState(@NotNull XDebuggerTree tree) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); XDebuggerTreeNode root = tree.getRoot(); myRootInfo = root != null ? new NodeInfo("", "", tree.isPathSelected(root.getPath())) : null; if (root != null) { @@ -30,7 +31,7 @@ private XDebuggerTreeState(@NotNull XDebuggerTree tree) { } public XDebuggerTreeRestorer restoreState(@NotNull XDebuggerTree tree) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); XDebuggerTreeRestorer restorer = null; if (myRootInfo != null) { restorer = new XDebuggerTreeRestorer(tree, myLastVisibleNodeRect); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java index d180d543fbeae..07b3cfb8b00f2 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java @@ -1,7 +1,6 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.xdebugger.impl.ui.tree.nodes; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.Comparing; @@ -11,6 +10,7 @@ import com.intellij.ui.ColoredTextContainer; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ThreeState; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.XExpression; @@ -213,7 +213,7 @@ public static void buildText(@NotNull XValuePresentation valuePresenter, @NotNul public void markChanged() { if (myChanged) return; - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myChanged = true; if (myName != null && myValuePresentation != null) { updateText(); @@ -295,7 +295,7 @@ public boolean isComputed() { } public void setValueModificationStarted() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myRawValue = null; myText.clear(); appendName(); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/memory/ui/ClassesTable.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/memory/ui/ClassesTable.java index bb242696559f3..b89d9a4950f34 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/memory/ui/ClassesTable.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/memory/ui/ClassesTable.java @@ -16,6 +16,7 @@ import com.intellij.ui.scale.JBUIScale; import com.intellij.ui.speedSearch.SpeedSearchUtil; import com.intellij.ui.table.JBTable; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.FList; import com.intellij.util.ui.JBDimension; import com.intellij.util.ui.StatusText; @@ -263,7 +264,7 @@ void exitClickableMode() { } private void releaseMouseListener() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (isInClickableMode()) { removeMouseListener(myMouseListener); myMouseListener = null; diff --git a/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/threadingModelHelper/TMHIntegrationTest.java b/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/threadingModelHelper/TMHIntegrationTest.java index 89c4e0dd18501..bec78181d88df 100644 --- a/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/threadingModelHelper/TMHIntegrationTest.java +++ b/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/threadingModelHelper/TMHIntegrationTest.java @@ -2,12 +2,12 @@ package org.jetbrains.idea.devkit.threadingModelHelper; import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.DefaultLogger; import com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments; import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.*; import org.jetbrains.annotations.NotNull; @@ -56,7 +56,7 @@ public void testEdtActionInBackground() { } public void testBackgroundActionOnEdt() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); assertThrows(RuntimeException.class, ()->runBackgroundAction()); } diff --git a/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/threadingModelHelper/package-info.java b/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/threadingModelHelper/package-info.java index 610cfdc7476f3..3ce43c7c1e8a8 100644 --- a/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/threadingModelHelper/package-info.java +++ b/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/threadingModelHelper/package-info.java @@ -13,7 +13,7 @@ * * by inserting *
    - *
  • {@code Application.assertIsDispatchThread()} + *
  • {@code ThreadingAssertions.assertEventDispatchThread()} *
  • {@code Application.assertIsNonDispatchThread()} *
  • {@code Application.assertReadAccessAllowed()} *
  • {@code Application.assertWriteAccessAllowed()} diff --git a/plugins/git4idea/src/git4idea/branch/DeepComparator.kt b/plugins/git4idea/src/git4idea/branch/DeepComparator.kt index bbe17f441156c..ded1c56d978b5 100644 --- a/plugins/git4idea/src/git4idea/branch/DeepComparator.kt +++ b/plugins/git4idea/src/git4idea/branch/DeepComparator.kt @@ -2,7 +2,6 @@ package git4idea.branch import com.intellij.openapi.Disposable -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager @@ -21,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.platform.diagnostic.telemetry.TelemetryManager import com.intellij.platform.diagnostic.telemetry.helpers.computeWithSpan import com.intellij.ui.awt.RelativePoint +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.vcs.log.* import com.intellij.vcs.log.data.DataPack @@ -33,7 +33,6 @@ import com.intellij.vcs.log.util.VcsLogUtil import com.intellij.vcs.log.util.findBranch import com.intellij.vcs.log.util.subgraphDifference import com.intellij.vcs.log.visible.VisiblePack -import git4idea.GitBranch import git4idea.GitNotificationIdsHolder.Companion.COULD_NOT_COMPARE_WITH_BRANCH import git4idea.GitUtil import git4idea.commands.Git @@ -104,7 +103,7 @@ class DeepComparator(private val project: Project, @RequiresEdt fun startTask(dataPack: VcsLogDataPack, branchToCompare: String) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (comparedBranch != null) { LOG.error("Already comparing with branch $comparedBranch") return @@ -123,14 +122,14 @@ class DeepComparator(private val project: Project, @RequiresEdt fun stopTaskAndUnhighlight() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() stopTask() unhighlight() } @RequiresEdt fun hasHighlightingOrInProgress(): Boolean { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() return comparedBranch != null } diff --git a/plugins/git4idea/src/git4idea/index/GitStageLineStatusTracker.kt b/plugins/git4idea/src/git4idea/index/GitStageLineStatusTracker.kt index ab4ec764e5959..48b67a947da7c 100644 --- a/plugins/git4idea/src/git4idea/index/GitStageLineStatusTracker.kt +++ b/plugins/git4idea/src/git4idea/index/GitStageLineStatusTracker.kt @@ -45,6 +45,7 @@ import com.intellij.ui.components.JBLabel import com.intellij.ui.components.labels.LinkLabel import com.intellij.ui.paint.PaintUtil import com.intellij.ui.scale.JBUIScale +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.containers.PeekableIteratorWrapper import com.intellij.util.ui.JBUI @@ -101,7 +102,7 @@ class GitStageLineStatusTracker( @RequiresEdt fun setBaseRevision(vcsContent: CharSequence, newStagedDocument: Document) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isReleased) return if (stagedDocument != newStagedDocument) { @@ -124,7 +125,7 @@ class GitStageLineStatusTracker( @RequiresEdt fun dropBaseRevision() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isReleased) return isInitialized = false diff --git a/plugins/git4idea/src/git4idea/index/GitStageManager.kt b/plugins/git4idea/src/git4idea/index/GitStageManager.kt index a430d6d730699..747c0d172dd05 100644 --- a/plugins/git4idea/src/git4idea/index/GitStageManager.kt +++ b/plugins/git4idea/src/git4idea/index/GitStageManager.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.startup.ProjectActivity import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vcs.impl.LineStatusTrackerSettingListener +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.vcs.commit.CommitMode import com.intellij.vcs.commit.CommitModeManager import git4idea.GitVcs @@ -14,7 +15,7 @@ import git4idea.config.GitVcsApplicationSettings internal class CommitModeListener(val project: Project) : CommitModeManager.CommitModeListener { override fun commitModeChanged() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isStagingAreaAvailable(project)) { GitStageTracker.getInstance(project).updateTrackerState() diff --git a/plugins/ide-features-trainer/src/training/dsl/TaskContext.kt b/plugins/ide-features-trainer/src/training/dsl/TaskContext.kt index 5626abd86f736..34de46bba3917 100644 --- a/plugins/ide-features-trainer/src/training/dsl/TaskContext.kt +++ b/plugins/ide-features-trainer/src/training/dsl/TaskContext.kt @@ -1,10 +1,9 @@ -// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package training.dsl -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project +import com.intellij.util.concurrency.ThreadingAssertions import org.intellij.lang.annotations.Language -import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.Nls import training.learn.LearnBundle import training.statistic.LearningInternalProblems @@ -214,7 +213,7 @@ abstract class TaskContext : LearningDslBase { class DoneStepContext(private val future: CompletableFuture, rt: TaskRuntimeContext) : TaskRuntimeContext(rt) { fun completeStep() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (!future.isDone && !future.isCancelled) { future.complete(true) } diff --git a/plugins/ide-features-trainer/src/training/dsl/impl/LessonExecutor.kt b/plugins/ide-features-trainer/src/training/dsl/impl/LessonExecutor.kt index af46acce34e9a..5867cdb77a868 100644 --- a/plugins/ide-features-trainer/src/training/dsl/impl/LessonExecutor.kt +++ b/plugins/ide-features-trainer/src/training/dsl/impl/LessonExecutor.kt @@ -16,6 +16,7 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Ref import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.Alarm +import com.intellij.util.concurrency.ThreadingAssertions import org.intellij.lang.annotations.Language import training.dsl.* import training.learn.ActionsRecorder @@ -134,7 +135,7 @@ internal class LessonExecutor(val lesson: KLesson, } fun task(taskContent: TaskContext.() -> Unit) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val taskProperties = LessonExecutorUtil.taskProperties(taskContent, project) addTaskAction(taskProperties, taskContent) { @@ -149,7 +150,7 @@ internal class LessonExecutor(val lesson: KLesson, override fun dispose() { if (hasBeenStopped) return - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val lessonPassed = currentTaskIndex == taskActions.size val visualIndex = if(lessonPassed) currentVisualIndex else (taskActions[currentTaskIndex].taskVisualIndex ?: 0) lesson.onStop(project, lessonPassed, currentTaskIndex, visualIndex, internalProblems) @@ -216,7 +217,7 @@ internal class LessonExecutor(val lesson: KLesson, private fun processNextTask2() { LessonManager.instance.clearRestoreMessage() - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (currentTaskIndex == taskActions.size) { LessonManager.instance.passLesson(lesson) return @@ -251,7 +252,7 @@ internal class LessonExecutor(val lesson: KLesson, } private fun processTask(taskContent: TaskContext.() -> Unit) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val recorder = ActionsRecorder(project, selectedEditor?.document, this) currentRecorder = recorder val taskCallbackData = TaskData() @@ -404,7 +405,7 @@ internal class LessonExecutor(val lesson: KLesson, } private fun stepHasBeenCompleted(taskContext: TaskContextImpl, taskInfo: TaskInfo) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() // do not process the next task if the current task is not fully completed // or lesson has been stopped during task completion (dialogs in Recent Files and Restore removed code lessons) // or the next task already has been processed diff --git a/plugins/kotlin/base/analysis-api/analysis-api-utils/src/org/jetbrains/kotlin/idea/base/analysis/api/utils/analyzeUtils.kt b/plugins/kotlin/base/analysis-api/analysis-api-utils/src/org/jetbrains/kotlin/idea/base/analysis/api/utils/analyzeUtils.kt index 2d4e44878db7f..b47c8396a2fe2 100644 --- a/plugins/kotlin/base/analysis-api/analysis-api-utils/src/org/jetbrains/kotlin/idea/base/analysis/api/utils/analyzeUtils.kt +++ b/plugins/kotlin/base/analysis-api/analysis-api-utils/src/org/jetbrains/kotlin/idea/base/analysis/api/utils/analyzeUtils.kt @@ -1,11 +1,11 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.base.analysis.api.utils -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runReadAction import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.Task import com.intellij.openapi.util.NlsContexts.DialogTitle +import com.intellij.util.concurrency.ThreadingAssertions import org.jetbrains.kotlin.analysis.api.KtAnalysisSession import org.jetbrains.kotlin.analysis.api.analyze import org.jetbrains.kotlin.psi.KtElement @@ -22,7 +22,7 @@ inline fun analyzeInModalWindow( @DialogTitle windowTitle: String, crossinline action: KtAnalysisSession.() -> R ): R { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val task = object : Task.WithResult(contextElement.project, windowTitle, /*canBeCancelled*/ true) { override fun compute(indicator: ProgressIndicator): R = runReadAction { analyze(contextElement, action) } diff --git a/plugins/kotlin/completion/impl-k1/src/org/jetbrains/kotlin/idea/completion/LookupCancelService.kt b/plugins/kotlin/completion/impl-k1/src/org/jetbrains/kotlin/idea/completion/LookupCancelService.kt index 4f3d00db0b63a..448d7ecadcb88 100644 --- a/plugins/kotlin/completion/impl-k1/src/org/jetbrains/kotlin/idea/completion/LookupCancelService.kt +++ b/plugins/kotlin/completion/impl-k1/src/org/jetbrains/kotlin/idea/completion/LookupCancelService.kt @@ -4,7 +4,6 @@ package org.jetbrains.kotlin.idea.completion import com.intellij.codeInsight.lookup.LookupEvent import com.intellij.codeInsight.lookup.LookupListener -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.service import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.RangeMarker @@ -12,7 +11,7 @@ import com.intellij.openapi.editor.event.CaretEvent import com.intellij.openapi.editor.event.CaretListener import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key -import org.jetbrains.kotlin.psi.KtTypeArgumentList +import com.intellij.util.concurrency.ThreadingAssertions class LookupCancelService { internal class Reminiscence(editor: Editor, offset: Int) { @@ -29,7 +28,7 @@ class LookupCancelService { } init { - ApplicationManager.getApplication()!!.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() editor.caretModel.addCaretListener(editorListener!!) } @@ -38,7 +37,7 @@ class LookupCancelService { } fun dispose() { - ApplicationManager.getApplication()!!.assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (marker != null) { editor!!.caretModel.removeCaretListener(editorListener!!) marker = null diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt index 5c2aea328a372..5163ba81d7772 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.search.usagesSearch @@ -12,6 +12,7 @@ import com.intellij.openapi.util.Computable import com.intellij.openapi.util.NlsContexts import com.intellij.psi.* import com.intellij.psi.util.MethodSignatureUtil +import com.intellij.util.concurrency.ThreadingAssertions import org.jetbrains.kotlin.analyzer.LanguageSettingsProvider import org.jetbrains.kotlin.asJava.classes.lazyPub import org.jetbrains.kotlin.asJava.toLightClass @@ -53,7 +54,7 @@ inline fun calculateInModalWindow( @NlsContexts.DialogTitle windowTitle: String, crossinline action: () -> R ): R { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val task = object : Task.WithResult(contextElement.project, windowTitle, /*canBeCancelled*/ true) { override fun compute(indicator: ProgressIndicator): R = ApplicationManager.getApplication().runReadAction(Computable { action() }) diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/LongRunningReadTask.java b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/LongRunningReadTask.java index 627330f4bf4a6..89fd8f7af1d72 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/LongRunningReadTask.java +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/LongRunningReadTask.java @@ -11,6 +11,7 @@ import com.intellij.openapi.progress.util.ProgressIndicatorBase; import com.intellij.openapi.progress.util.ProgressIndicatorUtils; import com.intellij.openapi.util.Disposer; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,7 +35,7 @@ protected LongRunningReadTask(Disposable disposable) { /** Should be executed in GUI thread */ public boolean shouldStart(@Nullable LongRunningReadTask previousTask) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (currentState != State.INITIALIZED) { throw new IllegalStateException("Task should be initialized state. Call init() method."); @@ -72,7 +73,7 @@ else if (previousTask.currentState == State.FINISHED_WITH_ACTUAL_DATA) { /** Should be executed in GUI thread */ public final void run() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (currentState != State.INITIALIZED) { throw new IllegalStateException("Task should be initialized with init() method"); @@ -111,7 +112,7 @@ public final void run() { * @return true if new request was successfully created, false if request is invalid and shouldn't be started */ public final boolean init() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); requestInfo = prepareRequestInfo(); currentState = State.INITIALIZED; @@ -120,7 +121,7 @@ public final boolean init() { } private void resultReady(ResultData resultData) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); currentState = State.FINISHED; diff --git a/plugins/kotlin/plugin-updater/src/org/jetbrains/kotlin/idea/KotlinPluginUpdater.kt b/plugins/kotlin/plugin-updater/src/org/jetbrains/kotlin/idea/KotlinPluginUpdater.kt index 9ce79fdf00dc6..481bb1838ef41 100644 --- a/plugins/kotlin/plugin-updater/src/org/jetbrains/kotlin/idea/KotlinPluginUpdater.kt +++ b/plugins/kotlin/plugin-updater/src/org/jetbrains/kotlin/idea/KotlinPluginUpdater.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea @@ -11,6 +11,7 @@ import com.intellij.openapi.application.* import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.extensions.PluginId +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.io.HttpRequests import org.jetbrains.kotlin.idea.compiler.configuration.KotlinIdePlugin import org.jetbrains.kotlin.idea.update.verify @@ -43,7 +44,7 @@ class KotlinPluginUpdater : StandalonePluginUpdateChecker( } fun runCachedUpdate(callback: (PluginUpdateStatus) -> Boolean) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val cachedStatus = lastUpdateStatus if (cachedStatus != null && System.currentTimeMillis() - cachedStatus.timestamp < CACHED_REQUEST_DELAY) { if (cachedStatus !is PluginUpdateStatus.CheckFailed) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/importing/MavenImportingManager.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/importing/MavenImportingManager.kt index 3ab0f21ddd2f8..4c5c5f7bc176e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/importing/MavenImportingManager.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/importing/MavenImportingManager.kt @@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.util.concurrency.AppExecutorUtil +import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.messages.MessageBusConnection import com.intellij.util.messages.Topic @@ -83,7 +84,7 @@ class MavenImportingManager(val project: Project) { @RequiresEdt fun linkAndImportFile(pom: VirtualFile): MavenImportingResult { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val manager = MavenProjectsManager.getInstance(project) val importPath = if (pom.isDirectory) RootPath(pom) else FilesList(pom) return openProjectAndImport(importPath, manager.importingSettings, manager.generalSettings, MavenImportSpec.EXPLICIT_IMPORT) @@ -118,7 +119,7 @@ class MavenImportingManager(val project: Project) { importingSettings: MavenImportingSettings, generalSettings: MavenGeneralSettings, spec: MavenImportSpec): MavenImportingResult { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (isImportingInProgress()) { return MavenImportingResult(waitingPromise, null, null) } @@ -268,7 +269,7 @@ class MavenImportingManager(val project: Project) { if (isRecursiveImportCalledFromMavenProjectsManagerWatcher()) { return MavenImportingResult(getWaitingPromise(), null, null) } - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val manager = MavenProjectsManager.getInstance(project) if (isImportingInProgress()) { return MavenImportingResult(getWaitingPromise(), null, null) @@ -286,7 +287,7 @@ class MavenImportingManager(val project: Project) { return MavenImportingResult(getWaitingPromise(), null, null) } - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() val manager = MavenProjectsManager.getInstance(project) val settings = MavenWorkspaceSettingsComponent.getInstance(project) manager.projectsTree.removeManagedFiles(filesToDelete) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenArchetypesStep.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenArchetypesStep.java index 36db205c8a5f8..c1d2119de713e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenArchetypesStep.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenArchetypesStep.java @@ -12,6 +12,7 @@ import com.intellij.ui.*; import com.intellij.ui.render.RenderingUtil; import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.AsyncProcessIcon; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; @@ -216,7 +217,7 @@ public void requestUpdate() { } public void updateArchetypesList(final MavenArchetype selected) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myLoadingIcon.setBackground(RenderingUtil.getBackground(myArchetypesTree)); diff --git a/plugins/stats-collector/src/com/intellij/stats/completion/tracker/CompletionLoggerInitializer.kt b/plugins/stats-collector/src/com/intellij/stats/completion/tracker/CompletionLoggerInitializer.kt index 9153289dbb229..7580425e78db1 100644 --- a/plugins/stats-collector/src/com/intellij/stats/completion/tracker/CompletionLoggerInitializer.kt +++ b/plugins/stats-collector/src/com/intellij/stats/completion/tracker/CompletionLoggerInitializer.kt @@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project import com.intellij.stats.completion.CompletionStatsPolicy import com.intellij.stats.completion.sender.isCompletionLogsSendAllowed import com.intellij.util.PlatformUtils +import com.intellij.util.concurrency.ThreadingAssertions import kotlin.random.Random class CompletionLoggerInitializer : LookupTracker() { @@ -56,13 +57,13 @@ class CompletionLoggerInitializer : LookupTracker() { private val actionListener: LookupActionsListener by lazy { LookupActionsListener.getInstance() } override fun lookupClosed() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() actionListener.listener = CompletionPopupListener.DISABLED } override fun lookupCreated(lookup: LookupImpl, storage: MutableLookupStorage) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (!shouldInitialize()) return val experimentInfo = ExperimentStatus.getInstance().forLanguage(storage.language) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryTreeNode.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryTreeNode.java index c21578b722240..e3c5c8ad668a3 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryTreeNode.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryTreeNode.java @@ -3,9 +3,9 @@ import com.intellij.CommonBundle; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.NlsContexts; import com.intellij.util.NotNullFunction; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -109,7 +109,7 @@ public String toString() { } public void reload(@NotNull Expander expander, boolean removeCurrentChildren) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (removeCurrentChildren || NodeLoadState.EMPTY.equals(myChildrenLoadState)) { initChildren(); @@ -125,7 +125,7 @@ private void initChildren() { } private List getChildren() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (NodeLoadState.EMPTY.equals(myChildrenLoadState)) { initChildren(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/browserCache/RepositoryLoader.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/browserCache/RepositoryLoader.java index a7382da591e13..a2eec12557e50 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/browserCache/RepositoryLoader.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/browserCache/RepositoryLoader.java @@ -1,13 +1,13 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.svn.dialogs.browserCache; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vcs.VcsException; +import com.intellij.util.concurrency.ThreadingAssertions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.SvnVcs; @@ -39,7 +39,7 @@ class RepositoryLoader extends Loader { @Override public void load(@NotNull RepositoryTreeNode node, @NotNull Expander afterRefreshExpander) { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final Pair data = Pair.create(node, afterRefreshExpander); if (! myQueueProcessorActive) { @@ -61,7 +61,7 @@ private void setError(@NotNull Pair data, @NotNull } private void startNext() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); final Pair data = myLoadQueue.poll(); if (data == null) { diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java index 047b09ff9176b..1de588fd01a55 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java @@ -10,6 +10,7 @@ import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache; import com.intellij.openapi.vcs.changes.committed.CommittedChangesListener; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; @@ -145,7 +146,7 @@ private BunchIterator(final Bunch bunch) { } private void checkValidity() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myCreationTime <= getRefreshTime()) { throw new SwitchRevisionsProviderException(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java index 4161507d82331..145e7b55461b4 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java @@ -2,7 +2,6 @@ package org.jetbrains.idea.svn.treeConflict; import com.intellij.ide.IdeCoreBundle; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diff.impl.patch.FilePatch; import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder; @@ -28,6 +27,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; @@ -418,7 +418,7 @@ private static void preloadRevisionContents(@Nullable ContentRevision revision) @RequiresEdt private void initAddOption() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myAdd == null) { myAdd = getAddedFilesPlaceOption(); } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java index 765eb5f74eb00..ce0f13165de6b 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java @@ -1,9 +1,8 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.idea.svn.treeConflict; import com.intellij.openapi.CompositeDisposable; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.*; import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator; @@ -20,6 +19,7 @@ import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLoadingPanel; import com.intellij.util.BeforeAfter; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresEdt; import com.intellij.util.ui.JBUI; @@ -171,7 +171,7 @@ private ConflictSidePresentation createSide(@Nullable ConflictVersion version, @ @RequiresEdt public void refresh() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myDetailsPanel.startLoading(); Loader task = new Loader(myVcs.getProject()); diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/TerminalEventDispatcher.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/TerminalEventDispatcher.kt index 41209118745f8..8d958a066d5d1 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/TerminalEventDispatcher.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/TerminalEventDispatcher.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.actionSystem.KeyboardShortcut -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.invokeLater import com.intellij.openapi.editor.Editor @@ -22,6 +21,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.registry.Registry import com.intellij.terminal.JBTerminalSystemSettingsProviderBase +import com.intellij.util.concurrency.ThreadingAssertions import com.jediterm.terminal.emulator.mouse.MouseMode import org.jetbrains.annotations.NonNls import org.jetbrains.plugins.terminal.exp.TerminalSelectionModel.TerminalSelectionListener @@ -56,7 +56,7 @@ internal abstract class TerminalEventDispatcher(private val parentDisposable: Di protected abstract fun handleKeyEvent(e: KeyEvent) fun register(actionsToSkip: List) { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() this.actionsToSkip = actionsToSkip if (!myRegistered) { IdeEventQueue.getInstance().addDispatcher(this, parentDisposable) @@ -65,7 +65,7 @@ internal abstract class TerminalEventDispatcher(private val parentDisposable: Di } fun unregister() { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() if (myRegistered) { IdeEventQueue.getInstance().removeDispatcher(this) actionsToSkip = emptyList() diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java b/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java index 864ded59a3f1b..d486fdf8fed1a 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java @@ -1,11 +1,11 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.uiDesigner; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.uiDesigner.componentTree.ComponentPtr; import com.intellij.uiDesigner.componentTree.ComponentSelectionListener; import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.radComponents.RadComponent; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; @@ -25,7 +25,7 @@ public SelectionState(@NotNull final GuiEditor editor) { } public void setInsideChange(final boolean insideChange){ - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); myInsideChange = insideChange; } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java index 1615e4a982016..ef81859ef3633 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java @@ -60,6 +60,7 @@ import com.intellij.uiDesigner.radComponents.RadRootContainer; import com.intellij.uiDesigner.radComponents.RadTabbedPane; import com.intellij.util.Alarm; +import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -377,7 +378,7 @@ public SelectionState getSelectionState() { @Override public void dispose() { - ApplicationManager.getApplication().assertIsDispatchThread(); + ThreadingAssertions.assertEventDispatchThread(); if (myWhere != null) { LOG.error("Already disposed: old trace: ", myWhere); diff --git a/python/src/com/jetbrains/python/configuration/PythonSdkConfiguration.kt b/python/src/com/jetbrains/python/configuration/PythonSdkConfiguration.kt index 662d867d710c5..b2d4820ad6f69 100644 --- a/python/src/com/jetbrains/python/configuration/PythonSdkConfiguration.kt +++ b/python/src/com/jetbrains/python/configuration/PythonSdkConfiguration.kt @@ -1,10 +1,10 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.jetbrains.python.configuration -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project import com.intellij.openapi.projectRoots.SdkModificator +import com.intellij.util.concurrency.ThreadingAssertions import com.jetbrains.python.sdk.PythonSdkAdditionalData import com.jetbrains.python.sdk.flavors.PythonSdkFlavor @@ -25,7 +25,7 @@ internal fun SdkModificator.resetAssociatedModulePath() { } private fun SdkModificator.getOrCreateSdkAdditionalData(): PythonSdkAdditionalData { - ApplicationManager.getApplication().assertIsDispatchThread() + ThreadingAssertions.assertEventDispatchThread() var additionalData = sdkAdditionalData as? PythonSdkAdditionalData if (additionalData == null) { additionalData = PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(homePath))