18
votes

The Javadoc for enums always display its constants using alphabetic ordering. Is it possible to change that?

For instance, the javadoc for java.time.DayOfWeek would look better if the constants weren't displayed as FRIDAY, MONDAY, SATURDAY, SUNDAY, THURSDAY TUESDAY, WEDNESDAY...

1
I don't know if it's possible but the new Java time javadoc has not been able to do that: docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.htmlwha'eve'
I'm not really don't understand this question.Abimaran Kugathasan
Your enum example, seems to be from DayOfWeek in Java8. Looking at the Java8 javadoc for the compareTo method in Enum it looks like the order will be the order in which the values are declared, which is in alphabetical order in your example.Dan Temple
@AbimaranKugathasan OP's asking about why the javadoc tool produces documentation for declared enum values in alphabetical order instead of the order they were declared, and if this behavior can be altered.awksp
Not only Enums, all the fields, methods are order by alphabetically.Abimaran Kugathasan

1 Answers

1
votes

The default HTML doclet sorts the summaries of its members.

Collections.sort(members);

from /com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java :312

It is probably best that you don't do this.

Javadoc puts the summaries in alphabetical order so that you can quickly find the one you want. Breaking that model would make the Javadoc much harder to quickly scan and find what you are looking for.

Alphabetical order only applies to the summary, the full Javadoc will be in the order of decleration in the source file.


If you really needed to do this then you could roll your own doclet or perhaps a taglet might be able to do it.