We’ve all seen those books that consist entirely of listings of the Java API for version thus-and-such of the JDK. I don’t suppose you thought the authors of these works sat down and typed the entire contents from scratch. As a programmer, you would have realized, I hope, that there must be a way to obtain that information from Java. But you might not have realized how easy it is! If you’ve read this chapter faithfully, you now know that there is one true way: make the computer do the walking. Example 25-9 is a program that puts most of the techniques together. This version generates a cross-reference listing, but by overriding the last few methods you could easily convert it to print the information in any format you like, including an API Reference book. You’d need to deal with the details of this or that publishing software -- FrameMaker, troff, TEX, or whatever -- but that’s the easy part.
This program makes fuller use of the reflection API than did
JavaP in Section 25.7. It also
classes (see Section 9.19) to crack the JAR archive containing the class
files of the API. Each class file found in the archive is loaded and
listed; the listing part is similar to
Example 25-9. CrossRef.java
import java.io.*; import java.util.*; import java.util.zip.*; import java.lang.reflect.*; /** * CrossRef prints a cross-reference about all classes named in argv. * For each class, all public fields and methods are listed. * "Reflectance" is used ...