Bug 25976 - Bug in code formatter: can't be called twice in a row...
Summary: Bug in code formatter: can't be called twice in a row...
Status: RESOLVED DUPLICATE of bug 23134
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-11 10:52 EST by Johannes K. Lehnert CLA
Modified: 2003-01-17 10:20 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.