`
jhyimu2005
  • 浏览: 181067 次
  • 性别: Icon_minigender_2
  • 来自: 苏州
社区版块
存档分类
最新评论

在MyEclipse中如何做到代码的注释规则是一致的

阅读更多
我们的一个团队在开发一个项目时,遇到的问题是,每个人的注释格式都是不同的,例如函数头的注释类的注释等;下面是我们项目中实施的办法,我认为很值得借鉴,所以贴过来分享一下。


=================================================================================================
1. 类的版权注释格式及设置步骤方式:
=================================================================================================
Eclipse -> Window -> Preferences -> Java -> Code Style -> Code Templates -> Code  -> New Java files  -> Edit ->

把其中的内容修改为:

/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
${package_declaration}

${typecomment}
${type_declaration}


=================================================================================================
2.类的注释格式及设置步骤如下:
=================================================================================================
Eclipse -> Window -> Preferences -> Java -> Code Style -> Code Templates -> Comments -> Types -> Edit ->把注释格式设置为:

/**
* This class is used for ...
*
* @version
*       1.0, ${date} ${time}
* @author  Jiang Haiying
*/

-> OK 设置完毕。

把@author改为自己的名字拼音即可. 自动生成的代码如下:

/**
* This class is used for ...
*
* @version  1.0, Apr 22, 2010 10:05:00 AM
* @author  Jiang Haiying
*/

若有需要参考别的类或方法时可以加上@see标注,例如:

/**
* This class is used for ...
*
* @version  1.0, Apr 22, 2010 10:05:00 AM
* @author Jiang Haiying
* @see com.founder.mcpm.crt.dao.IBatchCompoundAnalysisDAO
*/

在生成的JavaDoc中会生成 ” 另请参见com.founder.mcpm.crt.dao.IBatchCompoundAnalysisDAO“ 的链接。

  =================================================================================================
3.类的方法注释格式设置方式:
  =================================================================================================

Eclipse -> Window -> Preferences -> Java -> Code Style -> Code Templates -> Comments -> Methods -> Edit ->把注释格式设置为:

/**
* ${tags}
* @author Jiang Haiying
*/

把 @author 修改为自己的品拼音名字,生成的格式如下:

  /**
* @param value
* @return
* @throws Exception
* @author Jiang Haiying
*/
public String add(String value)  throws Exception {
  ....



=================================================================================================
4.注意事项
=================================================================================================
   <a>.对已经存在的类,若没有版权声明注释要加上版权注释。
   <b>.若对已有的类修改或增强功能,在 @author 之后再添加自己的名字并用英文逗号隔开。
      例如:
/**
* This class is used for ...
*
* @version 1.0, Apr 22, 2010 10:05:00 AM
* @author Jiang Haiying, Lisa
*/

<c>.当创建新的Class时,把Generate comments选中,Eclipse会自动生成类的版权注释及类的注释,否则不会生成(需要手工修改)。

=================================================================================================
5.  接口及实现类的注释样例代码
=================================================================================================
================
接口
================
   /**
* Gets total count of rows by sql string.
*
* @param sql  the sql string is the filter and sort condition.
* @return return 0 if there is no data.
* @throws DAOException if it occurs an error, it will throw a DAOException exception.
* @author Jiang Haiying
*/
Integer getTotalRowCount(String sql) throws DAOException;
================
实现类
================
/*
* @see com.founder.bcimp.core.dao.IBCIMPUserDAO#getTotalRowCount(java.lang.String)
*/
@Override
public Integer getTotalRowCount(String sql) throws DAOException {

return null;
}

注意:
   方法异常签名时,在@throws 之后加上异常类型 DAOException
    
       如: @throws DAOException  .......



 
   


   
   
分享到:
评论
2 楼 minikale 2012-03-28  
mark....
1 楼 ba1du 2010-09-21  
:oops:

相关推荐

Global site tag (gtag.js) - Google Analytics