views:

230

answers:

3

I'm looking for the source code of Sun's standard java compiler, javac.

jdk1.6.0_07 has a few classes that are related, but they are interfaces (java.lang.Compiler and javax.tools.JavaCompiler). There's also some packages under com.sun.mirror.* and com.sun.source.*, which seem to be interfaces for representing the java abstract syntax tree.

But I can't find the compiler source - anyone know where it is?

+4  A: 

Check this site The Java programming-language compiler (javac) group. The sources are in the Mercurial repositories.

jdk7/tl/langtools (for JDK 1.7)

jdk6/jdk6/langtools (for JDK 1.6)

In the header of the two sites I linked to you find download links for the sources (in bz2, zip and gz format)

There you have the sources in *src\share\classes\com\sun\tools\javac\*

jitter
thanks! Is the official sun one (that comes with the jdk), not a reimplementation? BTW: The parser seems to be a simple recursive descent parser, closely modeling the JLS http://hg.openjdk.java.net/jdk6/jdk6/langtools/file/a9008b46db24/src/share/classes/com/sun/tools/javac/parser/Parser.jav. so you can trace through the grammar.
13ren
It should be the official one. As since approx. 2006 the JDK/JRE are opensource. There was a time when certain pieces of JDK/JRE maybe tools too weren't completely opensource as there where some licensing issues. If you want to know since what build exactly the javac is opensource I suggest writing to the appropriate openjdk mailinglist
jitter
Thanks, looking through the source, some have the Sun copyright notice, and some explicitly say their API isn't Sun-supported.
13ren
I just wanted to say how much I appreciate your answer. It was an Indiana moment to trace through the parsing of familiar parts of a java program (e.g. a class declaration); like secret knowledge. Even more affirming was to recognize the recursive descent parsing as exactly the same flavour as parsing code I've written recently: in this, the java engineers are my peers.
13ren
+1  A: 

It's here

Foxfire
+1  A: 

It is also here:

http://java.sun.com/javase/downloads/index.jsp

In the section:

Java SE 6 JDK Source Code

OscarRyz