Search in sources :

Example 1 with CodeFormatter

use of org.eclipse.jdt.core.formatter.CodeFormatter in project AutoRefactor by JnRouvignac.

the class TestHelper method normalizeJavaSourceCode.

public static String normalizeJavaSourceCode(String source) {
    final CodeFormatter codeFormatter = createCodeFormatter(getJava7Options());
    final TextEdit edit = codeFormatter.format(K_COMPILATION_UNIT, // source to format
    source, // source to format
    0, // source to format
    source.length(), // initial indentation and line separator
    0, // initial indentation and line separator
    System.getProperty("line.separator"));
    try {
        final IDocument document = new Document(source);
        edit.apply(document);
        return document.get();
    } catch (MalformedTreeException e) {
        throw new RuntimeException(e);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
Also used : CodeFormatter(org.eclipse.jdt.core.formatter.CodeFormatter) TextEdit(org.eclipse.text.edits.TextEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

CodeFormatter (org.eclipse.jdt.core.formatter.CodeFormatter)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)1 TextEdit (org.eclipse.text.edits.TextEdit)1