Community
Participate
Working Groups
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.
Looks like a duplicate of 23134.
*** This bug has been marked as a duplicate of 23134 ***