一、代碼自動格式化提高效率
如果在保存代碼時能自動格式化代碼,例如去掉沒有被引用的import類,並且按照格式模板格式化,那么既能提高代碼質量又能提高開發效率。
二、代碼格式化插件Save Actions
1.Save Actions的功能如下:
- Optimize imports
- Run on file save, shortcut, batch (or a combination)
- Run on multiple files by choosing a scope
- Reformat code (whole file or only changed text)
- Rearrange code (reorder methods, fields, etc.)
- Include / exclude files with regex support
- Works on any file type (Java, Python, XML, etc.)
- Uses a settings file per project you can commit
- Available keymaps and actions for activation
- Eclipse configuration file
.epf
support (Java IDE only) - Automatically fix Java inspections (Java IDEA only)
2.安裝Save Actions插件:
3.Save Actions默認沒有激活,需要激活:
三、使用阿里的代碼格式模板
阿里的代碼規范是開源的,編碼時如果遵循阿里的代碼規范,則可使用阿里的代碼模板。
1.先安裝Eclipse Code Formatter插件並安裝:
2.下載阿里代碼模板:
https://github.com/alibaba/p3c/tree/master/p3c-formatter
3.使用阿里代碼模板:
至此,就可以在保存Java代碼時自動按照阿里的代碼模板格式化代碼了。
end.