Bug 164093 - [formatter] Proper indentation-option for method arguments and qualified invocations still missing
Summary: [formatter] Proper indentation-option for method arguments and qualified invo...
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement with 1 vote (vote)
Target Milestone: 4.7 M2   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard: To be verified for 4.7 M2
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-10 07:08 EST by Michael Moser CLA
Modified: 2016-09-13 02:09 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Moser CLA 2006-11-10 07:08:08 EST
While the eclipse JDT code formatter is definitely excellent and has gone a *long* way there are still a few things that I can not tweak to my liking, esp. re. line wrapping:

1.) Method arguments:

I still miss an option that allows me to wrap all but the first argument,
i.e. even if a line is too long I would like to see:

// max. length, say, here ---| 
    int someLongMethodName(int foo,  // (1)
                           boolean bar,  // (2)
                           someType yetAnotherArg) {
        ...
    }

Remarks:
(1) the 1st arg should always remain with the method name even if it exceeds 
    the max. line length
(2) all following lines are wrapped and "indented on column", again not 
    mattering whether they exceed the max. line length or not.

The closest approach I was able to so far yields:
----------
    ...
    int someLongMethodName(
                           int foo,
                           boolean bar,
                           someType yetAnotherArg) {
        ...
    }
    ...
----------
but I *hate* that linebreak for the first argument. The first arg. should remain on the same line!


Similar for the qualified method invocation. I don't see the point in the following formatting (which is what I get now):

----------
    ...
   // max. length, say, here ------------------| 
   someIdentifier(someArg).someFieldName
                                        .someMethodName(
                                                        foo, 
                                                        bar)
                                                            .otherMethod(arg0,
                                                                         arg1);
    ...
----------
                                                    

That should either be:
----------
    ...
   someIdentifier(someArgHere).someFieldName
                              .someMethodName(foo, 
                                              bar)
                              .otherMethod(arg0, arg1);
   ...
----------
   (i.e. indenting all on the first qualification-'.' and wrapping args if 
    necessary)

or:
----------
   ...
   someIdentifier(someArg).someFieldName.someMethodName(foo, 
                                                        bar).someMethod(arg0, 
                                                                        arg1);
   ...
----------
                                                            
   (i.e. ignoring the max. line length for the qualifications and only wrapping 
    the arguments, but those in the style described above).


Michael
Comment 1 Olivier Thomann CLA 2006-11-17 15:18:25 EST

*** This bug has been marked as a duplicate of 59891 ***
Comment 2 Frederic Fusier CLA 2010-04-23 06:16:02 EDT
This issue will be considered separately from bug 59891.
Comment 3 Frederic Fusier CLA 2010-04-23 06:17:02 EDT
Hence reopen...
Comment 4 Mateusz Matela CLA 2016-09-08 15:40:28 EDT
Looks like this task is about "Wrap all elements, except first if not necessary" wrapping policy, which was added a long time ago.
Comment 5 Sasikanth Bharadwaj CLA 2016-09-13 02:09:46 EDT
Verified for 4.7 M2 using I20160912-2000 build. Just one observation though - the policy gives different results for MethodDeclarations and qualified invocations, so formatting the example below with the line wrapping policy set to "Wrap all elements, except first if not necessary" , the declaration looks as expected but the invocation doesn't have all arguments wrapped.

public class Test {
	Test t = new Test();

	public	void
			someMethodDeclarationWithAVeryLongNameThatExceedsLineLength(int first,
																		boolean second,
																		Runnable third) {
		//
	}

	public void foo() {
		if (true) {
			this.t.someMethodDeclarationWithAVeryLongNameThatExceedsLineLength(
				0, false, () -> {
				});
		}
	}
}