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

Bug 367893

Summary: Code formatter should allow indenting wrapped lines differently than new blocks
Product: [Eclipse Project] JDT Reporter: Glenview Jeff <junk>
Component: CoreAssignee: JDT Core Triaged <jdt-core-triaged>
Status: NEW --- QA Contact: Ayushman Jain <amj87.iitr>
Severity: enhancement    
Priority: P3 CC: amj87.iitr, daniel_megert
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
code snippet
none
formatter prefs none

Description Glenview Jeff CLA 2012-01-04 15:54:08 EST
Build Identifier: 20100917-0705

I like to format my code like this:

void someFunction() {
   normalLine();
   reallyLongLineThatNeedsToBeWrapped(
    OnlyIndentOneSpaceHere = true);
   normalLine();
}

But from my experimenting with Eclipse's source formatting, it seems that you can't specify wrapped line indentation independently from new block indentation.

Reproducible: Always
Comment 1 Ayushman Jain CLA 2012-01-06 10:47:34 EST
In the Formatter preferences, try this:
In Indentation tab, specify the indentation policy as "mixed", and check the box that says "Use spaces to indent wrapped lines". Then in "Line wrapping" tab, select  Function calls>Arguments, and then wrapping policy - wrap where necessary, indentation = indent by one.

This will indent the arguments inside the long method call starting from one space, which you want. Let me know if this works for you.
Comment 2 Glenview Jeff CLA 2012-01-06 11:09:45 EST
Thanks very much Ayushman, but this does not appear to work when I tried it on Indigo 20110916-0149.  

After following your instructions, if I set indentation size to 3 and tab size to 3 on the indentation tab, the Function calls>Arguments preview looks like this:

/**
 * Arguments
 */
class Example {
	void foo() {
		Other.bar(
		   100,
		   nested(200, 300, 400, 500, 600,
		      700, 800, 900));
	}
}

And if I change indentation size to 1 and tab size to 3 on the indentation tab, the Function calls>Arguments preview looks like this:

/**
 * Arguments
 */
class Example {
 void foo() {
  Other.bar(
	100,
	nested(200, 300, 400, 500, 600, 700,
	 800, 900));
 }
}
Comment 3 Ayushman Jain CLA 2012-01-06 11:15:41 EST
(In reply to comment #2)
> Thanks very much Ayushman, but this does not appear to work when I tried it on
> Indigo 20110916-0149.  

Sorry I forgot one step, set the "indentation size" in the "indentation" tab to 1. Now try. :)
Please try formatting your code too, instead of just the preview. Thanks.
Comment 4 Glenview Jeff CLA 2012-01-06 14:23:27 EST
Thanks again, but are you implying that you believe the preview window is broken?  Is there a bug report for that?

You must not have read the complete text of my response.  I had already explained that I set the indentation size to 1 and kept the tab size 3.

Here is some random code formatted with these settings that show the (incorrect) output.  It matches the preview window.

 public void launchMethodInsideLoadingDialog(Activity anActivity, Handler aHandler,
  int aDialogIdentifier) {
  myActivity = anActivity;
  myHandler = aHandler;
  myDialogIdentifier = aDialogIdentifier;

  Thread loadingThread = new Thread() {
   @Override
   public void run() {
    myHandler.post(new Runnable() {
...
Comment 5 Glenview Jeff CLA 2012-01-07 09:20:47 EST
Ayushman, if you wouldn't mind pasting the code after formatting into a comment on this issue so I can see that you did, in fact, come up with some combination of formatting options that accomplishes the formatting I showed, I'd appreciate it.  You could use the standard code shown in the preferences:

/**
 * Arguments
 */
class Example {
    void foo() {
        Other.bar(
           100,
           nested(200, 300, 400, 500, 600,
              700, 800, 900));
    }
}
Comment 6 Ayushman Jain CLA 2012-01-09 03:25:32 EST
Created attachment 209185 [details]
code snippet
Comment 7 Ayushman Jain CLA 2012-01-09 03:27:04 EST
Created attachment 209186 [details]
formatter prefs

Use these preferences to format the above snippet. This indents the wrapped line to one space after the starting of the method call in the line before. 
I hope this is what you want.
Comment 8 Ayushman Jain CLA 2012-01-09 03:46:34 EST
Sorry I think I now understand your problem. You want to specify the line wrapping indentation NOT in terms of "number of indents" as is currently the case, but in terms of "number of spaces", which may be different from the indentation size. Yes, this is currently not supported, so I'll keep the bug open. Thanks!