mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
getCurrentMergeableTransaction->getContextTransaction
This commit is contained in:
+1
-1
@@ -275,7 +275,7 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
|
||||
|
||||
protected void restartAnalysis(final Project project, final AnalysisScope scope) {
|
||||
TransactionGuard guard = TransactionGuard.getInstance();
|
||||
TransactionId id = guard.getCurrentMergeableTransaction();
|
||||
TransactionId id = guard.getContextTransaction();
|
||||
DumbService.getInstance(project).smartInvokeLater(
|
||||
() -> TransactionGuard.getInstance().submitMergeableTransaction(project, id, () -> {
|
||||
if (DumbService.isDumb(project)) {
|
||||
|
||||
@@ -174,7 +174,7 @@ public abstract class TransactionGuard {
|
||||
* and so it won't be run after it has been disposed.
|
||||
* @param mergeInto an optional id of another transaction, to allow execution inside that transaction if it's still running
|
||||
* @param transaction code to execute inside a transaction.
|
||||
* @see #getCurrentMergeableTransaction()
|
||||
* @see #getContextTransaction()
|
||||
*/
|
||||
public abstract void submitMergeableTransaction(@NotNull Disposable parentDisposable, @Nullable TransactionId mergeInto, @NotNull Runnable transaction);
|
||||
|
||||
@@ -203,5 +203,5 @@ public abstract class TransactionGuard {
|
||||
* @return the id of the currently running transaction for using in {@link #submitMergeableTransaction(Disposable, TransactionId, Runnable)},
|
||||
* or null if there's no transaction running or merging is not allowed in the callee context (e.g. from invokeLater).
|
||||
*/
|
||||
public abstract TransactionId getCurrentMergeableTransaction();
|
||||
public abstract TransactionId getContextTransaction();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.intellij.openapi.application;
|
||||
import com.intellij.openapi.Disposable;
|
||||
|
||||
/**
|
||||
* A unique object identifying each running transaction. Can be retrieved from {@link TransactionGuard#getCurrentMergeableTransaction()}
|
||||
* A unique object identifying each running transaction. Can be retrieved from {@link TransactionGuard#getContextTransaction()}
|
||||
* while inside a transaction, and used to merge other transactions into it via
|
||||
* {@link TransactionGuard#submitMergeableTransaction(Disposable, TransactionId, Runnable)}.
|
||||
*
|
||||
|
||||
@@ -121,7 +121,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
|
||||
@Override
|
||||
public void submitMergeableTransaction(@NotNull final Disposable parentDisposable, @NotNull final TransactionKind kind, @NotNull final Runnable _transaction) {
|
||||
submitMergeableTransaction(parentDisposable, kind, getCurrentMergeableTransaction(), _transaction);
|
||||
submitMergeableTransaction(parentDisposable, kind, getContextTransaction(), _transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,7 +204,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
public void submitTransactionAndWait(@NotNull final Runnable runnable) throws ProcessCanceledException {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (app.isDispatchThread()) {
|
||||
Transaction transaction = new Transaction(runnable, getCurrentMergeableTransaction(), TransactionKind.ANY_CHANGE, app);
|
||||
Transaction transaction = new Transaction(runnable, getContextTransaction(), TransactionKind.ANY_CHANGE, app);
|
||||
if (!canRunTransactionNow(transaction, true)) {
|
||||
throw new AssertionError("Cannot run synchronous submitTransactionAndWait from invokeLater. " +
|
||||
"Please use asynchronous submit*Transaction. " +
|
||||
@@ -285,7 +285,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
|
||||
@Override
|
||||
public void submitTransactionLater(@NotNull final Disposable parentDisposable, @NotNull final Runnable transaction) {
|
||||
final TransactionIdImpl id = getCurrentMergeableTransaction();
|
||||
final TransactionIdImpl id = getContextTransaction();
|
||||
Application app = ApplicationManager.getApplication();
|
||||
app.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@@ -296,7 +296,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionIdImpl getCurrentMergeableTransaction() {
|
||||
public TransactionIdImpl getContextTransaction() {
|
||||
if (!ApplicationManager.getApplication().isDispatchThread()) {
|
||||
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
|
||||
return indicator != null ? myProgresses.get(indicator) : null;
|
||||
|
||||
@@ -222,7 +222,7 @@ public class AutoPopupController implements Disposable {
|
||||
}
|
||||
public static void runTransactionWithEverythingCommitted(@NotNull final Project project, @NotNull final Runnable runnable) {
|
||||
TransactionGuard guard = TransactionGuard.getInstance();
|
||||
TransactionId id = guard.getCurrentMergeableTransaction();
|
||||
TransactionId id = guard.getContextTransaction();
|
||||
ModalityState modalityState = ModalityState.current();
|
||||
final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
|
||||
pdm.performWhenAllCommitted(() -> {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class ProgressWindow extends ProgressIndicatorBase implements BlockingPro
|
||||
myCancelText = cancelText;
|
||||
setModalityProgress(shouldShowBackground ? null : this);
|
||||
TransactionGuardImpl guard = (TransactionGuardImpl)TransactionGuard.getInstance();
|
||||
guard.registerProgress(this, guard.getCurrentMergeableTransaction());
|
||||
guard.registerProgress(this, guard.getContextTransaction());
|
||||
|
||||
myFocusTrackback = new FocusTrackback(this, WindowManager.getInstance().suggestParentWindow(project), false);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
public void "test no current id inside invokeLater"() {
|
||||
SwingUtilities.invokeLater {
|
||||
log << '2'
|
||||
assert !guard.currentMergeableTransaction
|
||||
assert !guard.contextTransaction
|
||||
}
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
log << '1'
|
||||
@@ -86,12 +86,12 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
public void "test has id inside nested transaction"() {
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
log << '1'
|
||||
def id = guard.currentMergeableTransaction
|
||||
def id = guard.contextTransaction
|
||||
assert id
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
log << '2'
|
||||
assert guard.currentMergeableTransaction
|
||||
assert id != guard.currentMergeableTransaction
|
||||
assert guard.contextTransaction
|
||||
assert id != guard.contextTransaction
|
||||
}
|
||||
assert log == ['1', '2']
|
||||
}
|
||||
@@ -101,11 +101,11 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
public void "test modal progress started from inside a transaction has the same id"() {
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
log << '1'
|
||||
def id = guard.currentMergeableTransaction
|
||||
def id = guard.contextTransaction
|
||||
assert id
|
||||
ProgressManager.instance.runProcessWithProgressSynchronously({
|
||||
assert !ApplicationManager.application.dispatchThread
|
||||
assert id == guard.currentMergeableTransaction
|
||||
assert id == guard.contextTransaction
|
||||
log << '2'
|
||||
}, 'title', true, project)
|
||||
}
|
||||
@@ -116,7 +116,7 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
log << '1'
|
||||
ApplicationManager.application.executeOnPooledThread({
|
||||
assert !ApplicationManager.application.dispatchThread
|
||||
assert !guard.currentMergeableTransaction
|
||||
assert !guard.contextTransaction
|
||||
log << '2'
|
||||
}).get()
|
||||
}
|
||||
@@ -138,7 +138,7 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
public void "test do not merge into newly started nested transactions"() {
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
log << '1'
|
||||
def id = guard.currentMergeableTransaction
|
||||
def id = guard.contextTransaction
|
||||
SwingUtilities.invokeLater {
|
||||
guard.submitMergeableTransaction testRootDisposable, id, { log << '4' }
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
log << '2'
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
guard.submitMergeableTransaction testRootDisposable, id, { log << '5' }
|
||||
def nestedId = guard.currentMergeableTransaction
|
||||
def nestedId = guard.contextTransaction
|
||||
SwingUtilities.invokeLater {
|
||||
guard.submitMergeableTransaction testRootDisposable, nestedId, { log << '3' }
|
||||
assert log == ['1', '2']
|
||||
|
||||
Reference in New Issue
Block a user