Bug 29716

Summary: Default CodeFormatter problems
Product: [Eclipse Project] JDT Reporter: Jeff Badorek <ytsedt>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 M5   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

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 ***