eclipse 代碼清理 代碼格式化 代碼注釋

來源:互聯網
上載者:User

標籤: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,大家可以上網上搜尋一下。

一個現在公司的模版:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.