mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
GitOrigin-RevId: f6ad42c71714098a6ff9117f443e75f69f45d64d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1751d860da
commit
f4e1e7ff86
+42
-33
@@ -1,4 +1,4 @@
|
||||
// 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-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.openapi.application.impl
|
||||
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
@@ -35,16 +35,15 @@ internal class AppUIExecutorImpl private constructor(private val modality: Modal
|
||||
: AppUIExecutor,
|
||||
BaseExpirableExecutorMixinImpl<AppUIExecutorImpl>(constraints, cancellationConditions, expirableHandles,
|
||||
getExecutorForThread(thread, modality)) {
|
||||
|
||||
constructor(modality: ModalityState, thread: ExecutionThread) : this(modality, thread, emptyArray(), emptyArray(), emptySet())
|
||||
|
||||
companion object {
|
||||
private fun getExecutorForThread(thread: ExecutionThread,
|
||||
modality: ModalityState) =
|
||||
when (thread) {
|
||||
private fun getExecutorForThread(thread: ExecutionThread, modality: ModalityState): Executor {
|
||||
return when (thread) {
|
||||
ExecutionThread.EDT -> MyEdtExecutor(modality)
|
||||
ExecutionThread.WT -> MyWtExecutor(modality)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MyWtExecutor(private val modality: ModalityState) : Executor {
|
||||
@@ -60,8 +59,8 @@ internal class AppUIExecutorImpl private constructor(private val modality: Modal
|
||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(command, modality)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class MyEdtExecutor(private val modality: ModalityState) : Executor {
|
||||
override fun execute(command: Runnable) {
|
||||
if (ApplicationManager.getApplication().isDispatchThread
|
||||
@@ -78,14 +77,16 @@ internal class AppUIExecutorImpl private constructor(private val modality: Modal
|
||||
|
||||
override fun cloneWith(constraints: Array<ContextConstraint>,
|
||||
cancellationConditions: Array<BooleanSupplier>,
|
||||
expirationSet: Set<Expiration>): AppUIExecutorImpl =
|
||||
AppUIExecutorImpl(modality, thread, constraints, cancellationConditions, expirationSet)
|
||||
expirationSet: Set<Expiration>): AppUIExecutorImpl {
|
||||
return AppUIExecutorImpl(modality, thread, constraints, cancellationConditions, expirationSet)
|
||||
}
|
||||
|
||||
override fun dispatchLaterUnconstrained(runnable: Runnable) =
|
||||
when (thread) {
|
||||
override fun dispatchLaterUnconstrained(runnable: Runnable) {
|
||||
return when (thread) {
|
||||
ExecutionThread.EDT -> ApplicationManager.getApplication().invokeLater(runnable, modality)
|
||||
ExecutionThread.WT -> ApplicationManager.getApplication().invokeLaterOnWriteThread(runnable, modality)
|
||||
}
|
||||
}
|
||||
|
||||
override fun later(): AppUIExecutorImpl {
|
||||
val edtEventCount = if (ApplicationManager.getApplication().isDispatchThread) IdeEventQueue.getInstance().eventCount else -1
|
||||
@@ -93,20 +94,21 @@ internal class AppUIExecutorImpl private constructor(private val modality: Modal
|
||||
@Volatile
|
||||
var usedOnce: Boolean = false
|
||||
|
||||
override fun isCorrectContext(): Boolean =
|
||||
when (thread) {
|
||||
override fun isCorrectContext(): Boolean {
|
||||
return when (thread) {
|
||||
ExecutionThread.EDT -> when (edtEventCount) {
|
||||
-1 -> ApplicationManager.getApplication().isDispatchThread
|
||||
else -> usedOnce || edtEventCount != IdeEventQueue.getInstance().eventCount
|
||||
}
|
||||
ExecutionThread.WT -> usedOnce
|
||||
}
|
||||
}
|
||||
|
||||
override fun schedule(runnable: Runnable) {
|
||||
dispatchLaterUnconstrained(Runnable {
|
||||
usedOnce = true
|
||||
runnable.run()
|
||||
})
|
||||
usedOnce = true
|
||||
runnable.run()
|
||||
})
|
||||
}
|
||||
|
||||
override fun toString() = "later"
|
||||
@@ -120,8 +122,9 @@ internal class AppUIExecutorImpl private constructor(private val modality: Modal
|
||||
override fun inTransaction(parentDisposable: Disposable): AppUIExecutorImpl {
|
||||
val id = TransactionGuard.getInstance().contextTransaction
|
||||
return withConstraint(object : ContextConstraint {
|
||||
override fun isCorrectContext(): Boolean =
|
||||
TransactionGuard.getInstance().contextTransaction != null
|
||||
override fun isCorrectContext(): Boolean {
|
||||
return TransactionGuard.getInstance().contextTransaction != null
|
||||
}
|
||||
|
||||
override fun schedule(runnable: Runnable) {
|
||||
// The Application instance is passed as a disposable here to ensure the runnable is always invoked,
|
||||
@@ -163,34 +166,39 @@ internal class AppUIExecutorImpl private constructor(private val modality: Modal
|
||||
override fun toString() = "inWriteAction"
|
||||
})
|
||||
}
|
||||
|
||||
override fun inSmartMode(project: Project): AppUIExecutorImpl {
|
||||
return withConstraint(InSmartMode(project), project)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Deprecated("Beware, context might be infectious, if coroutine resumes other waiting coroutines. " +
|
||||
"Use runUndoTransparentWriteAction instead.", ReplaceWith("this"))
|
||||
fun AppUIExecutor.inUndoTransparentAction(): AppUIExecutor =
|
||||
(this as AppUIExecutorImpl).inUndoTransparentAction()
|
||||
fun AppUIExecutor.inUndoTransparentAction(): AppUIExecutor {
|
||||
return (this as AppUIExecutorImpl).inUndoTransparentAction()
|
||||
}
|
||||
|
||||
@Deprecated("Beware, context might be infectious, if coroutine resumes other waiting coroutines. " +
|
||||
"Use runWriteAction instead.", ReplaceWith("this"))
|
||||
fun AppUIExecutor.inWriteAction():AppUIExecutor =
|
||||
(this as AppUIExecutorImpl).inWriteAction()
|
||||
fun AppUIExecutor.inWriteAction():AppUIExecutor {
|
||||
return (this as AppUIExecutorImpl).inWriteAction()
|
||||
}
|
||||
|
||||
fun AppUIExecutor.withConstraint(constraint: ContextConstraint): AppUIExecutor =
|
||||
(this as AppUIExecutorImpl).withConstraint(constraint)
|
||||
fun AppUIExecutor.withConstraint(constraint: ContextConstraint, parentDisposable: Disposable): AppUIExecutor =
|
||||
(this as AppUIExecutorImpl).withConstraint(constraint, parentDisposable)
|
||||
fun AppUIExecutor.withConstraint(constraint: ContextConstraint): AppUIExecutor {
|
||||
return (this as AppUIExecutorImpl).withConstraint(constraint)
|
||||
}
|
||||
|
||||
fun AppUIExecutor.withConstraint(constraint: ContextConstraint, parentDisposable: Disposable): AppUIExecutor {
|
||||
return (this as AppUIExecutorImpl).withConstraint(constraint, parentDisposable)
|
||||
}
|
||||
|
||||
/**
|
||||
* A [context][CoroutineContext] to be used with the standard [launch], [async], [withContext] coroutine builders.
|
||||
* Contains: [ContinuationInterceptor].
|
||||
*/
|
||||
fun AppUIExecutor.coroutineDispatchingContext(): ContinuationInterceptor =
|
||||
(this as AppUIExecutorImpl).asCoroutineDispatcher()
|
||||
|
||||
fun AppUIExecutor.coroutineDispatchingContext(): ContinuationInterceptor {
|
||||
return (this as AppUIExecutorImpl).asCoroutineDispatcher()
|
||||
}
|
||||
|
||||
internal class WithDocumentsCommitted(private val project: Project, private val modality: ModalityState) : ContextConstraint {
|
||||
override fun isCorrectContext(): Boolean {
|
||||
@@ -204,12 +212,14 @@ internal class WithDocumentsCommitted(private val project: Project, private val
|
||||
|
||||
override fun toString(): String {
|
||||
val isCorrectContext = isCorrectContext()
|
||||
val details = if (!isCorrectContext) {
|
||||
val details = if (isCorrectContext) {
|
||||
""
|
||||
}
|
||||
else {
|
||||
val manager = PsiDocumentManager.getInstance(project) as PsiDocumentManagerBase
|
||||
", isCommitInProgress()=${manager.isCommitInProgress}" +
|
||||
", hasEventSystemEnabledUncommittedDocuments()=${manager.hasEventSystemEnabledUncommittedDocuments()}"
|
||||
}
|
||||
else ""
|
||||
return "withDocumentsCommitted {isCorrectContext()=$isCorrectContext$details}"
|
||||
}
|
||||
}
|
||||
@@ -221,8 +231,7 @@ internal class InSmartMode(private val project: Project) : ContextConstraint {
|
||||
}
|
||||
}
|
||||
|
||||
override fun isCorrectContext(): Boolean =
|
||||
!DumbService.getInstance(project).isDumb
|
||||
override fun isCorrectContext() = !DumbService.getInstance(project).isDumb
|
||||
|
||||
override fun schedule(runnable: Runnable) {
|
||||
DumbService.getInstance(project).runWhenSmart(runnable)
|
||||
|
||||
Reference in New Issue
Block a user