简体   繁体   English

如何从javadoc Ant任务的结果中排除特定的方法/构造函数?

[英]How do I exclude a specific method/constructor from the results of the javadoc Ant task?

I'm using javadocs generated by the javadoc Ant task to document a web service, and I want to exclude some constructors from the output. 我正在使用由javadoc Ant任务生成的javadocs来记录Web服务,并且我想从输出中排除一些构造函数。 How do I do that? 我怎么做?

There is no way to do this for public methods. 对于公共方法,这是没有办法的。 The standard practice (even in quite a few JDK classes) is to indicate that the method or constructor is not meant for public use. 标准实践(即使在相当多的JDK类中)也表明该方法或构造函数不适合公共使用。

There is a plan to add an @exclude tag in the future : 计划在将来添加@exclude标签

@exclude - for API to be excluded from generation by Javadoc. @exclude-用于将Javadoc从生成中排除API。 Programmer would mark a class, interface, constructor, method or field with @exclude. 程序员将使用@exclude标记类,接口,构造函数,方法或字段。 Presence of tag would cause API to be excluded from the generated documentation. 标签的存在将导致API从生成的文档中排除。 Text following tag could explain reason for exclusion, but would be ignored by Javadoc. 标签后面的文字可以解释排除的原因,但Javadoc将忽略它。 (Formerly proposed as @hide, but the term "hide" is more appropriate for run-time dynamic show/hide capability.) For more discussion, see: Feature Request #4058216 in Developer Connection. (以前建议使用@hide,但术语“ hide”更适合于运行时动态显示/隐藏功能。)有关更多讨论,请参见:Developer Connection中的功能请求#4058216

See the relevant Javadoc FAQ entry . 请参阅相关的Javadoc FAQ条目

There is currently no Javadoc option to hide, exclude or suppress public members from the javadoc-generated documentation. 当前没有Javadoc选项可以从javadoc生成的文档中隐藏,排除或禁止公共成员。

It would appear this is not possible in the vanilla Javadoc, but some workarounds are offered. 看起来这在原始 Javadoc中是不可能的,但是提供了一些解决方法。

Isn't excluding something public from your documentation just a variation on "security through obscurity" (or rather, "documentation through obscurity")? 是不是从文档中排除了一些公开的内容,而仅仅是“通过隐蔽性实现安全性”(或者“通过隐蔽性进行文档化”)的变体? If the constructor is part of your code's API, it's available for them to use. 如果构造函数是代码API的一部分,则可供他们使用。 If they find out about it and use it, is that their fault (since you made it public in the first place)? 如果他们发现并使用了它,那是他们的错吗(因为您首先公开了它)?

If you can change the constructor's visibility or remove it altogether, I would go for that. 如果您可以更改构造函数的可见性或完全删除它,那么我会这样做。 If you cannot remove it from the API, make it known in the Javadoc for the constructor that it's not intended for use via web service. 如果您无法将其从API中删除,请在Javadoc中让构造函数知道它不打算通过Web服务使用。 That way you've established a contract with users of your API, informing them not to use it. 这样,您已经与API用户建立了合同,通知他们不要使用它。

It's better to document that it should not be used instead of not documenting it at all (if it's public). 最好记录一下不应使用它,而不是根本不记录它(如果它是公开的)。 Not documenting it adds risk that it gets inadvertently used, and then the client code using it breaks when you change the implementation. 不记录它会增加无意使用它的风险,然后当您更改实现时,使用它的客户端代码就会中断。

Change the method access level of the method, then use the use the javadoc task's access-level filtering attributes, private , package , etc. Only do this if it makes sense in your code, though, eg, method that had inappropriately loose access levels. 更改方法的方法访问级别,然后使用javadoc任务的访问级别过滤属性, privatepackage等。仅在代码中有意义的情况下才执行此操作,例如,访问级别不适当的方法。

For constructors, for example, you could reduce the access level to package , then create a factory class in the same package that provides construction access outside the package. 例如,对于构造函数,您可以降低对package的访问级别,然后在提供该包外部构造访问权限的同一包中创建一个工厂类。 The factory class can be easily filtered from the javadocs. 可以从javadocs中轻松过滤出工厂类。 Kind of hacky, but it works. 有点hacky,但是可以用。

Give Chris Nokleberg's ExcludeDoclet a try: http://www.sixlegs.com/blog/java/exclude-javadoc-tag.html 尝试Chris Nokleberg的ExcludeDoclet: http//www.sixlegs.com/blog/java/exclude-javadoc-tag.html

I've just been experimenting with it and it seems to do the trick. 我一直在尝试它,它似乎可以解决问题。

Currently the simplest solution is to start the javadoc comment with @deprecated , and then pass -nodeprecated to the javadoc command. 目前最简单的办法是先从javadoc注释@deprecated ,然后通过-nodeprecatedjavadoc命令。 Of course, this may not be acceptable if you have actual deprecated items which you nevertheless want to include in the documentation. 当然,如果您有实际已弃用的物品但仍希望包含在文档中,则这可能是不可接受的。

我得到的结果是使用Doclava ,它具有@hide标记,您可以在方法文档中指定该标记。

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

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