Bug 25976

Summary: Bug in code formatter: can't be called twice in a row...
Product: [Eclipse Project] JDT Reporter: Johannes K. Lehnert <lehnert>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Johannes K. Lehnert CLA 2002-11-11 10:52:21 EST
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.
Comment 1 Olivier Thomann CLA 2002-11-14 13:20:25 EST

*** This bug has been marked as a duplicate of 23134 ***
Comment 2 Olivier Thomann CLA 2003-01-17 10:20:10 EST
Change milestone.