简体   繁体   English

如何为没有源的类生成JavaDoc文档?

[英]How to generate JavaDoc documentation for classes without source?

I would like to generate some basic html interface documentation (without comments of course) of the class files within a jar to which I do not have source. 我想在jar中生成一些我没有源代码的基本html接口文档(当然没有注释)。 How can I go about doing this? 我该怎么做呢?

The old tool of classdoc [Class Doc][1]http://classdoc.sourceforge.net/ which was available for java 1.3 used to provide this service. classdoc [Class Doc] [1] http://classdoc.sourceforge.net/的旧工具,可用于java 1.3,用于提供此服务。 It seems to me that this can be done via the use of reflection. 在我看来,这可以通过使用反射来完成。

Any ideas or examples using javadoc or another utility on how to perform this seemingly simple task on 1.6 or 1.7 classes? 使用javadoc或其他实用程序的任何想法或示例如何在1.6或1.7类上执行这个看似简单的任务?

There are maybe automated solutions but I do not know any. 可能有自动化解决方案,但我不知道。 My best bet would be to write manually some code which will generate dummy java files with javadoc inside. 我最好的选择是手动编写一些代码,这些代码将生成带有javadoc的虚拟java文件。 You'll have to browse the jar file using something like this: 您将不得不使用以下内容浏览jar文件:

ArrayList<Class> classes = new ArrayList<Class>();    
    JarFile jfile = new JarFile("your jar file name");
    String pkgpath = pckgname.replace(".", "/");     
    for (Enumeration<JarEntry> entries = jfile.entries(); entries.hasMoreElements();) {
        JarEntry element = entries.nextElement();     
        if(element.getName().startsWith(pkgpath)
            && element.getName().endsWith(".class")){     
            String fileName = element.getName().substring(pckgname.length() + 1);     
            classes.add(Class.forName(pckgname + "." + fileName .split("\\.")[0]));     
        }     
    }

Then for each class you'll have to browse their methods to finally write down the dummy classes which look like the original ones in the jar file. 然后,对于每个类,您将必须浏览他们的方法,最后写下看起来像jar文件中的原始类的虚拟类。 While the code write the dummy methods to file, make it also write javadoc comments based on what the parameters and the return type are. 当代码将伪方法写入文件时,使它也根据参数和返回类型写入javadoc注释。

Once this is done use javadoc to generate the documentation from your dummy classes. 完成此操作后,使用javadoc从您的虚拟类生成文档。

This might be a bit long to do but that's my guess for this one... 这可能有点长,但我猜这个...

您可以使用jar tvf yourjar.jar列出类,并使用javap来反汇编类,它会产生一个非常清晰的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM