’Decompiling’ Scala
Somehow I often end up in a situation where I need to take a look at what the Scala compiler generates, mainly at the class-signature of the generated stuff. So here is a list if the tools I frequently use for doing this.
IntelliJ IDEA
Well, I’m usually hacking Scala in Intellij, so why not using it as a ‘decompiler’. When you drop a class file into IntelliJ it shows the signature of the class. Well, with the Scala plugin installed it shows a Scala outline, which is nice. However when you want to see the raw signature it is kind of pointless. Without the Scala plugin you will see the regular Java outline.
Javap
The JDK brings its own decompiler and it does its job well. The scalap command will decompile class files to a simple text output. Depending on the arguments it shows the outline or all the byte code details. So, this little tool is your friend.
Just run the javap command to see what options are available. Javap will print its result to the standard out, so you just can pipe to the proper place.
Classfile Analyser
This little tool basically does more or less the same as Javap. However it uses a different output format, namely the Jasmin 2 ‘bytecode’ assembler. Certain things are easier to read here than in the Javap output. For example annotations:
Java Decompilers
I sometimes used freely available Scala decompilers to take a look at Scala class files. However those tend to fuck up when generating Java code for certain Scala constructs. That often adds confusion instead of clearing things up. I would recommend sticking to javap etc. which do not attempt to create Java code.
Well maybe there is a really good decompiler out there which works flawless. In case you have a different experience, let me know.
- BBC의 셜록 2기 시리즈 / BBC’s: Sherlock Series 2
- Ijon Tichy 시리즈 2기 / Ijon Tichy: Raumpilot 2nd Series
Did you try JD-GUI? I’m not sure if it’s the decompiler or me, but I’m left with confusing java source from scala class files!
Yes, I tried that aswell. But it tends to create broken, unreadable Java Code from Scala-Source.