/** * Returns the default Eclipse formatter settings * * @return the Eclipse default settings * @since 3.1 */ public static Map getEclipseDefaultSettings() { return DefaultCodeFormatterOptions.getEclipseDefaultSettings().getMap(); }
/** * Returns the settings according to the Java conventions. * * @return the settings according to the Java conventions * @since 3.0 */ public static Map getJavaConventionsSettings() { return DefaultCodeFormatterOptions.getJavaConventionsSettings().getMap(); } /**
public static DefaultCodeFormatterOptions getDefaultSettings() { DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions(); options.setDefaultSettings(); return options; }
private void initOptions(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, String> options) { if (options != null) { this.originalOptions = new DefaultCodeFormatterOptions(options); this.workingOptions = new DefaultCodeFormatterOptions(options); this.oldCommentFormatOption = getOldCommentFormatOption(options); String compilerSource = options.get(CompilerOptions.OPTION_Source); this.sourceLevel = compilerSource != null ? compilerSource : CompilerOptions.VERSION_1_8; } else { Map<String, String> settings = DefaultCodeFormatterConstants.getJavaConventionsSettings(); this.originalOptions = new DefaultCodeFormatterOptions(settings); this.workingOptions = new DefaultCodeFormatterOptions(settings); this.oldCommentFormatOption = DefaultCodeFormatterConstants.TRUE; this.sourceLevel = CompilerOptions.VERSION_1_8; } if (defaultCodeFormatterOptions != null) { this.originalOptions.set(defaultCodeFormatterOptions.getMap()); this.workingOptions.set(defaultCodeFormatterOptions.getMap()); } }
/** * Returns the formatter settings that most closely approximate * the default formatter settings of Eclipse version 2.1. * * @return the Eclipse 2.1 settings * @since 3.0 */ public static Map getEclipse21Settings() { return DefaultCodeFormatterOptions.getDefaultSettings().getMap(); }
public static DefaultCodeFormatterOptions getJavaConventionsSettings() { DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions(); options.setJavaConventionsSettings(); return options; }
public DefaultCodeFormatterOptions(Map<String, String> settings) { setDefaultSettings(); if (settings == null) return; set(settings); }
public static DefaultCodeFormatterOptions getEclipseDefaultSettings() { DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions(); options.setEclipseDefaultSettings(); return options; }
this.alignment_for_compact_loop = toInt(alignmentForCompactLoopOption, Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_INDENT_BY_ONE); this.alignment_for_expressions_in_for_loop_header = toInt(alignmentForExpressionsInForLoopOption, Alignment.M_NO_ALIGNMENT); this.alignment_for_module_statements = toInt(alignmentForModuleStatementsOption, Alignment.M_COMPACT_SPLIT); this.alignment_for_parameterized_type_references = toInt(alignmentForParameterizeddTypeReferencesOption, Alignment.M_NO_ALIGNMENT); this.alignment_for_type_arguments = toInt(alignmentForTypeArguments, Alignment.M_NO_ALIGNMENT); this.alignment_for_type_parameters = toInt(alignmentForTypeParameters, Alignment.M_NO_ALIGNMENT); this.parenthesis_positions_in_method_declaration = toString(closingParenPositionInMethodDeclaration, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_method_invocation = toString(closingParenPositionInMethodInvocation, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_enum_constant_declaration = toString(closingParenPositionInEnumConstantDeclaration, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_if_while_statement = toString(closingParenPositionInIfWhileStatement, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_for_statement = toString(closingParenPositionInForStatement, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_switch_statement = toString(closingParenPositionInSwitchStatement, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_try_clause = toString(closingParenPositionInTryClause, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_catch_clause = toString(closingParenPositionInCatchClause, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_annotation = toString(closingParenPositionInAnnotation, DefaultCodeFormatterConstants.COMMON_LINES);
this.alignment_for_expressions_in_for_loop_header = toInt(alignmentForExpressionsInForLoopOption, Alignment.M_NO_ALIGNMENT); this.alignment_for_module_statements = toInt(alignmentForModuleStatementsOption, Alignment.M_COMPACT_SPLIT); this.alignment_for_parameterized_type_references = toInt(alignmentForParameterizeddTypeReferencesOption, Alignment.M_NO_ALIGNMENT); this.alignment_for_type_arguments = toInt(alignmentForTypeArguments, Alignment.M_NO_ALIGNMENT); this.alignment_for_type_parameters = toInt(alignmentForTypeParameters, Alignment.M_NO_ALIGNMENT); this.parenthesis_positions_in_method_declaration = toString(closingParenPositionInMethodDeclaration, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_method_invocation = toString(closingParenPositionInMethodInvocation, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_enum_constant_declaration = toString(closingParenPositionInEnumConstantDeclaration, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_if_while_statement = toString(closingParenPositionInIfWhileStatement, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_for_statement = toString(closingParenPositionInForStatement, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_switch_statement = toString(closingParenPositionInSwitchStatement, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_try_clause = toString(closingParenPositionInTryClause, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_catch_clause = toString(closingParenPositionInCatchClause, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_annotation = toString(closingParenPositionInAnnotation, DefaultCodeFormatterConstants.COMMON_LINES); this.parenthesis_positions_in_lambda_declaration = toString(closingParenPositionInLambdaDeclaration, DefaultCodeFormatterConstants.COMMON_LINES);
private DefaultCodeFormatter getCommentCodeFormatter() { if (this.commentCodeFormatter == null) { Map<String, String> options2 = this.options.getMap(); options2.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, String.valueOf(this.options.comment_line_length - this.commentIndent - COMMENT_LINE_SEPARATOR_LENGTH)); options2.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, String.valueOf(this.options.page_width - this.commentIndent - COMMENT_LINE_SEPARATOR_LENGTH)); options2.put(CompilerOptions.OPTION_Source, this.sourceLevel); this.commentCodeFormatter = new DefaultCodeFormatter(options2); } return this.commentCodeFormatter; }
public DefaultCodeFormatter() { this(new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getJavaConventionsSettings()), null); }
public Map getMap() { Map options = new HashMap(); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION, getAlignment(this.alignment_for_arguments_in_annotation)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT, getAlignment(this.alignment_for_arguments_in_enum_constant)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, getAlignment(this.alignment_for_arguments_in_explicit_constructor_call)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_qualified_allocation_expression)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, getAlignment(this.alignment_for_assignment)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, getAlignment(this.alignment_for_enum_constants)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_ARRAY_INITIALIZER, getAlignment(this.alignment_for_expressions_in_array_initializer)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_METHOD_DECLARATION, getAlignment(this.alignment_for_method_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLE_FIELDS, getAlignment(this.alignment_for_multiple_fields)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION, getAlignment(this.alignment_for_parameters_in_constructor_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, getAlignment(this.alignment_for_parameters_in_method_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RESOURCES_IN_TRY, getAlignment(this.alignment_for_resources_in_try)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SELECTOR_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_selector_in_method_invocation)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SUPERCLASS_IN_TYPE_DECLARATION, getAlignment(this.alignment_for_superclass_in_type_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SUPERINTERFACES_IN_ENUM_DECLARATION, getAlignment(this.alignment_for_superinterfaces_in_enum_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SUPERINTERFACES_IN_TYPE_DECLARATION, getAlignment(this.alignment_for_superinterfaces_in_type_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_CONSTRUCTOR_DECLARATION, getAlignment(this.alignment_for_throws_clause_in_constructor_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_METHOD_DECLARATION, getAlignment(this.alignment_for_throws_clause_in_method_declaration)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_UNION_TYPE_IN_MULTICATCH, getAlignment(this.alignment_for_union_type_in_multicatch)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGN_TYPE_MEMBERS_ON_COLUMNS, this.align_type_members_on_columns ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ANNOTATION_TYPE_DECLARATION, this.brace_position_for_annotation_type_declaration);
setDeprecatedOptions(settings); final Object commentFormatJavadocCommentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT); if (commentFormatJavadocCommentOption != null) {
public static String format(String code, Map<String, String> options) { DefaultCodeFormatterOptions cfOptions = DefaultCodeFormatterOptions.getJavaConventionsSettings(); cfOptions.tab_char = DefaultCodeFormatterOptions.TAB; CodeFormatter cf = new DefaultCodeFormatter(cfOptions, options); TextEdit te = cf.format(CodeFormatter.K_UNKNOWN, code, 0, code.length(), 0, null); IDocument dc = new Document(code); try { te.apply(dc); } catch (Exception e) { throw new MinnalGeneratorException("Failed while formatting the code", e); } return dc.get(); } }
private void initOptions(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, String> options) { if (options != null) { this.originalOptions = new DefaultCodeFormatterOptions(options); this.workingOptions = new DefaultCodeFormatterOptions(options); this.oldCommentFormatOption = getOldCommentFormatOption(options); String compilerSource = options.get(CompilerOptions.OPTION_Source); this.sourceLevel = compilerSource != null ? compilerSource : CompilerOptions.VERSION_1_8; } else { Map<String, String> settings = DefaultCodeFormatterConstants.getJavaConventionsSettings(); this.originalOptions = new DefaultCodeFormatterOptions(settings); this.workingOptions = new DefaultCodeFormatterOptions(settings); this.oldCommentFormatOption = DefaultCodeFormatterConstants.TRUE; this.sourceLevel = CompilerOptions.VERSION_1_8; } if (defaultCodeFormatterOptions != null) { this.originalOptions.set(defaultCodeFormatterOptions.getMap()); this.workingOptions.set(defaultCodeFormatterOptions.getMap()); } }
/** * Returns the formatter settings that most closely approximate * the default formatter settings of Eclipse version 2.1. * * @return the Eclipse 2.1 settings * @since 3.0 */ public static Map getEclipse21Settings() { DefaultCodeFormatterOptions options = DefaultCodeFormatterOptions.getDefaultSettings(); options.page_width = 80; // changed with bug 356841 return options.getMap(); }
public static DefaultCodeFormatterOptions getJavaConventionsSettings() { DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions(); options.setJavaConventionsSettings(); return options; }
public DefaultCodeFormatterOptions(Map<String, String> settings) { setDefaultSettings(); if (settings == null) return; set(settings); }
public static DefaultCodeFormatterOptions getEclipseDefaultSettings() { DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions(); options.setEclipseDefaultSettings(); return options; }