获得不受欢迎的财产摘要"生成Javadoc时的部分

时间:2014-10-02 16:51:17

标签: java javadoc

我有一些javadoc方法,如下所示:

/**
 * Convenience method that determines whether this {@code ContextLink} links a {@code Property} or not.
 * <p>
 * If this {@code ContextLink}'s {@code ContextType} is anything other than {@code ContextType.GROUP}, it links a
 * {@code Property}.
 *
 * @return  {@code true} if the {@code ContextLink} links a {@code Property}, otherwise {@code false}
 */
public final boolean isProperty() {
    return getType() != ContextType.GROUP;
}

/**
 * Convenience method that determines whether this {@code ContextLink} links a {@code Property} with advanced
 * behavior or not.
 * <p>
 * If this {@code ContextLink}'s {@code ContextType} is {@code ContextType.ADVANCED}, it links a {@code Property}
 * with advanced behavior.
 *
 * @return  {@code true} if the {@code ContextLink} links a {@code Property} with advanced behavior, otherwise
 *          {@code false}
 */
@SuppressWarnings("UnusedDeclaration")
public final boolean isAdvancedProperty() {
    return getType() == ContextType.ADVANCED;
}

/**
 * Convenience method that determines whether this {@code ContextLink} links a web application {@code Property} or
 * not.
 * <p>
 * If this {@code ContextLink}'s {@code ContextType} is {@code ContextType.APPLICATION}, it links a web application
 * {@code Property}.
 *
 * @return  {@code true} if the {@code ContextLink} links a web application {@code Property}, otherwise
 *          {@code false}
 */
@SuppressWarnings("UnusedDeclaration")
public final boolean isApplicationProperty() {
    return getType() == ContextType.APPLICATION;
}

当我生成javadoc时,我会得到一个我不想要的属性摘要部分。不是将我的方法视为普通方法,而是将它们视为不合适的特殊处理。如何在不重命名我的方法的情况下阻止这种情况,以便他们不会在“财产”中结束?我有自己的Property class,这样命名是有意义的,因为这实际上是我们的业务领域词汇表中的名称。

enter image description here

2 个答案:

答案 0 :(得分:2)

这是Javadoc工具中的一个错误,更准确地说是VisibleMemberMap#isPropertyMethod(MethodDoc)

在确定应特别处理并在&#34;属性摘要&#34;中出现的方法列表时,Javadoc选择所有可见的方法,名称以&#34结尾;属性&#34; ,没有任何参数,不返回void,并且名称不以&#34; getX&#34;开头。或&#34; setX&#34;其中X是任何大写字母。

由于对getter和setter方法有特殊处理(正则表达式&#34; [sg] et \ p {Upper}。*&#34;被使用),我确信这是一个bug,无论谁写了这段代码忘记也考虑以&#34开头的getter方法是&#34;。

我向JDK团队提交了一个错误报告,解释了这个问题并建议了一个简单的修复(只需用[sg]et\\p{Upper}.*替换正则表达式([sg]et|is)\\p{Upper}.* abc。当这个错误报告得到一个时,我会更新这个答案公共错误ID已分配。

目前只有两种解决方法:

修复Javadoc工具中的问题,重新编译Javadoc并使用修补版本。如果无法控制生成API文档的环境,这可能不可行。

作为替代方案,布尔getter方法可以重命名为&#34; getX&#34;而不是&#34; isX&#34;,但这可能违反了某些命名约定,对JavaBeans也无效。除此之外,它还会破坏与依赖旧名称的代码的兼容性。

第二种解决方案的另一个变体是重命名方法,使其名称不以&#34;属性&#34;结尾。例如&#34; isPropertyAdvanced&#34;而不是&#34; isAdvancedProperty&#34;。但是,这仍然存在破坏现有代码的问题。

更新:最后,错误报告被添加到公共错误跟踪系统中。它有错误ID JDK-8161254

答案 1 :(得分:0)

根据javadoc tool documentation,使用Property Summary选项运行javadoc时会生成-javafx部分。因此,如果您想要删除此部分,并且您正在使用标准doclet,请运行不带此选项的工具。

编辑:似乎此选项仅在Java 8以后可用。

相关问题