IJ-CR-108265 [java-decompiler] IDEA-198397 add cancelled checks for java-decompiler

GitOrigin-RevId: 845695f0775b844c27343e9216bbc5c12d0c13cc
This commit is contained in:
Mikhail Pyltsin
2023-06-13 19:19:12 +02:00
committed by intellij-monorepo-bot
parent 47d79a54d7
commit b90082abea
17 changed files with 144 additions and 127 deletions

View File

@@ -0,0 +1,22 @@
// 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.java.decompiler;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.java.decompiler.main.CancellationManager;
@ApiStatus.Experimental
public class IdeaCancellationManager extends CancellationManager.SimpleWithTimeoutCancellationManager {
@Override
public void checkCanceled() throws CanceledException, TimeExceedException {
try {
ProgressManager.checkCanceled();
}
catch (ProcessCanceledException e) {
throw new CanceledException(e);
}
super.checkCanceled();
}
}

View File

@@ -147,7 +147,8 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
val provider = MyBytecodeProvider(files)
val saver = MyResultSaver()
val decompiler = BaseDecompiler(provider, saver, options, myLogger.value, SimpleCancellationManager())
val decompiler = BaseDecompiler(provider, saver, options, myLogger.value,
IdeaCancellationManager())
files.forEach { decompiler.addSource(File(it.path)) }
try {
decompiler.decompileContext()

View File

@@ -1,47 +0,0 @@
// 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.java.decompiler;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.java.decompiler.main.CancellationManager;
@ApiStatus.Experimental
public class SimpleCancellationManager implements CancellationManager {
private volatile ProcessCanceledException exception = null;
@Override
public void checkCanceled() throws CanceledException {
try {
ProgressManager.checkCanceled();
}
catch (ProcessCanceledException e) {
exception = e;
throw new CanceledException(e);
}
}
@Override
public void saveCancelled() {
if (exception != null) {
return;
}
try {
checkCanceled();
}
catch (CanceledException e) {
if (e.getCause() instanceof ProcessCanceledException) {
exception = (ProcessCanceledException)e.getCause();
}
}
}
@Override
public void checkSavedCancelled() throws CanceledException {
ProcessCanceledException currentException = exception;
if (currentException != null) {
throw new CanceledException(currentException);
}
}
}