[tests] fix "DecompilerPresetKt <clinit> requests AppCodeStyleSettingsManager instance. Class initialization must not depend on services" exception

GitOrigin-RevId: ad5203cbaa478e833c347d17a583eaad6845a2e1
This commit is contained in:
Alexey Kudravtsev
2025-10-27 18:20:18 +00:00
committed by intellij-monorepo-bot
parent 738a0877e3
commit de0dae2e04
3 changed files with 7 additions and 9 deletions
@@ -9,13 +9,13 @@ import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
/**
* Exposing decompilation presets to the users was initially discussed in IDEA-343826.
*/
internal enum class DecompilerPreset(@Nls val description: String, val options: Map<String, String>) {
HIGH(IdeaDecompilerBundle.message("decompiler.preset.high.description"), highPreset),
MEDIUM(IdeaDecompilerBundle.message("decompiler.preset.medium.description"), mediumPreset),
LOW(IdeaDecompilerBundle.message("decompiler.preset.low.description"), lowPreset);
internal enum class DecompilerPreset(@Nls val description: String, val options: () -> Map<String, String>) {
HIGH(IdeaDecompilerBundle.message("decompiler.preset.high.description"), {highPreset}),
MEDIUM(IdeaDecompilerBundle.message("decompiler.preset.medium.description"), {mediumPreset}),
LOW(IdeaDecompilerBundle.message("decompiler.preset.low.description"), {lowPreset});
fun toCommandLineInvocation(): String {
return options
return options()
.filterNot { (key, _) -> key == "ban" || key == "ind" } // remove banner and indent flags as they breaks output
.map { (key, value) -> "-$key=$value" }.joinToString(separator = " ")
}
@@ -124,7 +124,7 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
val mask = "${file.nameWithoutExtension}$"
val files = listOf(file) + file.parent.children.filter { it.name.startsWith(mask) && it.fileType === JavaClassFileType.INSTANCE }
val options: MutableMap<String, Any> = IdeaDecompilerSettings.getInstance().state.preset.options.toMutableMap()
val options: MutableMap<String, Any> = IdeaDecompilerSettings.getInstance().state.preset.options().toMutableMap()
if (Registry.`is`("decompiler.use.line.mapping")) {
options[IFernflowerPreferences.BYTECODE_SOURCE_MAPPING] = "1"
}
@@ -6,7 +6,7 @@ import com.intellij.util.application
@State(name = "IdeaDecompilerSettings", storages = [Storage(StoragePathMacros.NON_ROAMABLE_FILE)])
@Service(Service.Level.APP)
internal class IdeaDecompilerSettings() : PersistentStateComponent<IdeaDecompilerSettings.State?> {
internal class IdeaDecompilerSettings : PersistentStateComponent<IdeaDecompilerSettings.State?> {
private var state = State()
companion object {
@@ -25,14 +25,12 @@ internal class IdeaDecompilerSettings() : PersistentStateComponent<IdeaDecompile
class State {
@JvmField
var preset: DecompilerPreset = DecompilerPreset.HIGH
var options: Map<String, String> = DecompilerPreset.HIGH.options
companion object {
@JvmStatic
fun fromPreset(preset: DecompilerPreset): State {
val newState = State()
newState.preset = preset
newState.options = preset.options
return newState
}
}