Bug 90238 - [formatter] Code Formatter Doesn't Wrap Binary Expression
Summary: [formatter] Code Formatter Doesn't Wrap Binary Expression
Status: CLOSED DUPLICATE of bug 303519
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Windows XP
: P5 normal with 6 votes (vote)
Target Milestone: 4.5   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-04 19:51 EDT by David McLeod CLA
Modified: 2015-12-25 19:18 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David McLeod CLA 2005-04-04 19:51:06 EDT
I have the following code in my class:

    private boolean shouldStop()
    {
        synchronized (s_monitor)
        {
            return ((s_fatalFailures > s_fatalFailureLimit) || 
((s_nonFatalFailureLimit > 0) && (s_nonFatalFailures > 
s_nonFatalFailureLimit)));
        }
    }

The variables s_fatalFailures, s_fatalFailureLimit, s_nonFatalFailures, and 
s_nonFatalFailureLimit are all ints.  The return statement, unformatted, is 
145 characters long.

I am using Eclipse 3.0.2.

I have set up my code formatter to allow for a line width of 80 characters, 
and I have experimented with various settings on the Binary Expressions Line 
Wrapping page, and there doesn't seem to be a setting where Eclipse will 
recognize that my "return" statement is too long.  Eclipse doesn't seem to 
want to break this line anywhere so that it wraps to fit logically within the 
80-character limit.

Even if I manually format the line the way I want, if I subsequently use the 
Ctrl-Shift-F option to format, Eclipse reverts the return statement to a 
single line that is 145 characters long.
Comment 1 Trevor Robinson CLA 2005-04-05 15:44:00 EDT
I have the same problem with various types of statements. Here's an example that
Eclipse will not wrap (i.e. it puts everything on one line) regardless of my
settings (even using the Java Conventions and Eclipse 2.1 built-in profiles):

if (!((reqPkt instanceof RdWrSizedPacket && ((RdWrSizedPacket) reqPkt).compat ==
Bit.ONE) || (reqPkt instanceof AtomicRMWPacket && ((AtomicRMWPacket)
reqPkt).compat == Bit.ONE)))
{
}

In my particular file, this line is also indented 24 spaces, making the total
line length 202. It should wrap at 80.

This bug is similar to bug 76633.
Comment 2 Trevor Robinson CLA 2005-04-05 16:17:22 EDT
Oh, and I'm running I20050331-1200.
Comment 3 Philipe Mulet CLA 2005-04-07 08:01:37 EDT
Deferring post 3.1
Comment 4 Olivier Thomann CLA 2005-08-31 10:50:18 EDT
Reopening.
Comment 5 Olivier Thomann CLA 2005-09-01 10:51:35 EDT
The problem comes from the surrounding parenthesized expression.
I am investigating.
Comment 6 Olivier Thomann CLA 2005-11-10 11:24:32 EST
*** Bug 115210 has been marked as a duplicate of this bug. ***
Comment 7 Dennis Klemann CLA 2005-11-18 10:16:40 EST
Are there any news concerning this bug?

As I've already written in the description of 93433:
"This is rather annoying, because the code gets "QAed" with Checkstyle, which 
always reports that the line is too long once I use the code formatting. :-("

I would be VERY glad if this bug was fixed.
Thanks in advance!
Comment 8 Olivier Thomann CLA 2005-11-18 10:20:56 EST
This will be done if we find some time to do it.
Patches are always welcome.
Comment 9 Dennis Klemann CLA 2005-12-06 17:28:21 EST
I can't promise, but I'll try to look into this.
Could you point me to the rough direction, code-wise? Thanks!

Cheers,
Dennis
Comment 10 Olivier Thomann CLA 2005-12-07 10:15:05 EST
You can look at the formatting of binary expression in this class:
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor
Or even better in this class:
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor2

The second one is used to format DOM/AST nodes. This is where we want to go for the future.
Comment 11 Frederic Fusier CLA 2008-08-18 08:06:47 EDT
Ownership has changed for the formatter, but I surely will not have enough time to fix your bug during the 3.5 development process, hence set its priority to P5.
Please provide a patch if you definitely need the bug to be fixed in this version and I'll have a look at it...
TIA
Comment 12 Mateusz Matela CLA 2015-12-25 19:18:15 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***