自动添加大括号

时间:2013-11-16 23:20:05

标签: eclipse code-formatting curly-braces

如何配置eclipse以下述方式运行?

我有一些代码,如下:

for(int x: someList)
    if(x == y)
        doSomething();
    else if(x == z)
        doSomethingElse();
    else satisfiesCondition(x)
        x = someFunction(x);

我已经决定要在if(x == z)部分添加另一个声明。

我将光标放在行尾,如下所示:

    else if(x == z)█ //here
        doSomethingElse();█ //or here

然后我按输入 / return ,它会自动为块添加大括号,如下所示:

for(int x: someList)
    if(x == y)
        doSomething();
    else if(x == z){
        █ //if it was at the end of the else
        doSomethingElse();
        █ //if it was at the end of the `doSomethingElse();` statement
    } else
        x = someFunction(x);

然后,我想在for块的末尾添加一些东西,所以我把光标放在这里:

        x = someFunction(x);
█

我按标签,它会这样做:

for(int x: someList){
    if(x == y)
        doSomething();
    else if(x == z){
        doSomethingElse();
        doSomeThirdThing();
    } else
        x = someFunction(x);
    █
}

然后,我决定我实际上想要将语句添加到else块,而不是for块,所以我再次按 tab ,它会移动大括号,所以就像这样:

for(int x: someList)
    if(x == y)
        doSomething();
    else if(x == z){
        doSomethingElse();
        doSomeThirdThing();
    } else {
        x = someFunction(x);
        █
    }

0 个答案:

没有答案