設置注釋模板的入口:
Window-<Preference-<Java-<CodeStyle-<Code Template 然后展開Comments節點就是所有需設置注釋的元素。現就每一個元素逐一介紹:
文件(Files)注釋標簽:
/**
* Copyright © ${year}公司名字. All rights reserved.
*
* @Title: ${file_name}
* @Prject: ${project_name}
* @Package: ${package_name}
* @Description: ${todo}
* @author: ${user}
* @date: ${date} ${time}
* @version: V1.0
*/
類型(Types)注釋標簽(類的注釋):
/**
* @ClassName: ${type_name}
* @Description: ${todo}
* @author: ${user}
* @date: ${date} ${time}
* ${tags}
*/
字段(Fields)注釋標簽:
/**
* @fieldName: ${field}
* @fieldType: ${field_type}
* @Description: ${todo}
*/
構造函數標簽:
/**
* @Title:${enclosing_type}
* @Description:${todo}
* ${tags}
*/
方法(Constructor & Methods)標簽:
/**
* @Title: ${enclosing_method}
* @Description: ${todo}
* ${tags}
* @return: ${return_type}
*/
覆蓋方法(Overriding Methods)標簽:
/* (non Javadoc)
* @Title: ${enclosing_method}
* @Description: ${todo}
* ${tags}
* ${see_to_overridden}
*/
代表方法(Delegate Methods)標簽:
/**
* ${tags}
* ${see_to_target}
*/
getter方法標簽:
/**
* @return the ${bare_field_name}
*/
setter方法標簽:
/**
* @param ${param} the ${bare_field_name} to set
*/
或者可以從網上下載配置好的.xml文件導入也可以。下載請點擊我!
PS:在按照上面的方法設置后,一定要到windows->Preferences->general->Content Types,右側Context Types樹,點開Text,選擇Java Source File,在下面的Default encoding輸入框中輸入UTF-8,點Update,則設置Java文件編碼為UTF-8,否則會出現字符編碼的問題。
經過如上的設置后,就可以使用快捷鍵Alt+Shift+J來快速生成文檔的注釋了。使用方法如下:
文件頭注釋:
方法、類、字段等注釋: