It looks like the Enum problem should alreadz be fixed according to bug 6902720 (<a href="http://hg.openjdk.java.net/jdk7/tl/langtools/rev/b1bb8164a9bd">http://hg.openjdk.java.net/jdk7/tl/langtools/rev/b1bb8164a9bd</a>, <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6902720">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6902720</a>), but it is not.<br>
<br><div class="gmail_quote">2012/1/29 Rémi Forax <span dir="ltr"><<a href="mailto:forax@univ-mlv.fr">forax@univ-mlv.fr</a>></span><br><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
<div><div></div><div class="h5">On 01/29/2012 01:40 PM, Crazy Java wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
Hi,<br>
as part of the javac AST Visualizer project, I have some difficulties with javac's pretty printer. The problem is the fact, that I am doing double compilation (after first compilation I get the textual representation of produced AST and that is in fact used for visualization purposes). Double compilation is needed because I want to visualize all the compiler sugar (default constructor, effectively final variables in ARM, code generated for enum, ...).<br>
The problem is that javac's pretty printer (I guess it is pretty printer) after calling CompilationUnitTree.toString() produces in some specific situations code that is not able to compile:<br>
1.) it transforms<br>
public class FullClassUsage {<br>
{<br>
new <Object> ArrayList<String>(10) {<br>
{<br>
add("123");<br>
}<br>
};<br>
}<br>
}<br>
into<br>
public class FullClassUsage {<br>
<br>
public FullClassUsage() {<br>
super();<br>
}<br>
{<br>
new <Object>ArrayList<String>(10){<br>
<br>
(int x0) {<br>
super(x0);<br>
}<br>
{<br>
add("123");<br>
}<br>
};<br>
}<br>
}<br>
the (int x0) is the problem.<br>
2.) when using together with enum types it transforms:<br>
public enum SimpleEnum {<br>
ENUM_CONSTANT_1,<br>
ENUM_CONSTANT_2<br>
}<br>
into<br>
public enum SimpleEnum {<br>
/*public static final*/ ENUM_CONSTANT_1 /* = new SimpleEnum() */,<br>
/*public static final*/ ENUM_CONSTANT_2 /* = new SimpleEnum() */;<br>
<br>
private SimpleEnum() {<br>
super();<br>
}<br>
}<br>
that is really weird. Not only it generates comments ??? but also a super call causing the code not to compile. I would also assume that it will generate all the enum type code (constructors with n+2 arguments, valueOf() factory method, extending java.lang.Enum, ...).<br>
Is there any reason why it produces that weird code?<br>
</blockquote>
<br></div></div>
Java language != bytecode,<br>
at the end javac will generate bytecodes and there are a lot of things that are allowed<br>
in bytecode that are not allowed in Java.<br>
<br>
The pretty printer is something used to debug and not something that will generate fully compatible Java code<br>
because some de-sugared code are only valid in bytecode but not in Java.<div class="im"><br>
<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
Is there any better way to get the Textual representation of CompilationUnitTree (using pretty printer) that will compile in both of these examples ?<br>
</blockquote>
<br></div>
write your own :)<br>
<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
//Martin<br>
</blockquote><font color="#888888">
<br>
Rémi<br>
<br>
</font></blockquote></div><br>