如何在java中添加注释框?

时间:2015-02-13 11:48:09

标签: java eclipse comments shortcut box

我正在使用Java中的一个项目,我需要在每个方法上面添加一个注释框来解释每个方法的作用。它应该是这样的:

***** *** ** ** **(星号线)***************************** ******************************************** * @ PARAM

*

**** *** ** ** ** **(另一条线)**************************** *****************************************

我正在使用eclipse,我知道有一个快捷方式可以制作这个盒子,但我似乎无法记住它或在网上找到它...

3 个答案:

答案 0 :(得分:5)

转到日食>窗户>偏好> java>模板

点击NEW现在为您的模式命名并添加说明并提供以下模式

/*****************************************************************************************
* ${cursor}This is default description for this method. Kindly remove this type the actual 
* usage and other relevant information for the method as description.
* @since    ${date}
* @param    paramName   Parameter description 
* @return   <Description of return value. Remove this tab for return type     void.>
* @throws   ExceptionClass  Description of the exception reason or  scenario
*****************************************************************************************/

/*
* Author    ${user}
* Version   <Enter the version of the product/project for this method.> 
* History   Updated By      Update Date     Update Reason
*           ==============  ===========     ================================================
*/

使用上下文作为java,现在最后显示创建任何类,然后在引入方法之前添加方法只需开始键入上述模板的名称,然后按CTRL + SPACE并选择模板并繁荣您的方法阅读说明。

答案 1 :(得分:0)

在主菜单窗口中 - &gt;喜好 在左边的树上 Java-&gt;代码样式 - &gt; CodeTemplates 在右侧面板上,选择注释 - &gt;方法并在右下方文本区域中打印模式

答案 2 :(得分:0)

最好使用JavaDoc记录每个方法,并解释它们的作用,参数,返回的内容以及可能引发的异常。

/**
 * This is proper JavaDoc notation. It starts with a forward slash, two asterisks
 * and then an asterisk per line. When it ends, we use the combo asterisk forward slash
 */

识别参数和返回类型时,请使用@字符:

/**
 * method add2 takes an integer and adds
 * 2 to it. It then returns the new integer
 *
 * @param someInt    the integer we will add 2 to
 * @return integer   the new integer after 2 was added
 */
public int add2(int someInt) {
    int integer = someInt + 2;
    return integer;
}