-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b86b2e
commit 74d40fb
Showing
10 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/org/jetbrains/java/decompiler/main/decompiler/CancelationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.jetbrains.java.decompiler.main.decompiler; | ||
|
||
/** | ||
* Used for cancelling the decompilation process. This can for example be useful in GUI frontends with cancelation | ||
* support. | ||
*/ | ||
public final class CancelationManager { | ||
private static Runnable cancelationChecker = () -> {}; | ||
|
||
private CancelationManager() { | ||
} | ||
|
||
/** | ||
* Cancels the decompilation process by throwing a {@linkplain CanceledException}. | ||
*/ | ||
public static void cancel() { | ||
throw CanceledException.INSTANCE; | ||
} | ||
|
||
/** | ||
* Polled frequently by the decompiler to check if decompilation has been canceled. Use | ||
* {@linkplain #setCancelationChecker(Runnable)} to set the logic for checking cancelation. | ||
*/ | ||
public static void checkCanceled() { | ||
cancelationChecker.run(); | ||
} | ||
|
||
/** | ||
* Sets the logic for checking cancelation. To cancel decompilation, call {@linkplain #cancel()} inside the checker. | ||
*/ | ||
public static void setCancelationChecker(Runnable checker) { | ||
cancelationChecker = checker; | ||
} | ||
|
||
/** | ||
* The exception that is thrown upon cancelation. | ||
*/ | ||
public static final class CanceledException extends RuntimeException { | ||
public static final CanceledException INSTANCE = new CanceledException(); | ||
|
||
private CanceledException() { | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters