Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line wrapping in Eclipse Java formatter

I'm trying to configure the Java code formatter to have a compact formatting. I've set the policy to "Wrap where necessary", and maximum line width to 80, but either it wraps where it shouldn't, or it doesn't wrap where it should... Here is an example of what I get:

// -------------------------------------------------------------------------80->
public class FormatterTest {
    void test() {
        int i, a = 1, b = 1, c = 1, d = 1;
        i =
                a
                        * b
                        * c
                        * d
                        * (100000000 + 100000000 + 100000000 + 100000000
                                + 100000000 + 100000000 + 100000000 + 100000000 + 100000000);
    }
}
// -------------------------------------------------------------------------80->

And what I'd like:

    i = a * b * c * d * (100000000 + 100000000 + 100000000 + 100000000
            + 100000000 + 100000000 + 100000000 + 100000000 + 100000000);

Thanks for your help.

like image 347
Patrick Avatar asked Nov 20 '25 17:11

Patrick


1 Answers

You can suppress the formatting if you add an // at the end of the line:

i = a * b * c * d * (100000000 + 100000000 + 100000000 + 100000000 //
        + 100000000 + 100000000 + 100000000 + 100000000 + 100000000);
like image 153
Kai Avatar answered Nov 22 '25 08:11

Kai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!