Reputation: 3759
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.
Upvotes: 3
Views: 3354
Reputation: 201
I managed to get it formatted in my Eclipse as follows, using the "Java Conventions [built-in]" formatter settings:
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));
}
}
For some reason, the brackets around the entire expression are essential. Without them, I get completely different formatting.
Hope this helps.
Upvotes: 0
Reputation: 195289
well in comment you said "expressions", there are different kind of expressions. check the screenshot. I think it (example codes by eclipse at right side) looks like what you want.
hope it is helpful.
EDIT
could you try
expressions-> Assignments :Do not wrap
Upvotes: 0
Reputation: 39651
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);
Upvotes: 1