1 package jp.igapyon.jcfa.util;
3 import org.eclipse.jdt.core.ToolFactory;
4 import org.eclipse.jdt.core.formatter.CodeFormatter;
5 import org.eclipse.jface.text.BadLocationException;
6 import org.eclipse.jface.text.Document;
7 import org.eclipse.jface.text.IDocument;
8 import org.eclipse.text.edits.MalformedTreeException;
9 import org.eclipse.text.edits.TextEdit;
11 public class JcfaEclipseUtil {
13 * Format source using eclipse.
17 * @return Formatted source.
19 public static String formatSource(final String source) {
21 System.out.println("TRACE: " + source);
23 final CodeFormatter cf = ToolFactory.createCodeFormatter(null);
24 final TextEdit te = cf.format(CodeFormatter.K_UNKNOWN, source, 0,
25 source.length(), 0, null);
26 IDocument doc = new Document(source);
30 } catch (MalformedTreeException e) {
32 throw new IllegalArgumentException(e);
33 } catch (BadLocationException e) {
35 throw new IllegalArgumentException(e);