2014-01-24 201 views
4

Eclipse允許您自定義代碼格式化程序並導出/導入它們。有沒有辦法讓我創建一個格式化程序,將它保存在源代碼控制中,並將某個屬性設置爲當您打開項目時自動加載到eclipse中的某個位置?Eclipse默認自定義格式化器

我們希望使用自定義格式器,但如果不能通過團隊自動配置它,則不能使用。我們不希望有人忘記導入格式化程序並最終使用另一個設置格式化代碼。只能想象這會造成一些不那麼有趣的衝突。

回答

3

右鍵單擊該項目,選擇「屬性」,然後選擇「Java - > Formatter」,選中「啓用項目特定設置」,然後根據需要配置格式器。整個配置將保存在項目目錄中,您可以輕鬆將其置於版本控制之下。

2

正如閣下所說,您可以修改所使用的默認格式化程序,並將其保存到您的項目目錄中。具體來說,.settings文件夾指向兩個不同的文件:一個文件名爲org.eclipse.jdt.core.prefs,用於存儲特定的格式化指令,另一個名爲org.eclipse.jdt.ui.prefs的「指針」文件指向修改後的代碼格式化程序。

org.eclipse.jdt.core.prefs樣子:

eclipse.preferences.version=1 
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 
org.eclipse.jdt.core.compiler.compliance=1.7 
org.eclipse.jdt.core.compiler.debug.lineNumber=generate 
org.eclipse.jdt.core.compiler.debug.localVariable=generate 
org.eclipse.jdt.core.compiler.debug.sourceFile=generate 
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 
(etc) 

org.eclipse.jdt.ui.prefs樣子:

eclipse.preferences.version=1 
formatter_profile=_Eclipse [modified] 
formatter_settings_version=12 

注:我叫我修改格式 「修改」(這似乎是適當的)。我使用開普勒,所以你的里程可能會有所不同,在禁止的情況下無效,請參閱經銷商的詳細信息...

確保將.settings文件夾以及這兩個文件保存到您的SCM系統。項目文件,它將位於根文件夾中)。

玩得開心!