diff --git a/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressCallback.java b/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressCallback.java
index 609491f2a129..dbb1f3382a56 100644
--- a/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressCallback.java
+++ b/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressCallback.java
@@ -78,15 +78,7 @@ public interface FormattingProgressCallback {
*/
void setTask(@Nullable SequentialTask task);
- /**
- * Allows to register callback for the target event type.
- *
- * @param eventType target event type
- * @param callback callback to register for the given event type
- * @return {@code true} if given callback is successfully registered for the given event type;
- * {@code false} otherwise
- */
- boolean addCallback(@NotNull EventType eventType, @NotNull Runnable callback);
+ void cancelled();
/**
* Null object for {@link FormattingProgressCallback}.
@@ -113,8 +105,7 @@ public interface FormattingProgressCallback {
}
@Override
- public boolean addCallback(@NotNull EventType eventType, @NotNull Runnable callback) {
- return false;
+ public void cancelled() {
}
};
}
diff --git a/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressTask.java b/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressTask.java
index 2a9f2d0a7ded..98d3e29bd702 100644
--- a/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressTask.java
+++ b/platform/code-style-impl/src/com/intellij/formatting/FormattingProgressTask.java
@@ -13,7 +13,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.SequentialModalProgressTask;
import com.intellij.util.SequentialTask;
-import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -21,8 +20,6 @@ import org.jetbrains.annotations.Nullable;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
public final class FormattingProgressTask extends SequentialModalProgressTask implements FormattingProgressCallback {
public static final ThreadLocal FORMATTING_CANCELLED_FLAG = ThreadLocal.withInitial(() -> false);
@@ -31,8 +28,6 @@ public final class FormattingProgressTask extends SequentialModalProgressTask im
private static final double TOTAL_WEIGHT =
Arrays.stream(FormattingStateId.values()).mapToDouble(FormattingStateId::getProgressWeight).sum();
- private final ConcurrentMap> myCallbacks = new ConcurrentHashMap<>();
-
private final WeakReference myFile;
private final WeakReference myDocument;
private final int myFileTextLength;
@@ -48,7 +43,6 @@ public final class FormattingProgressTask extends SequentialModalProgressTask im
myFile = new WeakReference<>(file.getVirtualFile());
myDocument = new WeakReference<>(document);
myFileTextLength = file.getTextLength();
- addCallback(EventType.CANCEL, new MyCancelCallback());
}
private static @NotNull @NlsContexts.DialogTitle String getTitle(@NotNull PsiFile file) {
@@ -72,42 +66,15 @@ public final class FormattingProgressTask extends SequentialModalProgressTask im
});
}
- @Override
- public boolean addCallback(@NotNull EventType eventType, @NotNull Runnable callback) {
- return getCallbacks(eventType).add(callback);
- }
-
- @Override
- public void onSuccess() {
- for (Runnable callback : getCallbacks(EventType.SUCCESS)) {
- callback.run();
- }
- }
-
@Override
public void onCancel() {
- for (Runnable callback : getCallbacks(EventType.CANCEL)) {
- callback.run();
- }
+ cancelled();
}
@Override
public void onThrowable(@NotNull Throwable error) {
super.onThrowable(error);
- for (Runnable callback : getCallbacks(EventType.CANCEL)) {
- callback.run();
- }
- }
-
- private Collection getCallbacks(@NotNull EventType eventType) {
- Collection result = myCallbacks.get(eventType);
- if (result == null) {
- Collection candidate = myCallbacks.putIfAbsent(eventType, result = ContainerUtil.newConcurrentSet());
- if (candidate != null) {
- result = candidate;
- }
- }
- return result;
+ cancelled();
}
@Override
@@ -166,21 +133,19 @@ public final class FormattingProgressTask extends SequentialModalProgressTask im
}
}
- private final class MyCancelCallback implements Runnable {
- @Override
- public void run() {
- FORMATTING_CANCELLED_FLAG.set(true);
- VirtualFile file = myFile.get();
- Document document = myDocument.get();
- if (file == null || document == null || myDocumentModificationStampBefore < 0) {
- return;
- }
- FileEditor editor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
- if (editor == null) {
- return;
- }
-
- EditorFacade.getInstance().undo(myProject, editor, document, myDocumentModificationStampBefore);
+ @Override
+ public void cancelled() {
+ FORMATTING_CANCELLED_FLAG.set(true);
+ VirtualFile file = myFile.get();
+ Document document = myDocument.get();
+ if (file == null || document == null || myDocumentModificationStampBefore < 0) {
+ return;
}
+ FileEditor editor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
+ if (editor == null) {
+ return;
+ }
+
+ EditorFacade.getInstance().undo(myProject, editor, document, myDocumentModificationStampBefore);
}
}