[java-decompiler] IDEA-381330 fix DecompilerPresetKt class requesting CodeStyle services during class init

I think it's good enough to hardcode the indent size for decompiled code to CodeStyleDefaults.DEFAULT_INDENT_SIZE (which is 4).
It was using application-wide indent size anyway (not the project-wide one),
which I doubt people customize – usually the one that is customized is the project-wide setting.

If someone really wants to view decompiled code with their customized indent size,
let's hope they will create a ticket in YouTrack, and then we'll implement it.

This commit also partially reverts the previous commit by Alexey Kudravtsev
(monorepo commit ad5203cbaa478e833c347d17a583eaad6845a2e1)

GitOrigin-RevId: 4e00b33fda24218ec0d358d567fb9f7366e13edc
This commit is contained in:
Bartek Pacia
2025-10-31 17:59:58 +00:00
committed by intellij-monorepo-bot
parent 391662586e
commit 4d556dfb6d
2 changed files with 8 additions and 9 deletions
@@ -1,21 +1,20 @@
// Copyright 2000-2024 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.application.options.CodeStyle
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.psi.codeStyle.CodeStyleDefaults
import org.jetbrains.annotations.Nls
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 = " ")
}
@@ -25,7 +24,7 @@ private val basePreset: Map<String, String> = mapOf(
// Appearance-specific options
IFernflowerPreferences.BANNER to IDEA_DECOMPILER_BANNER,
IFernflowerPreferences.NEW_LINE_SEPARATOR to "1",
IFernflowerPreferences.INDENT_STRING to " ".repeat(CodeStyle.getDefaultSettings().getIndentOptions(JavaFileType.INSTANCE).INDENT_SIZE),
IFernflowerPreferences.INDENT_STRING to " ".repeat(CodeStyleDefaults.DEFAULT_INDENT_SIZE),
IFernflowerPreferences.MAX_PROCESSING_METHOD to "60",
IFernflowerPreferences.IGNORE_INVALID_BYTECODE to "1",
@@ -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"
}