简体   繁体   English

如何在Java中添加评论框?

[英]How do you add a comment box in java?

I am working on a project in java for class and I need to add a comment box above each of my methods explaining what each method does. 我正在用Java开发一个类的项目,我需要在每个方法上方添加一个注释框,以说明每个方法的作用。 It's supposed to look like this: 应该看起来像这样:

***** *** ** ** ** (asterisk line) ************************************************************************* *@param ***** *** ** ** **(星号线)******************************** ********************************************** * @ param

* *

**** *** ** ** ** **(another line) ********************************************************************* **** *** ** ** **(另一行)******************************* ******************************************

I am using eclipse and I know there is a shortcut that makes this box but I can't seem to remember it or find it on the web... 我正在使用eclipse,我知道有一个快捷方式可以使此框生效,但是我似乎无法记住它或在网上找到它。

Goto eclipse > windows > preference > java > templates 转到Eclipse> Windows>首选项> Java>模板

click NEW now give name for your pattern and add description and provide below pattern 单击“ 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
*           ==============  ===========     ================================================
*/

use context as java and now final show down create any class and than add method before introducing a method just start typing the name of the above template and than press CTRL+SPACE and select your template and boom your method is read for description. 使用上下文作为java ,现在最终展示创建任何类,然后在介绍方法之前添加方法,只需开始输入上述模板的名称,然后按CTRL + SPACE并选择模板,然后读取您的方法进行描述。

在主菜单中,窗口->首选项在左侧的树中,Java->代码样式-> CodeTemplates在右侧面板上,选择注释->方法,然后在右下方的文本区域中打印图案

It is good practice to use JavaDoc to document each of your methods and explain what they do, their parameters, what they return, and any exception it may throw. 优良作法是使用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
 */

When identifying parameters and return types, use the @ character: 标识参数和返回类型时,请使用@字符:

/**
 * 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;
}

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

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