’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.

And what did your Scala compiler ate this week?

And what did your Scala compiler ate this week?

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.

With Scala Plugin

With Scala Plugin

Without Scala Plugin

Without Scala Plugin

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.

Javap-Signature

Javap-Signature

Javap Bytecode

Javap Bytecode

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:

ClassAnalyer vs Javap

ClassAnalyer vs Javap

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.

Tagged on: , ,

2 thoughts on “’Decompiling’ Scala

  1. Toby

    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!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>