Sunday, December 19, 2004

Javadoc broken for enums?

Here's another puzzle, stripped down as much as I could so you can see the problem:


import com.sun.javadoc.*;

public class TestEnum {
static void test(Doc d) {
System.out.println(d);
if(d.isEnum())
System.out.println(d + " is enum");
if(d.isEnumConstant())
System.out.println(d + " is EnumConstant");
}
public static boolean start(RootDoc root) {
for(ClassDoc cDoc : root.classes()) {
System.out.println("-----Class------");
test(cDoc);
System.out.println("------EnumConstants------");
for(FieldDoc fd : cDoc.enumConstants())
test(fd);
System.out.println("------Fields------");
for(FieldDoc fd : cDoc.fields())
test(fd);
System.out.println("------Methods------");
for(MethodDoc md : cDoc.methods())
test(md);
}
return true;
}
}

enum Foo { bar, baz }

If you use the following command line:

javadoc -doclet TestEnum -package TestEnum.java

Here's the output:

Loading source file TestEnum.java...
Constructing Javadoc information...
-----Class------
TestEnum
------EnumConstants------
------Fields------
------Methods------
TestEnum.test(com.sun.javadoc.Doc)
TestEnum.start(com.sun.javadoc.RootDoc)
-----Class------
Foo
------EnumConstants------
------Fields------
Foo.bar
Foo.baz
------Methods------
Foo.values()
Foo.valueOf(java.lang.String)

So it sees the enum Foo, but it doesn't seem to recognize it as an enum. Similarly, it sees the fields but not as enum constants.

I'm thinking this is broken, but maybe I missed something. Anyone know?