Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 247730

Summary: [formatter] operator line wrapping preferences do not respect assignment operator
Product: [Eclipse Project] JDT Reporter: Brandon Yarbrough <brandonY>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P5 CC: jarthana, mateusz.matela, todd_richmond
Version: 3.4   
Target Milestone: 4.5 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Brandon Yarbrough CLA 2008-09-17 16:47:19 EDT
Build ID: I20080617-2000

Steps To Reproduce:
1. Go to Preferences > Java > Code Style > Formatter.
2. Choose "Java Conventions [built-in]".
3. Click OK.
4. Write some code that would line wrap around the assignment operator (perhaps use a very long variable name).
5. Note that the line wrapped AFTER the assignment operator and not beforehand.
6. There is no option to change this behavior.

More information:
The Java formatter has excellent line wrapping support with regards to operators (as documented in the Java formatting spec:
http://java.sun.com/docs/codeconv/html/CodeConventions.doc3.html#248

However, for some reason, it does not handle the assignment operator in addition to all the other operators.
Comment 1 Frederic Fusier CLA 2008-09-18 04:19:44 EDT
A code snippet showing the issue would be helpful...
Comment 2 Todd Richmond CLA 2014-09-24 12:55:34 EDT
Here is a sample that breaks on both normal assignment and annotations using Eclipse Java code cleanup. My settings are to wrap at column 80 and line break when necessary. The variable declaration should break after a "+" (I have it set to break after an operator).

Also, manually adding a CR after the = causes the next line to begin on column 20 instead of a single 4 char indent. Sames goes for the annotation

I've tried every combination of wrap and extra options possible and cannot get this to format correctly


import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;

public class EclipseFormatTest {
    // no wrapping (bugzilla breaks comment)
    public int a23456789012345678901234567890 = 1234567890 + 1234567890 + 1234567890;

    // line should keep message = on 1st line
    @ApiResponses(value = { @ApiResponse(code = 400,
        message = "invalid start or count supplied") })
    public void func() {}
}


The results should be


public class EclipseFormatTest {
    public int a23456789012345678901234567890 = 1234567890 + 1234567890 +
        1234567890;

    @ApiResponses(value = { @ApiResponse(code = 400, message =
        "invalid start or count supplied") })
    public void func() {}
}
Comment 3 Mateusz Matela CLA 2018-11-11 17:17:27 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***
Comment 4 Jay Arthanareeswaran CLA 2018-11-22 03:53:58 EST
Verified for 4.10 M3 with build id I20181121-1800