Skip to main content



      Home
Home » Newcomers » Newcomers » Java formatter inserts unwanted newline when wrapping expressions
Java formatter inserts unwanted newline when wrapping expressions [message #521040] Tue, 16 March 2010 06:12 Go to next message
Eclipse UserFriend
In Preferences->Java->Code Style->Formatter in the latest version of Eclipse, I have the following settings under the Line Wrapping tab:

Maximum line width: 100
Default indentation for wrapped lines: 0
Default indentation for array initializers: 0
Never join lines: [unchecked]
Force split: [unchecked]

In the Expressions section, I have ...

Line wrapping policy: Wrap only when necessary
Indentation policy: Indent on column

In this case, the example shows up as follows:

int sum =
          100 + 200 + 300 + 400
          + 500 + 600 + 700
          + 800;

However, I'd like it to look like this (no newline between the equal sign and "100"):

int sum = 100 + 200 + 300 + 400
          + 500 + 600 + 700
          + 800;

Note that there is enough whitespace in the example for "100" to appear on the same line as the equal sign.

How can I configure these Formatter settings so that there is no extra newline after the equal sign in cases like this?

Thanks in advance.


[Updated on: Tue, 16 March 2010 06:14] by Moderator

Re: Java formatter inserts unwanted newline when wrapping expressions [message #521069 is a reply to message #521040] Tue, 16 March 2010 07:47 Go to previous messageGo to next message
Eclipse UserFriend
Play around with Window -> Preferences -> Java -> Code Style ->
Formatter and you'll soon figure out how to eliminate the newline. You
can modify the formatting and save as your own. Once satisfied, you can
export them to a preferences file you can take with you and import into
another project, workspace, computer, etc.



On 3/16/2010 4:12 AM, HippoMan wrote:
> In Preferences->Java->Code Style->Formatter in the latest version of
> Eclipse, I have the following settings under the Line Wrapping tab:
>
> Maximum line width: 100
> Default indentation for wrapped lines: 0
> Default indentation for array initializers: 0
> Never join lines: [unchecked]
> Force split: [unchecked]
>
> In the Expressions section, I have ...
>
> Line wrapping policy: Wrap only when necessary
> Indentation policy: Indent on column
>
> In this case, the example shows up as follows:
>
>
> int sum =
> 100 + 200 + 300 + 400
> + 500 + 600 + 700
> + 800;
>
> However, I'd like it to look like this (no newline between the equal
> sign and "100"):
>
>
> int sum = 100 + 200 + 300 + 400
> + 500 + 600 + 700
> + 800;
>
> Note that there is enough space before the "100" in the example for it
> to appear on the same line as the equal sign.
>
> How can I configure these Formatter settings so that there is no extra
> newline after the equal sign in cases like this?
>
> Thanks in advance.
>
>
>
Re: Java formatter inserts unwanted newline when wrapping expressions [message #521335 is a reply to message #521069] Wed, 17 March 2010 06:20 Go to previous messageGo to next message
Eclipse UserFriend
Russell Bateman wrote on Tue, 16 March 2010 07:47
Play around with Window -> Preferences -> Java -> Code Style ->
Formatter and you'll soon figure out how to eliminate the newline. You
can modify the formatting and save as your own. Once satisfied, you can
export them to a preferences file you can take with you and import into
another project, workspace, computer, etc.
Thank you, but please re-read my initial message. In the very first line of that message, I stated that I am already using Preferences->Java->Code Style->Formatter.

As I mentioned, the extra newline I'm talking about appears in the Expressions section of the Line Wrapping tab.

The example I am showing in my previous message came right from that Expressions section, and there doesn't appear to be any way to remove that newline given the options that are presented to me.

That is what prompted my question here.

Am I out of luck? Is there no setting in Formatter or elsewhere which I can use to remove that newline?

Thanks again in advance.

[Updated on: Wed, 17 March 2010 06:21] by Moderator

Re: Java formatter inserts unwanted newline when wrapping expressions [message #521397 is a reply to message #521335] Wed, 17 March 2010 09:38 Go to previous message
Eclipse UserFriend
Yes, by the time I reached a conclusion I had spaced that you were in
the right place.

In specific cases such as this, there are alignment options that force
the expression to a new line; it is not aided by an explicit deny
newline setting among the many options. I remember that, for the
formatting in question, I specifically chose against some of the options
precisely because of the ugly forced newline.



On 3/17/2010 4:20 AM, HippoMan wrote:
> Russell Bateman wrote on Tue, 16 March 2010 07:47
>> Play around with Window -> Preferences -> Java -> Code Style ->
>> Formatter and you'll soon figure out how to eliminate the newline. You
>> can modify the formatting and save as your own. Once satisfied, you
>> can export them to a preferences file you can take with you and import
>> into another project, workspace, computer, etc.
>
> Thank you, but please re-read my initial message. In the very first line
> of that message, I stated that I am already using
> Preferences->Java->Code Style->Formatter.
>
> As I mentioned, the extra newline I'm talking about appears in the
> Expressions section of the Line Wrapping tab.
>
> The example I am showing in my previous message came right from that
> Expressions section, and there doesn't appear to be any way to remove
> that newline given the options that are presented to me.
>
> That is what prompted my question here.
>
> Am I out of luck? Is there no setting in Formatter or elsewhere which I
> can use to remove that newline?
>
> Thanks again in advance.
>
>
Previous Topic:Project feature request
Next Topic:Problems in Sparc Solaris 10
Goto Forum:
  


Current Time: Fri Nov 07 03:46:22 EST 2025

Powered by FUDForum. Page generated in 0.10469 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top