Skip to content

Commit dc24041

Browse files
authored
Merge pull request #628 from AlexandrosAlexiou/refactor/dependecies/decompiler
refactor: use JetBrains release repository for FernFlower decompiler
2 parents b7bc79a + 6cf3dac commit dc24041

File tree

10 files changed

+58
-173
lines changed

10 files changed

+58
-173
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ lsp4jVersion = "0.21.2"
44
exposedVersion = "0.37.3"
55
jmhVersion = "1.37"
66
guavaVersion = "33.4.0-jre"
7+
fernFlowerVersion = "243.22562.218"
78

89
[libraries]
910
org-jetbrains-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlinVersion" }
@@ -28,7 +29,7 @@ org-jetbrains-exposed-core = { module = "org.jetbrains.exposed:exposed-core", ve
2829
org-jetbrains-exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposedVersion" }
2930
org-jetbrains-exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposedVersion" }
3031

31-
org-jetbrains-fernflower = { module = "org.jetbrains:fernflower", version = "1.0" }
32+
com-jetbrains-intellij-java-decompiler = { module = "com.jetbrains.intellij.java:java-decompiler-engine", version.ref = "fernFlowerVersion" }
3233

3334
com-github-fwcd-ktfmt = { module = "com.github.fwcd.ktfmt:ktfmt", version = "b5d31d1" }
3435

platform/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies {
1515
api(libs.org.jetbrains.kotlin.sam.with.receiver.compiler.plugin)
1616
api(libs.org.jetbrains.kotlin.reflect)
1717
api(libs.org.jetbrains.kotlin.jvm)
18-
api(libs.org.jetbrains.fernflower)
18+
api(libs.com.jetbrains.intellij.java.decompiler)
1919
api(libs.org.jetbrains.exposed.core)
2020
api(libs.org.jetbrains.exposed.dao)
2121
api(libs.org.jetbrains.exposed.jdbc)

server/build.gradle.kts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ application {
1919
mainClass.set(serverMainClassName)
2020
description = "Code completions, diagnostics and more for Kotlin"
2121
applicationDefaultJvmArgs = listOf("-DkotlinLanguageServer.version=$version")
22-
applicationDistribution.into("bin") {
23-
filePermissions { unix("755".toInt(radix = 8)) }
24-
}
22+
applicationDistribution.into("bin") { filePermissions { unix("755".toInt(radix = 8)) } }
2523
}
2624

2725
repositories {
2826
maven(url = "https://repo.gradle.org/gradle/libs-releases")
29-
maven { url = uri("$projectDir/lib") }
30-
maven(uri("$projectDir/lib"))
3127
maven("https://jitpack.io")
28+
maven(url = "https://www.jetbrains.com/intellij-repository/releases")
3229
mavenCentral()
3330
}
3431

@@ -48,7 +45,7 @@ dependencies {
4845
implementation(kotlin("scripting-jvm-host-unshaded"))
4946
implementation(kotlin("sam-with-receiver-compiler-plugin"))
5047
implementation(kotlin("reflect"))
51-
implementation(libs.org.jetbrains.fernflower)
48+
implementation(libs.com.jetbrains.intellij.java.decompiler)
5249
implementation(libs.org.jetbrains.exposed.core)
5350
implementation(libs.org.jetbrains.exposed.dao)
5451
implementation(libs.org.jetbrains.exposed.jdbc)
@@ -79,9 +76,9 @@ tasks.register<Exec>("fixFilePermissions") {
7976

8077
onlyIf { !System.getProperty("os.name").lowercase().contains("windows") }
8178
commandLine(
82-
"chmod",
83-
"+x",
84-
"${tasks.installDist.get().destinationDir}/bin/kotlin-language-server"
79+
"chmod",
80+
"+x",
81+
"${tasks.installDist.get().destinationDir}/bin/kotlin-language-server",
8582
)
8683
}
8784

server/lib/fernflower-license.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

server/lib/gradle-kotlin-dsl-tooling-models-0.11.0-license.txt

Lines changed: 0 additions & 85 deletions
This file was deleted.
Binary file not shown.

server/lib/org/jetbrains/fernflower/1.0/fernflower-1.0.pom

Lines changed: 0 additions & 19 deletions
This file was deleted.

server/src/main/kotlin/org/javacs/kt/externalsources/ClassContentProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ClassContentProvider(
2121
private val cp: CompilerClassPath,
2222
private val tempDir: TemporaryDirectory,
2323
private val sourceArchiveProvider: SourceArchiveProvider,
24-
private val decompiler: Decompiler = FernflowerDecompiler()
24+
private val decompiler: Decompiler = FernFlowerDecompiler()
2525
) {
2626
/** Maps recently used (source-)KLS-URIs to their source contents (e.g. decompiled code) and the file extension. */
2727
private val cachedContents = object : LinkedHashMap<String, Pair<String, String>>() {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.javacs.kt.externalsources
2+
3+
import java.nio.file.Files
4+
import java.nio.file.Path
5+
import org.javacs.kt.LOG
6+
import org.javacs.kt.util.KotlinLSException
7+
import org.javacs.kt.util.replaceExtensionWith
8+
import org.javacs.kt.util.withCustomStdout
9+
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler
10+
11+
class FernFlowerDecompiler : Decompiler {
12+
private val outputDir: Path by lazy {
13+
Files.createTempDirectory("fernflowerOut").also {
14+
Runtime.getRuntime().addShutdownHook(Thread { it.toFile().deleteRecursively() })
15+
}
16+
}
17+
18+
private val decompilerOptions =
19+
arrayOf(
20+
"-iec=1", // Include entire classpath for better context
21+
"-jpr=1", // Include parameter names in method signatures
22+
)
23+
24+
override fun decompileClass(compiledClass: Path): Path {
25+
return decompile(compiledClass, ".java")
26+
}
27+
28+
override fun decompileJar(compiledJar: Path): Path {
29+
return decompile(compiledJar, ".jar")
30+
}
31+
32+
private fun decompile(input: Path, extension: String): Path {
33+
LOG.info("Decompiling ${input.fileName} using FernFlower...")
34+
35+
val args = decompilerOptions + arrayOf(input.toString(), outputDir.toString())
36+
37+
withCustomStdout(LOG.outStream) { ConsoleDecompiler.main(args) }
38+
39+
val outName = input.fileName.replaceExtensionWith(extension)
40+
val outPath = outputDir.resolve(outName)
41+
if (!Files.exists(outPath)) {
42+
throw KotlinLSException(
43+
"Could not decompile ${input.fileName}: FernFlower did not generate sources at $outName"
44+
)
45+
}
46+
return outPath
47+
}
48+
}

server/src/main/kotlin/org/javacs/kt/externalsources/FernflowerDecompiler.kt

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)