JavaCodeFormatter { public String format(String compilationUnit) { createCodeFormatter(); String lineSeparator = getLineEnding(compilationUnit); TextEdit te = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT + CodeFormatter.F_INCLUDE_COMMENTS, compilationUnit, 0, compilationUnit.length(), 0, lineSeparator); IDocument doc = new Document(compilationUnit); try { te.apply(doc); } catch (MalformedTreeException e) { logger.log(Level.SEVERE, ExceptionUtils.getStackTrace(e)); } catch (BadLocationException e) { logger.log(Level.SEVERE, ExceptionUtils.getStackTrace(e)); } String formattedCode = doc.get(); return formattedCode; }  String format(String compilationUnit);  }
@Test public void testFormat() { String unformattedCode = "public interface Company {\nde.test.Calculator calculateMe() throws de.test.CalculatorException ;\n}\n"; String formattedCode = javaCodeFormatter.format(unformattedCode); assertNotSame(unformattedCode, formattedCode); }