Bug 15286 - Code formatter: long param lists and line wrapping
Summary: Code formatter: long param lists and line wrapping
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-05 13:34 EDT by Scott Rutledge CLA
Modified: 2003-10-13 10:14 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 Scott Rutledge CLA 2002-05-05 13:34:34 EDT
Given a list of method parameters that's longer than the maximum line length, the formatter 
places each paramter on it's own line.

Eg.

public void doSomething(String param1, 
String param2, String param3, String param4)

gets formatted into:

public void 
doSomething(
   String param1,
   String param2,
   String param3,
   String param4)

I'd 
prefer the minimum number of lines be used:

public void doSomething(String param1, String 
param2,
   String param3, String param4)

Since I'm sure some people prefer the current 
style, could we have an option to control how this is handled?
Comment 1 Scott Rutledge CLA 2002-05-05 13:35:26 EDT
Ok, so bugzilla formatted my formatting for me. Hope the message is still clear, though.
Comment 2 Erich Gamma CLA 2002-05-06 17:10:05 EDT
formatter is owned by JDT CORE
Comment 3 Philipe Mulet CLA 2002-05-06 18:56:19 EDT
Will consider post 2.0
Comment 4 Martin Möbius CLA 2002-06-11 04:46:13 EDT
quoting some examples from
Subject: When will the code formatter will abide to standard ?
From: (AHoma)
where I agree


    // 
    // Here is how I would format it (Sun's code converntions does not say)
    //    String[][] doubleList = {
    //            { "alfa", "beta" },
    //            { "alfa", "beta" },
    //            { "alfa", "beta" },
    //            { "alfa", "beta" },            
    //    };
    // 
    // Here is how Eclipse format it
    String[][] doubleList = { { "alfa", "beta" }, {
            "alfa", "beta" }, {
            "alfa", "beta" }, {
            "alfa", "beta" }, };

Comment 5 Bob Foster CLA 2002-07-16 02:16:59 EDT
Not sure Martin's comment is the same subject, but I agree with Scott and Martin.
Comment 6 Philipe Mulet CLA 2002-07-25 06:30:55 EDT
Resurrecting formatter issues in 2.1 stream.
Comment 7 Philipe Mulet CLA 2002-07-25 06:32:43 EDT
Clearing resolution
Comment 8 Markus Keller CLA 2002-08-06 05:52:50 EDT
I suggest indenting method parameters by *2* tabs if the code formatter has to
split lines. About minimum number of lines, I don't care.

Extract from org.eclipse.jdt.core.search.SearchEngine:
    public void searchAllTypeNames(
        IWorkspace workspace,
        char[] packageName,
        char[] typeName,
        int matchMode,
        boolean isCaseSensitive,
        int searchFor,
        IJavaSearchScope scope,
        final ITypeNameRequestor nameRequestor,
        int waitingPolicy,
        IProgressMonitor progressMonitor)
        throws JavaModelException {

        IndexManager indexManager =
            ((JavaModelManager) JavaModelManager.getJavaModelManager())
                .getIndexManager();
    [...]

So where does the method body start? Indenting by 2 tabs is much better readable:
    public void searchAllTypeNames(
	        IWorkspace workspace,
	        char[] packageName,
	        char[] typeName,
	        int matchMode,
	        boolean isCaseSensitive,
	        int searchFor,
	        IJavaSearchScope scope,
	        final ITypeNameRequestor nameRequestor,
	        int waitingPolicy,
	        IProgressMonitor progressMonitor)
        throws JavaModelException {

        IndexManager indexManager =
            ((JavaModelManager) JavaModelManager.getJavaModelManager())
                .getIndexManager();
    [...]


http://java.sun.com/docs/codeconv/html/CodeConventions.doc3.html#11733 also
suggests using 8 spaces (which means 2 tabs for 4-space-tabs) for intending
method declarations.
Comment 9 Markus Keller CLA 2002-08-06 06:01:17 EDT
Sorry, I indented my suggestion with tabs, which makes the rendering
Browser-dependent. Here's the correct version (with spaces):
    public void searchAllTypeNames(
            IWorkspace workspace,
            char[] packageName,
            char[] typeName,
            int matchMode,
            boolean isCaseSensitive,
            int searchFor,
            IJavaSearchScope scope,
            final ITypeNameRequestor nameRequestor,
            int waitingPolicy,
            IProgressMonitor progressMonitor)
        throws JavaModelException {

        IndexManager indexManager =
            ((JavaModelManager) JavaModelManager.getJavaModelManager())
                .getIndexManager();
Comment 10 Olivier Thomann CLA 2003-01-15 13:22:51 EST
We need to clear 2.1 bug reports that won't be addressed before 2.1. The new 
implementation is still in the works. Therefore we cannot include it for 2.1. 
Not enough testing and we need to polish the preferences. This will be address 
for 2.2 as stated in the JDT/Core plan.
Comment 11 Philipe Mulet CLA 2003-06-12 06:35:39 EDT
Resurrecting for 3.0
Comment 12 Olivier Thomann CLA 2003-06-12 15:58:55 EDT
Reopen for 3.0 consideration.
Comment 13 Bob Foster CLA 2003-06-12 21:00:00 EDT
Glad to see this back! Commenting on the comments so far...

Several have commented that if the formatter must break lines in a parameter
list or declaration, it should put the *first* parameter or declaration group on
a new line. Something like:

public void foo(ExistentialConfusion em,
    Solipsism s,
    PhilosophicalNonsense pn) {

looks sloppy. Should be:

public void foo(
    ExistentialConfusion ec,
    Solipsism s,
    PhilosophicalNonsense pn) {

As a separate option, it should be possible to keep lines together as much as
possible within the wrap margin. E.g.,

public void foo(ExistentialConfusion ec, Solipsism s,
    PhilosophicalNonsense pn) {

The request to use "two tabs" instead of one should, at most, be an option, not
the default. This would defeat the point of keeping lines together by making
lines unnecessarily longer.

The whole thing can be boiled down to three options:

When wrap margin reached:
    One unit per line -or- As many as will fit
    First unit on new line -or- First on same line if it fits

Indent continuations ___ tab stops (default 1)
Comment 14 Olivier Thomann CLA 2003-10-03 09:52:36 EDT
This should be improved with the new formatter.
Fixed and released in HEAD.
Comment 15 David Audel CLA 2003-10-13 10:14:18 EDT
Verified.