-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from AlexandrosAlexiou/refactor/dependecies/d…
…ecompiler refactor: use JetBrains release repository for FernFlower decompiler
- Loading branch information
Showing
10 changed files
with
58 additions
and
173 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
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
server/lib/gradle-kotlin-dsl-tooling-models-0.11.0-license.txt
This file was deleted.
Oops, something went wrong.
Binary file not shown.
19 changes: 0 additions & 19 deletions
19
server/lib/org/jetbrains/fernflower/1.0/fernflower-1.0.pom
This file was deleted.
Oops, something went wrong.
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
48 changes: 48 additions & 0 deletions
48
server/src/main/kotlin/org/javacs/kt/externalsources/FernFlowerDecompiler.kt
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,48 @@ | ||
package org.javacs.kt.externalsources | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import org.javacs.kt.LOG | ||
import org.javacs.kt.util.KotlinLSException | ||
import org.javacs.kt.util.replaceExtensionWith | ||
import org.javacs.kt.util.withCustomStdout | ||
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler | ||
|
||
class FernFlowerDecompiler : Decompiler { | ||
private val outputDir: Path by lazy { | ||
Files.createTempDirectory("fernflowerOut").also { | ||
Runtime.getRuntime().addShutdownHook(Thread { it.toFile().deleteRecursively() }) | ||
} | ||
} | ||
|
||
private val decompilerOptions = | ||
arrayOf( | ||
"-iec=1", // Include entire classpath for better context | ||
"-jpr=1", // Include parameter names in method signatures | ||
) | ||
|
||
override fun decompileClass(compiledClass: Path): Path { | ||
return decompile(compiledClass, ".java") | ||
} | ||
|
||
override fun decompileJar(compiledJar: Path): Path { | ||
return decompile(compiledJar, ".jar") | ||
} | ||
|
||
private fun decompile(input: Path, extension: String): Path { | ||
LOG.info("Decompiling ${input.fileName} using FernFlower...") | ||
|
||
val args = decompilerOptions + arrayOf(input.toString(), outputDir.toString()) | ||
|
||
withCustomStdout(LOG.outStream) { ConsoleDecompiler.main(args) } | ||
|
||
val outName = input.fileName.replaceExtensionWith(extension) | ||
val outPath = outputDir.resolve(outName) | ||
if (!Files.exists(outPath)) { | ||
throw KotlinLSException( | ||
"Could not decompile ${input.fileName}: FernFlower did not generate sources at $outName" | ||
) | ||
} | ||
return outPath | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
server/src/main/kotlin/org/javacs/kt/externalsources/FernflowerDecompiler.kt
This file was deleted.
Oops, something went wrong.