Coding templates and formatters

原文地址:https://developer.connectopensource.org/display/CONNECTWIKI/Coding+templates+and+formatters

We make available code formatting templates for NetBeans and Eclipse, two IDEs the CONNECT development team uses. Community members are welcome to contribute templates for other IDEs.

NetBeans:

Download the NBFormatter.zip file.

Open Netbeans, and go to options -->Editor.

At the bottom left, click "Import", and then select the NBFormatter.zip file.  Restart NetBeans for changes to take effect.

For Eclipse:

  1. Download formatter.xml
  2. Open Eclipse
  3. Go to Window -> Preferences
  4. Under General -> Editors -> Text Editors, check "Show print margin" and set "Print margin column" to 120
  5. Under Java -> Code Style -> Code Templates select "Automatically add comments for new methods and types
  6. Under Java -> Code Style -> Formatter import the file formatter.xml.
  7. Under  Java -> Compiler -> Errors/Warnings expand the Annotations  settings and set "Unhandled token in '@SuppressWarnings'" to Ignore
  8. Under  Web -> HTML Files -> Editor set the Line width to 120 and select  Indent using spaces, and set the indentation size to 4.
  9. Under  XML -> XML Files -> Editor set the Line width to 120 and select  Indent using spaces, and set the indentation size to 4.
  10. Under Ant -> Editor -> Formatter set the Max Line Width to 120 and unselect the use tab chars for spaces option.
  11. To  prevent Eclipse from suggesting obscure suggestions for common classes  (such as List), you can add the unused classes/packages to the list at  Java -> Appearance -> Type Filters.
  12. Under General --> Workspace and under "New text file line delimiter" select UNIX.

這個模板主要指定了以下幾條規範:

  • 120個字符換行
  • 4個空格(而非TAB)縮進
  • 花括弧位置採用K&R風格
  • 算數操作符前後加空格

 

Formatter 模版文件導入方法:

打開Reference, 通過 formatter 過濾找到 配置項,然後導入 yumihua_java_eclipse_formatter.xml 文件。

導入成功後請測試一下是否設置成功,可能每個獨立項目都需要導入,如果你能發現一次導入適用於所有項目的辦法,請更新此 wiki 頁面


在自動保存的時候格式化文件的辦法:

Window -> Preferences, 搜索 action, 找到 save action, 如圖:

3,勾選 perform the selected action on save,選擇 format source code, format all code,Organize imprt,並保存 如圖:

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章