javac pretty printer probable bugs
Hi,
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, ...).
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:
1.) it transforms
public class FullClassUsage {
{
new <Object> ArrayList<String>(10) {
{
add("123");
}
};
}
}
into
public class FullClassUsage {
public FullClassUsage() {
super();
}
{
new <Object>ArrayList<String>(10){
(int x0) {
super(x0);
}
{
add("123");
}
};
}
}
the (int x0) is the problem.
2.) when using together with enum types it transforms:
public enum SimpleEnum {
ENUM_CONSTANT_1,
ENUM_CONSTANT_2
}
into
public enum SimpleEnum {
/*public static final*/ ENUM_CONSTANT_1 /* = new SimpleEnum() */,
/*public static final*/ ENUM_CONSTANT_2 /* = new SimpleEnum() */;
private SimpleEnum() {
super();
}
}
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, ...).
Is there any reason why it produces that weird code?
Is there any better way to get the Textual representation of CompilationUnitTree (using pretty printer) that will compile in both of these examples ?
//Martin