Community
Participate
Working Groups
Hi, in the code for one of my plugins I tried to format two methods using the default formatter. When I try to call the format method of the default formatter twice in a row (each time with the source code for a different method), the formatter inserts an extra } at the beginning of the result of the second call. You can have a workaround by concatenating the source code of both methods and calling the formatter only once, but I don't think this behavior is o.k. I've seen this bug both in release 2.0 and build 200210181211. The relevant source code for my test was: String method1 = "public void foo(){\nSystem.out.println(\"foo\");\n}"; String method2 = "public void bar(){\nSystem.out.println(\"bar\");\n}"; ICodeFormatter formatter = ToolFactory.createCodeFormatter(); String formattedCode1 = formatter.format(method1, 1, null, null); String formattedCode2 = formatter.format(method2, 1, null, null); MessageDialog.openInformation(JavaPlugin.getActiveWorkbenchShell(), "BugInFormatter", formattedCode1+"\n"+formattedCode2); I tried to debug into the default code formatter, but the code that does all the formatting is really hard to understand (lots of special cases). In order to make it easier to reproduce this problem, I've put together a small plugin which can be downloaded from my webpage http://www.lehnert.net/eclipse/download/formatterbug.zip Select a field from a Java class in the outline view, right click for the popup menu and select "BugInFormatter". This will show you an information popup showing the problem. Johannes K.
*** This bug has been marked as a duplicate of 23134 ***
Change milestone.