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,并保存 如图:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值