Example usage for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants WRAP_NO_SPLIT

List of usage examples for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants WRAP_NO_SPLIT

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants WRAP_NO_SPLIT.

Prototype

int WRAP_NO_SPLIT

To view the source code for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants WRAP_NO_SPLIT.

Click Source Link

Document

 FORMATTER / Value to disable alignment. 

Usage

From source file:com.thoratou.exact.processors.IndentUtil.java

License:Open Source License

public String javaCode(String input) {
    // take default Eclipse formatting options
    Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
    options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);

    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);

    // change the option to wrap each enum constant on a new line
    options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
            DefaultCodeFormatterConstants.createAlignmentValue(true,
                    DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
                    DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

    // change the option to wrap each enum constant on a new line
    options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT,
            DefaultCodeFormatterConstants.createAlignmentValue(false,
                    DefaultCodeFormatterConstants.WRAP_NO_SPLIT,
                    DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

    // change the option to wrap each enum constant on a new line
    options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SELECTOR_IN_METHOD_INVOCATION,
            DefaultCodeFormatterConstants.createAlignmentValue(false,
                    DefaultCodeFormatterConstants.WRAP_NO_SPLIT,
                    DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

    CodeFormatter cf = ToolFactory.createCodeFormatter(options);

    IDocument dc = new Document(input);
    TextEdit te = cf.format(CodeFormatter.K_COMPILATION_UNIT, dc.get(), 0, dc.get().length(), 0, null);

    try {//  ww w  .j  a  va 2  s  . c  o  m
        te.apply(dc);
    } catch (MalformedTreeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return dc.get();
}