Bug 29716 - Default CodeFormatter problems
Summary: Default CodeFormatter problems
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 2000
: P3 normal (vote)
Target Milestone: 2.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-17 10:45 EST by Jeff Badorek CLA
Modified: 2003-01-21 10:29 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 Jeff Badorek CLA 2003-01-17 10:45:08 EST
I'm try to format multiple ICompilationUnit(s) at the same time, however, I'm 
running in to a snag. when I try the following...it will put extra characters 
in some of the source files.

  ICompilationUnit[] cus = getCompilationUnits(selection);
  ICodeFormatter formatter = ToolFactory.createCodeFormatter();

  for (int i = 0; i < cus.length; i++) {
    try {
      IBuffer buf = cu.getBuffer();
      String contents = formatter.format(buf.getContents(), 0, null, null);
      buf.setContents(contents);
      buf.save(monitor, true);
    } catch (JavaModelException e) {
      JavaPlugin.log(e);
    }
  }

However, when I move the "ICodeFormatter formatter..." line inside the "for" 
loop, it works correctly. I'm guessing that when the formatting by the 
formatter is done, it is not flushing its buffer correctly. BTW, the formatter 
is the default CodeFormatter.

I would prefer to only have one code formatter instantiated since some of my 
projects have 1000s of java files.
Comment 1 Olivier Thomann CLA 2003-01-17 16:06:40 EST
Looks like a duplicate of 23134.
Comment 2 Olivier Thomann CLA 2003-01-21 10:29:03 EST

*** This bug has been marked as a duplicate of 23134 ***