Eclipse保存源碼添加自動動作選項
Eclipse提供自動源碼格式選項,并且組織輸入(刪除未使用的代碼)。你可以使用下面的這些快捷鍵進行操作。
Ctrl + Shift + F——源代碼格式
Ctrl + Shift + O——組織輸入并刪除未使用的代碼
代替手動調用這兩個函數,只需根據Eclipse自動格式和自動組織選項,可以隨時保存文件。
操作步驟,在Eclipse中進入Window -> Preferences -> Java -> Editor -> Save Actions,然后以選定的方式保存,最后檢查Format source code + Organize imports。
Additional actions:
Remove 'this' qualifier for non static field accesses
Remove 'this' qualifier for non static method accesses
Convert control statement bodies to block
Add final modifier to private fields
Add final modifier to method parameters
Add final modifier to local variables
Remove unused imports
Remove unused private methods
Remove unused private constructors
Remove unused private types
Remove unused private fields
Add missing '@Override' annotations
Add missing '@Override' annotations to implementations of interface methods
Add missing '@Deprecated' annotations
Remove unnecessary casts
Remove trailing white spaces on all lines