Example usage for org.eclipse.jdt.internal.formatter DefaultCodeFormatterOptions DefaultCodeFormatterOptions

List of usage examples for org.eclipse.jdt.internal.formatter DefaultCodeFormatterOptions DefaultCodeFormatterOptions

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.formatter DefaultCodeFormatterOptions DefaultCodeFormatterOptions.

Prototype

public DefaultCodeFormatterOptions(Map<String, String> settings) 

Source Link

Usage

From source file:com.google.googlejavaformat.java.EclipseJavadocFormatter.java

License:Apache License

private static String formatJavadocInternal(String input, int indent, JavaFormatterOptions options) {

    ImmutableMap.Builder<String, String> optionBuilder = ImmutableMap.<String, String>builder();
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, "true");
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE,
            Integer.toString(options.indentationMultiplier()));
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH,
            Integer.toString(options.maxLineLength() - indent));
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT,
            Integer.toString(options.maxLineLength()));
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_PARAMETER_DESCRIPTION,
            DefaultCodeFormatterConstants.FALSE);
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER,
            JavaCore.DO_NOT_INSERT);//from ww w.  j a  v a 2  s.  c o m
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT,
            DefaultCodeFormatterConstants.FALSE);
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_LINES_IN_COMMENTS,
            DefaultCodeFormatterConstants.TRUE);
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES,
            DefaultCodeFormatterConstants.TRUE);
    // Disable indenting root tags for now since it indents more than 4 spaces
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_ROOT_TAGS,
            DefaultCodeFormatterConstants.FALSE);
    optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE,
            DefaultCodeFormatterConstants.FALSE);
    optionBuilder.put(JavaCore.COMPILER_COMPLIANCE, "1.8");
    optionBuilder.put(JavaCore.COMPILER_SOURCE, "1.8");
    optionBuilder.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.8");
    DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(
            new DefaultCodeFormatterOptions(optionBuilder.build()));

    TextEdit edit = codeFormatter.format(CodeFormatter.K_JAVA_DOC, input, /*offset*/ 0, input.length(),
            // eclipse doesn't indent comments reliably, so always request no indent and fix it
            // up later in JavaCommentsHelper
            /*indent*/ 0, /*lineSeparator*/ null);
    if (edit == null) {
        throw new RuntimeException("error formatting javadoc");
    }
    Document document = new Document(input);
    try {
        edit.apply(document);
    } catch (BadLocationException e) {
        throw new RuntimeException("error formatting javadoc", e);
    }
    return document.get();
}

From source file:com.liferay.ide.ui.LiferayUIPlugin.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map getLiferaySettings() {
    final Map options = new DefaultCodeFormatterOptions(LiferayDefaultCodeFormatterSettings.settings).getMap();
    ProfileVersioner.setLatestCompliance(options);
    return options;
}

From source file:org.eclipse.objectteams.otdt.core.tests.formatter.FormatterTests.java

License:Open Source License

private void runTest(String packageName, String compilationUnitName) {
    DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(
            DefaultCodeFormatterConstants.getEclipseDefaultSettings());
    preferences.number_of_empty_lines_to_preserve = 0;
    DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences,
            this.currentProject.getOptions(false));
    runTest(codeFormatter, packageName, compilationUnitName, CodeFormatter.K_COMPILATION_UNIT, 0);
}