標籤:style http java 使用 strong 檔案
Code Style包括兩個方面:代碼清理,代碼正常化。代碼清理可以參考:
http://www.ibm.com/developerworks/cn/opensource/os-eclipse-clean/
代碼清理過程:
進入eclipse菜單: Window > Preferences > Java > Code Style > Clean Up,點擊介面上方的Import,在彈出框中選擇位於eclipse安裝
路徑下的eclipse/cleanup-profile.xml,點擊
開啟,點擊右下角的 Apply 使其生效。
代碼格式化過程:
進入eclipse菜單: Window > Preferences > Java > Code Style > Formatter,使用類似上述的方法匯入eclipse/formatter-profile.xml,並
使其生效。
設定代碼格式化的實現時間,一般為當儲存的時候自動格式化:
進入eclipse菜單: Window > Preferences > Java > Editor > Save Actions,勾選上Perform the selected actions on save 下的Format
source code,並選擇 Format all lines,勾選上Organize imports,點擊右下角的Apply 使其生效。
在eclipse中添加註釋
(1)在方法上面添加註釋:
在方法的上面一行輸/**,然後斷行符號。
(2)在檔案頭添加註釋:
用快速鍵 Alt+Shift+J。添加的注釋格式是可以修改的,通過菜單 Window->Preference 開啟參數設定面板,然後選擇:Java ->
Code Style -> Code Templates,在右側選擇Comments,選擇其中的Types項,然後選右邊的"Edit",進入編輯模式。進入編輯模
式後就可以自訂注釋了。另外可以插入一些變數,如年、日期等等。最後,確保 Code -> New Java files 中
有:"${filecomment}"。
如果沒有找到cleanup-profile.xml和formatter-profile.xml,大家可以上網上搜尋一下。
一個現在公司的模版: