Bug 79068

Summary: [formatter] Need option to control line wrapping before/after operators
Product: [Eclipse Project] JDT Reporter: Mark Drew <eclipse>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: hcs333, ian, mlists
Version: 3.1   
Target Milestone: 3.3 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 183685    

Description Mark Drew CLA 2004-11-19 08:47:46 EST
need option to control line wrapping before/after operators

It would be nice if there was a code formatting option (that could ideally be
referenced by the wrap java strings feature of the java editor), to set wrapping
before or after operators.  

One example of where this option would apply is when formatting code that looks
like this:

    if (a.getSomeBooleanValue() && b.getSomeOtherBooleanValue() &&
        c.getYetAnotherBooleanValue()) {
      doSomething();
    }

The code formatter currently always changes the code above to the code below,
and there's no option (at least not that I've found) to control this behavior.

    if (a.getSomeBooleanValue() && b.getSomeOtherBooleanValue()
        && c.getYetAnotherBooleanValue()) {
      doSomething();
    }

Note also that the wrap java strings feature and the code formatter are
inconsistent with respect to this behavior.  Specifically, if I use the wrap
java strings feature, I get this:

    System.out.println("asdlfj asfl;kj saflksj fl;ksaj flsjd f;asl fsjdf" +
        "sdflkjsdfl;jaslfdjsdlfkj  sdflk sdjflks f");

Now, when I format the code using the code formatter, I get

    System.out.println("asdlfj asfl;kj saflksj fl;ksaj flsjd f;asl fsjdf"
                       + "sdflkjsdfl;jaslfdjsdlfkj  sdflk sdjflks f");

Note that one wraps before the + operator and the other wraps after the plus
operator (not to mention the inconsistent indentation).
Comment 1 Philipe Mulet CLA 2005-04-07 09:44:27 EDT
Deferring post 3.1
Comment 2 Olivier Thomann CLA 2005-11-10 12:29:02 EST
Reopen
Comment 3 Olivier Thomann CLA 2005-11-10 12:29:52 EST
*** Bug 115210 has been marked as a duplicate of this bug. ***
Comment 4 Olivier Thomann CLA 2007-03-15 22:09:13 EDT
I would add the following constant:
/**
 * <pre>
 * FORMATTER / Option to wrap before the binary operator
 *     - option id:         "org.eclipse.jdt.core.formatter.wrap after the binary operator"
 *     - possible values:   { TRUE, FALSE }
 *     - default:           FALSE
 * </pre>
 * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION} is set.
 * @see #TRUE
 * @see #FALSE
 * @since 3.3
 */
public static final String FORMATTER_WRAP_BEFORE_BINARY_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_binary_operator"; //$NON-NLS-1$

One of the two cases described below won't be preserved.
Comment 5 Philipe Mulet CLA 2007-03-16 13:06:04 EDT
+1
Comment 6 Olivier Thomann CLA 2007-03-19 14:29:45 EDT
The constant has been added for 3.3M6 and the implementation will be provided post M6.
Comment 7 Olivier Thomann CLA 2007-04-23 19:53:24 EDT
Released for 3.3M7.
Comment 8 Olivier Thomann CLA 2007-04-23 20:08:35 EDT
Added regression test org.eclipse.jdt.core.tests.formatter.FormatterRegressionTests.test661()
Comment 9 Maxime Daniel CLA 2007-04-27 07:43:01 EDT
Verified for 3.3 M7 using build I20070427-0010.
Comment 10 Mateusz Matela CLA 2016-01-14 17:12:12 EST
*** Bug 48476 has been marked as a duplicate of this bug. ***