2013-10-21 40 views
0

我已經從Eclipse中導入了一個項目到IntelliJ中,我想配置代碼樣式設置。但是我在聲明數組時遇到了一個問題。IntelliJ中的代碼樣式設置(縮進)

月食格式格式化代碼如下:

@Before 
public void prepareData() throws Exception //NOPMD 
{ 
    LOG.info("Preparing setup data"); 
    new CoreBasicDataCreator().createEssentialData(null, null); 
    CatalogManager.getInstance().createEssentialData(Collections.EMPTY_MAP, null); 
    serviceLayerDataSetup.createJobPerformables(); 
    impExSystemSetup.createAutoImpexEssentialData(new SystemSetupContext(Collections.EMPTY_MAP, Type.ESSENTIAL, 
      CuppyConstants.EXTENSIONNAME)); 
    cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[] 
    { CuppyConstants.PARAM_BASICS_PLAYERS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 
    cuppySystemSetup.importWC2002(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_WC2002, new String[] 
    { CuppyConstants.PARAM_WC2002_SETUP, CuppyConstants.PARAM_WC2002_RESULTS_PRELIMINARIES, 
      CuppyConstants.PARAM_WC2002_RESULTS_FINALS, CuppyConstants.PARAM_WC2002_BETS_PRELIMINARIES, 
      CuppyConstants.PARAM_WC2002_BETS_FINALS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 

    LOG.info("Finished preparation of setup data"); 

    LOG.info("Preparing session"); 
    JaloSession.getCurrentSession().setUser(UserManager.getInstance().getUserByLogin("sternthaler")); 
    LOG.info("Finished preparation of session"); 
} 

和IntelliJ重新格式化代碼爲:

@Before 
public void prepareData() throws Exception //NOPMD 
{ 
    LOG.info("Preparing setup data"); 
    new CoreBasicDataCreator().createEssentialData(null, null); 
    CatalogManager.getInstance().createEssentialData(Collections.EMPTY_MAP, null); 
    serviceLayerDataSetup.createJobPerformables(); 
    impExSystemSetup.createAutoImpexEssentialData(new SystemSetupContext(Collections.EMPTY_MAP, Type.ESSENTIAL, 
      CuppyConstants.EXTENSIONNAME)); 
    cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[] 
      { CuppyConstants.PARAM_BASICS_PLAYERS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 
    cuppySystemSetup.importWC2002(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_WC2002, new String[] 
      { CuppyConstants.PARAM_WC2002_SETUP, CuppyConstants.PARAM_WC2002_RESULTS_PRELIMINARIES, 
        CuppyConstants.PARAM_WC2002_RESULTS_FINALS, CuppyConstants.PARAM_WC2002_BETS_PRELIMINARIES, 
        CuppyConstants.PARAM_WC2002_BETS_FINALS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 

    LOG.info("Finished preparation of setup data"); 

    LOG.info("Preparing session"); 
    JaloSession.getCurrentSession().setUser(UserManager.getInstance().getUserByLogin("sternthaler")); 
    LOG.info("Finished preparation of session"); 
} 

如果你是一個的IntelliJ用戶,您可以用這裏面的代碼示例發揮代碼風格編輯器。你 希望任何人能想出解決辦法:)

+0

你能描述intellij格式化有什麼問題嗎?這是件好事,你把代碼在這裏,但它會更好地形容它完全代替了「把工作做好」的問題... – zenbeni

+0

我不太知道如何來形容它。唯一的問題是這個新的線陣列標識(從這個例子看)。 我無法找到的IntelliJ相應參數來設置這個 – ZeDonDino

回答

1

你可以使用這個插件在理念:Eclipse Code Formatter

只要搜索和Preferences -> Plugins -> Browse Repositories(button)

+1

這是一個很好的建議,但我不認爲它回答是的OP終極問題。他正在IDEA中進行代碼格式化的特定配置。如果Eclipse格式文件是項目本身的一部分(在源代碼管理中),那麼您的建議就很好。但是,如果沒有這樣的文件存在並且OP希望對我們在IDEA中工作的所有項目使用這種類型的格式,那麼這種方法就沒有用處。 – Javaru

0

安裝它也許你應該只使用「保持格式化時」代碼樣式java中的「換行符」。

不是很漂亮,但有時處理不好的舊代碼的唯一方法(用空格和所有的...)。

在你的榜樣,你可以從你的方法調用中提取陣列(和其他變量)的聲明,這樣,也許你會得到相同的結果的Eclipse。另外,恕我直言,它可以讓你的代碼更容易閱讀,因爲實際上很難快速找出這個代碼正在做什麼。

+0

嗨,代碼本身並不重要。它只是從平臺本身的內部測試複製/粘貼:) 我會嘗試一下你寫的並回來給你 – ZeDonDino

1

如果我理解正確,你,你想這樣:

cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[] 
    {CuppyConstants.PARAM_BASICS_PLAYERS}), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 

格式化這樣

cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[] 
{CuppyConstants.PARAM_BASICS_PLAYERS}), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 

要做到這一點,你需要設置設置>代碼樣式>的Java>標籤和縮進>「的延續縮進」爲0。不過請注意,這將使所有包裝線齊平。我不確定那是否是你想要的。或者如果你只是想要它的特定代碼。如果是這樣,請你澄清一下。

還要注意的是,在IDEA 13(目前在beta/EAP)可以使用關閉格式化通過註釋的代碼段。 (此功能是通過IDEA-56995添加的)。這種標籤是可配置的,並且默認的值下面

// @formatter:off 
cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[] 
{CuppyConstants.PARAM_BASICS_PLAYERS}), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME)); 
// @formatter:on 

您可以輕鬆創建一個的環繞動態模板那些標記添加到代碼塊中。

+0

嗨,Continuation標識沒有幫助,因爲那時所有這些新的行將在相同的標識級別上。你會發現他們在我的展示代碼上有所創意。 – ZeDonDino

+0

因此,你是否希望任何數組聲明的開始括號,即使定義爲方法調用的參數,在下一行並與前一行相同?如果是這樣,那在IDEA中是不可能的。如果該設置存在,它將位於_Java> Wrapping and Braces> Array Initializer_中。我建議你打開[功能請求](http://youtrack.jetbrains.com/issues/IDEA)。有時候,代碼風格的請求很快就會實現。這一切都取決於[Denis](http://devnet.jetbrains.com/people/denis.zhdanov)(開發人員使用代碼樣式組件)在他的盤子上。 – Javaru

相關問題