开发者

Eclipse toggle comment indented

开发者 https://www.devze.com 2023-01-26 03:11 出处:网络
I have following code: public int doBam(int bam) { if(foo) { bam += 1; if(bar) { bam += 1; } } return bam; } I want to comment out the if(bar) ...

I have following code:

public int doBam(int bam) {
    if(foo) {
        bam += 1;
        if(bar) {
            bam += 1;
        }
    }
    return bam;
}

I want to comment out the if(bar) ...

When I do toggle comment in Eclipse 3.6 I will get this:

public in开发者_StackOverflow中文版t doBam(int bam) {
    if(foo) {
        bam += 1;
//        if(bar) {
//            bam += 1;
//        }
    }
    return bam;
}

Can I make Eclipse to toggle comment like this instead?

public int doBam(int bam) {
    if(foo) {
        bam += 1;
        //if(bar) {
        //    bam += 1;
        //}
    }
    return bam;
}


Can I make Eclipse to toggle comment like this instead?

It's a three step process..

Step-1:- Select desired code.

if(bar) {
  bam += 1;
}

Step-2:- Hit Control + 7 OR Control + /

//    if(bar) {
//      bam += 1;
//    }

Step-3:- Hit Control + Shift + F

   // if(bar) {
   // bam += 1;
   // }

UPDATE

Also, when uncommenting, the Eclipse autoformatter does not restore the previous indentation

Like commenting, uncommenting is also three step process:-

  1. select
  2. Contorl + /
  3. Control + Shift + F

it applies it's own formatting rules instead.

You can change these formatting rules. Windows --> Preferences --> Java --> Code Style --> Formatter --> Edit --> Comments Tab.

Eclipse does not allow editing default built-in profile. Create new profile and inherit all the properties from built-in profile, then you can customize the newly created profile.


seems like a real solution for this is not going to happen in eclipse

https://bugs.eclipse.org/bugs/show_bug.cgi?id=321092


For the bold, though the Eclipse team doesn't want to include this behavior, the bug report mentioned includes patches that would allow anyone building Eclipse from source to add the behavior into their copy.


The question seems to be little outdated, but anyway.

Block of code can be nicely commented-out (starting at Eclipse 3.5) using column selection mode [1]. Just press Alt + Shift + A to switch to column mode, then select the code using arrows, type // and press Alt + Shift + A again to turn off column mode.

[1] How do I enable the column selection mode in Eclipse?


Select the code to be commented

  • For toggle comment press Cntrl + /
  • For block comments press Cntrl + Shift + /

Eclipse toggle comment indented

0

精彩评论

暂无评论...
验证码 换一张
取 消