eclipse添加未实现的方法,包括javadoc

时间:2010-04-08 14:01:36

标签: java eclipse code-generation

在eclipse中实现接口时,它有一个非常好的功能,可以让你“添加未实现的方法”,它将为接口方法生成方法存根。

然而,它没有带来接口方法的方法文档,我想知道是否有办法让eclipse做到这一点。

这就是我想要发生的事情。假设我有一个这样的界面:

public interface BaseInterface {

    /**
     * This method takes the given string parameter and returns its integer value.
     * 
     * @param x the string to convert
     * @return the integer value of the string
     * 
     * @throws Exception if some error occurs
     */
    int method1(String x);
}

现在我创建了一个名为MyClass的类来实现这个接口。我想要发生的是,当我说“添加未实现的方法”时,我希望我的代码看起来像这样:

public class MyClass implements BaseInterface {

    /**
     * This method takes the given string parameter and returns its integer value.
     * 
     * @param x the string to convert
     * @return the integer value of the string
     * 
     * @throws Exception if some error occurs
     */
    public int method1(String x) {
        return 0;
    }

}

2 个答案:

答案 0 :(得分:5)

Yup:这些方法是使用您编写的代码模板生成的。

您必须进入“窗口/首选项 - > Java /代码样式/代码模板”

然后,在列表中选择“评论/覆盖方法”并使用您在“评论/方法”中找到的内容更改内容:

/**
 * ${tags}
 */

您甚至可以考虑添加${see_to_overridden}以直接链接到原始方法。但是,请注意,没有javadoc的方法会自动从其覆盖的方法继承其javadoc,因此这样的模板可能会生成与默认行为不太相关的文档。

答案 1 :(得分:0)

您可以通过JavaDoc注释实现它。它不是特定于Eclipse的,并且适用于所有构建/文档生成工具:

/**
 * My custom decumentation, and then the original one:
 * 
 * {@inheritDoc}
 */