Bug 146175

Summary: Code formatter cannot produce same result as in 2.1
Product: [Eclipse Project] JDT Reporter: Juergen Kremp <juergen.kremp>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, Olivier_Thomann
Version: 3.2   
Target Milestone: 3.6 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Juergen Kremp CLA 2006-06-09 02:45:05 EDT
Hello, 

I reported this issue already two years ago when 3.0 was out (cannot find it now. Probably deleted). It was closed with comment "Post 3.1". Now with 3.2 I still have the same error.

Eclipse 3.x is unable to produce the same Code Formatter results as Eclipse 2.1.2, even though there is a "Eclipse 2.1" mode and although there are many tweak settings. This causes me to have thousands of code differences in my source-code-revision system to appear as soon as I format older code (created in 2.1.2) with the new version. 

I have created an artificial example that demonstrates my main problem. 

This is the code as produced and formatted by 2.1.2:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package demo.formatter;

public class FormatterDemo {

    public void fooBar() {
        SomeOtherClass instanceOfOtherClass = new SomeOtherClass();

        /* The following statement demonstrates the formatter issue */
        SomeOtherClass.someMethodInInnerClass(
            instanceOfOtherClass.anotherMethod("Value of paramter 1"),
            instanceOfOtherClass.anotherMethod("Value of paramter 2"));

    }

    private static class SomeOtherClass {
        public static void someMethodInInnerClass(
            String param1,
            String param2) {
        }
        public String anotherMethod(String par) {
            return par;
        }
    }

}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

The critical part is the method invocation.

The best I can get out of Eclipse 3.x looks like this:

        /* The following statement demonstrates the formatter issue */
        SomeOtherClass.someMethodInInnerClass(instanceOfOtherClass
            .anotherMethod("Value of paramter 1"), instanceOfOtherClass
            .anotherMethod("Value of paramter 2"));

Besides that it creates many differences in source-code-revision system, it is also quite bad in visual style compared to the Eclipse 2.1.2 result. 

Kind regards,
Juergen Kremp
Comment 1 Juergen Kremp CLA 2006-06-09 03:00:40 EDT
Remark: The fact that the artificial example uses an inner class to demonstrate the problem is just to have the example compact. The issue appears with any nested method invocation exceeding the configured line length (in my case 80).

The other wrappings are also affected (binary expressions, paramters, ...). 

Comment 2 Olivier Thomann CLA 2006-10-10 21:28:25 EDT
There is no intention to get the exact same formatting between 3.x and 2.1. However the resulting formatting string that you show should be improved.
Comment 3 Olivier Thomann CLA 2006-11-21 11:06:15 EST

*** This bug has been marked as a duplicate of 59891 ***
Comment 4 Jay Arthanareeswaran CLA 2010-04-27 06:53:08 EDT
Verified for 3.6M7 using build I20100424-2000.