diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java index 9953f779700..7b080b7aaa9 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java @@ -529,6 +529,17 @@ public class DefaultCodeFormatterConstants { * @see #FALSE */ public static final String FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER = CCorePlugin.PLUGIN_ID + ".formatter.indent_body_declarations_compare_to_access_specifier"; //$NON-NLS-1$ + /** + *
+ * FORMATTER / Option to indent template declaration compare to template header + * - option id: "org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header" + * - possible values: { TRUE, FALSE } + * - default: FALSE + *+ * @see #TRUE + * @see #FALSE + */ + public static final String FORMATTER_INDENT_DECLARATION_COMPARE_TO_TEMPLATE_HEADER = CCorePlugin.PLUGIN_ID + ".formatter.indent_declaration_compare_to_template_header"; //$NON-NLS-1$ /** *
* FORMATTER / Option to indent body declarations compare to its enclosing namespace header @@ -640,7 +651,17 @@ public class DefaultCodeFormatterConstants { * @see CCorePlugin#DO_NOT_INSERT */ public static final String FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_INITIALIZER_LIST = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_after_opening_brace_in_array_initializer";//$NON-NLS-1$ - + /** + *+ * FORMATTER / Option to insert a new line after template declaration + * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_TEMPLATE_DECLARATION = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_after_template_declaration";//$NON-NLS-1$ /** ** FORMATTER / Option to insert a new line at the end of the current file if missing @@ -652,17 +673,17 @@ public class DefaultCodeFormatterConstants { * @see CCorePlugin#DO_NOT_INSERT */ public static final String FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_at_end_of_file_if_missing";//$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a new line before the catch keyword in try statement -// * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_catch_in_try_statement"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a new line before the catch keyword in try statement + * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_catch_in_try_statement"; //$NON-NLS-1$ /** ** FORMATTER / Option to insert a new line before the closing brace in an initializer list @@ -685,17 +706,6 @@ public class DefaultCodeFormatterConstants { * @see CCorePlugin#DO_NOT_INSERT */ public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_else_in_if_statement"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a new line before the finally keyword in try statement -// * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_finally_in_try_statement" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_FINALLY_IN_TRY_STATEMENT = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_finally_in_try_statement"; //$NON-NLS-1$ /** ** FORMATTER / Option to insert a new line before while in do statement @@ -707,6 +717,17 @@ public class DefaultCodeFormatterConstants { * @see CCorePlugin#DO_NOT_INSERT */ public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_while_in_do_statement"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a new line before the identifier in a function declaration + * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_IDENTIFIER_IN_FUNCTION_DECLARATION = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_identifier_in_function_declaration"; //$NON-NLS-1$ /** ** FORMATTER / Option to insert a new line in an empty block diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index f1f4b0db25a..55dd7370055 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -457,10 +457,13 @@ public class CodeFormatterVisitor extends CPPASTVisitor { final IASTPointerOperator[] pointerOperators= node.getPointerOperators(); formatPointers(pointerOperators); if (node instanceof IASTStandardFunctionDeclarator) { - // preserve newline between decl-specifier and declarator - // TLETODO need alignment for function definition - if (scribe.preserveNewLine()) { - scribe.space(); + if (preferences.insert_new_line_before_identifier_in_function_declaration) { + scribe.startNewLine(); + } else { + // preserve newline if not explicitely requested + if (scribe.preserveNewLine()) { + scribe.space(); + } } } IASTName name= node.getName(); @@ -1181,12 +1184,14 @@ public class CodeFormatterVisitor extends CPPASTVisitor { for (int i = 0; i < arrayModifiers.length; i++) { IASTArrayModifier arrayModifier = arrayModifiers[i]; scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket); - if (preferences.insert_space_after_opening_bracket ) { - scribe.space(); + boolean emptyBrackets= arrayModifier.getConstantExpression() == null + && !(arrayModifier instanceof ICASTArrayModifier); + if (!emptyBrackets) { + if (preferences.insert_space_after_opening_bracket) { + scribe.space(); + } } - boolean emptyBrackets= arrayModifier.getConstantExpression() == null; if (arrayModifier instanceof ICASTArrayModifier) { - emptyBrackets= false; final ICASTArrayModifier cArrayModifier= (ICASTArrayModifier)arrayModifier; if (scribe.printModifiers()) { scribe.space(); @@ -1198,13 +1203,14 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.space(); } } - boolean forceSpace= emptyBrackets && preferences.insert_space_between_empty_brackets; try { arrayModifier.accept(this); } catch (ASTProblemException e) { scribe.skipToToken(Token.tRBRACKET); } - scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_before_closing_bracket || forceSpace); + boolean insertSpace= emptyBrackets ? preferences.insert_space_between_empty_brackets + : preferences.insert_space_before_closing_bracket; + scribe.printNextToken(Token.tRBRACKET, insertSpace); } } return PROCESS_SKIP; @@ -1243,6 +1249,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor { if (preferences.insert_space_after_opening_angle_bracket_in_template_parameters) { scribe.space(); } + + // template parameters final ICPPASTTemplateParameter[] templateParameters= node.getTemplateParameters(); if (templateParameters.length > 0) { final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT); @@ -1254,11 +1262,27 @@ public class CodeFormatterVisitor extends CPPASTVisitor { if (preferences.insert_space_after_closing_angle_bracket_in_template_parameters) { scribe.space(); } + + // declaration final IASTDeclaration declaration= node.getDeclaration(); - // preserve newline if any - // TLETODO need alignment for template declaration - scribe.preserveNewLine(); + if (preferences.insert_new_line_after_template_declaration) { + scribe.startNewLine(); + if (preferences.indent_declaration_compare_to_template_header) { + scribe.indent(); + } + } else { + // preserve newline if not explicitely requested + scribe.preserveNewLine(); + } + declaration.accept(this); + + if (preferences.insert_new_line_after_template_declaration) { + if (preferences.indent_declaration_compare_to_template_header) { + scribe.unIndent(); + } + } + return PROCESS_SKIP; } @@ -1424,6 +1448,13 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } scribe.startNewLine(); } + if (preferences.indent_body_declarations_compare_to_access_specifier) { + scribe.indent(); + } + scribe.printComment(); + if (preferences.indent_body_declarations_compare_to_access_specifier) { + scribe.unIndent(); + } if (preferences.indent_access_specifier_compare_to_type_header) { scribe.unIndent(); } @@ -1435,9 +1466,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } private int visit(ICPPASTVisiblityLabel node) { - if (!preferences.indent_access_specifier_compare_to_type_header) { - scribe.unIndent(); - } if (node.getNodeLocations()[0] instanceof IASTMacroExpansion) { skipNode(node); } else { @@ -1455,10 +1483,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { if (peekNextToken() != Token.tCOLON) { scribe.skipToToken(Token.tCOLON); } - scribe.printNextToken(Token.tCOLON, false/*preferences.insert_space_before_colon_in_visibility_label */); - } - if (!preferences.indent_access_specifier_compare_to_type_header) { - scribe.indent(); + scribe.printNextToken(Token.tCOLON, false/*preferences.insert_space_before_colon_in_access specifier*/); } return PROCESS_SKIP; } @@ -1655,6 +1680,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } private int visit(ICPPASTCatchHandler node) { + if (preferences.insert_new_line_before_catch_in_try_statement) { + scribe.startNewLine(); + } scribe.printNextToken(Token.t_catch, true); scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_catch); if (preferences.insert_space_after_opening_paren_in_catch) { @@ -2184,10 +2212,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.printNextToken(Token.t_delete); if (node.isVectored()) { scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket); - if (preferences.insert_space_after_opening_bracket || preferences.insert_space_between_empty_brackets) { - scribe.space(); - } - scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_before_closing_bracket); + scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_between_empty_brackets); } scribe.space(); node.getOperand().accept(this); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java index c742df2a359..2c7a5d8cc58 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java @@ -104,19 +104,22 @@ public class DefaultCodeFormatterOptions { public boolean indent_body_declarations_compare_to_access_specifier; public boolean indent_access_specifier_compare_to_type_header; public boolean indent_body_declarations_compare_to_namespace_header; + public boolean indent_declaration_compare_to_template_header; public boolean indent_breaks_compare_to_cases; public boolean indent_empty_lines; public boolean indent_switchstatements_compare_to_cases; public boolean indent_switchstatements_compare_to_switch; public int indentation_size; + public boolean insert_new_line_after_opening_brace_in_initializer_list; + public boolean insert_new_line_after_template_declaration; public boolean insert_new_line_at_end_of_file_if_missing; -// public boolean insert_new_line_before_catch_in_try_statement; + public boolean insert_new_line_before_catch_in_try_statement; public boolean insert_new_line_before_closing_brace_in_initializer_list; public boolean insert_new_line_before_else_in_if_statement; -// public boolean insert_new_line_before_finally_in_try_statement; public boolean insert_new_line_before_while_in_do_statement; + public boolean insert_new_line_before_identifier_in_function_declaration; public boolean insert_new_line_in_empty_block; // public boolean insert_new_line_in_empty_method_body; // public boolean insert_new_line_in_empty_type_declaration; @@ -299,6 +302,7 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BODY, this.indent_statements_compare_to_body ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, this.indent_body_declarations_compare_to_access_specifier ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, this.indent_access_specifier_compare_to_type_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); + options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_DECLARATION_COMPARE_TO_TEMPLATE_HEADER, this.indent_declaration_compare_to_template_header? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_NAMESPACE_HEADER, this.indent_body_declarations_compare_to_namespace_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BREAKS_COMPARE_TO_CASES, this.indent_breaks_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, this.indent_empty_lines ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); @@ -306,12 +310,13 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, this.indent_switchstatements_compare_to_switch ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, Integer.toString(this.indentation_size)); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_INITIALIZER_LIST, this.insert_new_line_after_opening_brace_in_initializer_list? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_TEMPLATE_DECLARATION, this.insert_new_line_after_template_declaration? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING, this.insert_new_line_at_end_of_file_if_missing ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT, this.insert_new_line_before_catch_in_try_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT, this.insert_new_line_before_catch_in_try_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_INITIALIZER_LIST, this.insert_new_line_before_closing_brace_in_initializer_list? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT, this.insert_new_line_before_else_in_if_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_FINALLY_IN_TRY_STATEMENT, this.insert_new_line_before_finally_in_try_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT, this.insert_new_line_before_while_in_do_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_IDENTIFIER_IN_FUNCTION_DECLARATION, this.insert_new_line_before_identifier_in_function_declaration? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_BLOCK, this.insert_new_line_in_empty_block? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY, this.insert_new_line_in_empty_method_body? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION, this.insert_new_line_in_empty_type_declaration? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -799,6 +804,10 @@ public class DefaultCodeFormatterOptions { if (indentBodyDeclarationsCompareToAccessSpecifierOption != null) { this.indent_body_declarations_compare_to_access_specifier = DefaultCodeFormatterConstants.TRUE.equals(indentBodyDeclarationsCompareToAccessSpecifierOption); } + final Object indentDeclarationCompareToTemplateHeaderOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_DECLARATION_COMPARE_TO_TEMPLATE_HEADER); + if (indentDeclarationCompareToTemplateHeaderOption != null) { + this.indent_declaration_compare_to_template_header = DefaultCodeFormatterConstants.TRUE.equals(indentDeclarationCompareToTemplateHeaderOption); + } final Object indentBodyDeclarationsCompareToNamespaceHeaderOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_NAMESPACE_HEADER); if (indentBodyDeclarationsCompareToNamespaceHeaderOption != null) { this.indent_body_declarations_compare_to_namespace_header = DefaultCodeFormatterConstants.TRUE.equals(indentBodyDeclarationsCompareToNamespaceHeaderOption); @@ -833,14 +842,18 @@ public class DefaultCodeFormatterOptions { if (insertNewLineAfterOpeningBraceInInitializerListOption != null) { this.insert_new_line_after_opening_brace_in_initializer_list = CCorePlugin.INSERT.equals(insertNewLineAfterOpeningBraceInInitializerListOption); } + final Object insertNewLineAfterTemplateDeclarationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_TEMPLATE_DECLARATION); + if (insertNewLineAfterOpeningBraceInInitializerListOption != null) { + this.insert_new_line_after_template_declaration = CCorePlugin.INSERT.equals(insertNewLineAfterTemplateDeclarationOption); + } final Object insertNewLineAtEndOfFileIfMissingOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING); if (insertNewLineAtEndOfFileIfMissingOption != null) { this.insert_new_line_at_end_of_file_if_missing = CCorePlugin.INSERT.equals(insertNewLineAtEndOfFileIfMissingOption); } -// final Object insertNewLineBeforeCatchInTryStatementOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT); -// if (insertNewLineBeforeCatchInTryStatementOption != null) { -// this.insert_new_line_before_catch_in_try_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeCatchInTryStatementOption); -// } + final Object insertNewLineBeforeCatchInTryStatementOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT); + if (insertNewLineBeforeCatchInTryStatementOption != null) { + this.insert_new_line_before_catch_in_try_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeCatchInTryStatementOption); + } final Object insertNewLineBeforeClosingBraceInInitializerListOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_INITIALIZER_LIST); if (insertNewLineBeforeClosingBraceInInitializerListOption != null) { this.insert_new_line_before_closing_brace_in_initializer_list = CCorePlugin.INSERT.equals(insertNewLineBeforeClosingBraceInInitializerListOption); @@ -849,14 +862,14 @@ public class DefaultCodeFormatterOptions { if (insertNewLineBeforeElseInIfStatementOption != null) { this.insert_new_line_before_else_in_if_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeElseInIfStatementOption); } -// final Object insertNewLineBeforeFinallyInTryStatementOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_FINALLY_IN_TRY_STATEMENT); -// if (insertNewLineBeforeFinallyInTryStatementOption != null) { -// this.insert_new_line_before_finally_in_try_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeFinallyInTryStatementOption); -// } final Object insertNewLineBeforeWhileInDoStatementOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT); if (insertNewLineBeforeWhileInDoStatementOption != null) { this.insert_new_line_before_while_in_do_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeWhileInDoStatementOption); } + final Object insertNewLineBeforeIdentifierInFunctionDefinitionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_IDENTIFIER_IN_FUNCTION_DECLARATION); + if (insertNewLineBeforeWhileInDoStatementOption != null) { + this.insert_new_line_before_identifier_in_function_declaration = CCorePlugin.INSERT.equals(insertNewLineBeforeIdentifierInFunctionDefinitionOption); + } final Object insertNewLineInEmptyBlockOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_BLOCK); if (insertNewLineInEmptyBlockOption != null) { this.insert_new_line_in_empty_block = CCorePlugin.INSERT.equals(insertNewLineInEmptyBlockOption); @@ -1419,11 +1432,11 @@ public class DefaultCodeFormatterOptions { this.indentation_size = 4; this.insert_new_line_after_opening_brace_in_initializer_list = false; this.insert_new_line_at_end_of_file_if_missing = false; -// this.insert_new_line_before_catch_in_try_statement = false; + this.insert_new_line_before_catch_in_try_statement = false; this.insert_new_line_before_closing_brace_in_initializer_list = false; this.insert_new_line_before_else_in_if_statement = false; -// this.insert_new_line_before_finally_in_try_statement = false; this.insert_new_line_before_while_in_do_statement = false; + this.insert_new_line_before_identifier_in_function_declaration = false; this.insert_new_line_in_empty_block = true; // this.insert_new_line_in_empty_method_body = true; // this.insert_new_line_in_empty_type_declaration = true; @@ -1599,7 +1612,6 @@ public class DefaultCodeFormatterOptions { this.indent_statements_compare_to_body = true; this.indent_body_declarations_compare_to_namespace_header = false; // this.indent_body_declarations_compare_to_enum_declaration_header = true; - this.indent_body_declarations_compare_to_access_specifier = true; this.indent_breaks_compare_to_cases = true; this.indent_empty_lines = false; this.indent_switchstatements_compare_to_cases = true; @@ -1608,11 +1620,8 @@ public class DefaultCodeFormatterOptions { this.insert_new_line_after_opening_brace_in_initializer_list = false; this.insert_new_line_at_end_of_file_if_missing = false; -// this.insert_new_line_before_catch_in_try_statement = false; this.insert_new_line_before_closing_brace_in_initializer_list = false; this.insert_new_line_before_else_in_if_statement = true; -// this.insert_new_line_before_finally_in_try_statement = false; - this.insert_new_line_before_while_in_do_statement = false; this.insert_new_line_in_empty_block = true; // this.insert_new_line_in_empty_enum_declaration = true; // this.insert_new_line_in_empty_method_body = true; @@ -1639,18 +1648,18 @@ public class DefaultCodeFormatterOptions { *Example:
** namespace foospace + * { + * int Foo() * { - * int Foo() + * if (isBar) * { - * if (isBar) - * { - * bar(); - * return 1; - * } - * else - * return 0; + * bar(); + * return 1; * } + * else + * return 0; * } + * } ** @see http://en.wikipedia.org/wiki/Indent_style */ @@ -1660,16 +1669,16 @@ public class DefaultCodeFormatterOptions { this.brace_position_for_block = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; this.brace_position_for_block_in_case = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; // this.brace_position_for_enum_declaration = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; - this.brace_position_for_method_declaration = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; - this.brace_position_for_type_declaration = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; - this.brace_position_for_namespace_declaration = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; + this.brace_position_for_method_declaration = DefaultCodeFormatterConstants.NEXT_LINE; + this.brace_position_for_type_declaration = DefaultCodeFormatterConstants.NEXT_LINE; + this.brace_position_for_namespace_declaration = DefaultCodeFormatterConstants.NEXT_LINE; this.brace_position_for_switch = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; this.indent_statements_compare_to_block = true; this.indent_statements_compare_to_body = true; this.indent_body_declarations_compare_to_namespace_header = true; // this.indent_body_declarations_compare_to_enum_declaration_header = true; - this.indent_body_declarations_compare_to_access_specifier = true; + this.indent_declaration_compare_to_template_header = true; this.indent_breaks_compare_to_cases = true; this.indent_empty_lines = false; this.indent_switchstatements_compare_to_cases = true; @@ -1677,16 +1686,19 @@ public class DefaultCodeFormatterOptions { this.indentation_size = 8; this.insert_new_line_after_opening_brace_in_initializer_list = false; + this.insert_new_line_after_template_declaration = true; this.insert_new_line_at_end_of_file_if_missing = false; -// this.insert_new_line_before_catch_in_try_statement = false; + this.insert_new_line_before_catch_in_try_statement = true; this.insert_new_line_before_closing_brace_in_initializer_list = false; this.insert_new_line_before_else_in_if_statement = true; -// this.insert_new_line_before_finally_in_try_statement = false; - this.insert_new_line_before_while_in_do_statement = false; + this.insert_new_line_before_identifier_in_function_declaration = true; + this.insert_new_line_before_while_in_do_statement = true; this.insert_new_line_in_empty_block = true; -// this.insert_new_line_in_empty_enum_declaration = true; -// this.insert_new_line_in_empty_method_body = true; -// this.insert_new_line_in_empty_type_declaration = true; +// this.insert_new_line_in_empty_enum_declaration = false; +// this.insert_new_line_in_empty_method_body = false; +// this.insert_new_line_in_empty_type_declaration = false; + + this.insert_space_before_colon_in_base_clause = true; this.compact_else_if = true; this.keep_guardian_clause_on_one_line = false; @@ -1737,7 +1749,6 @@ public class DefaultCodeFormatterOptions { this.indent_statements_compare_to_block = false; this.indent_statements_compare_to_body = false; this.indent_body_declarations_compare_to_namespace_header = false; - this.indent_body_declarations_compare_to_access_specifier = true; this.indent_breaks_compare_to_cases = true; this.indent_empty_lines = false; this.indent_switchstatements_compare_to_cases = true; @@ -1746,10 +1757,9 @@ public class DefaultCodeFormatterOptions { this.insert_new_line_after_opening_brace_in_initializer_list = true; this.insert_new_line_at_end_of_file_if_missing = false; -// this.insert_new_line_before_catch_in_try_statement = true; + this.insert_new_line_before_catch_in_try_statement = true; this.insert_new_line_before_closing_brace_in_initializer_list = true; this.insert_new_line_before_else_in_if_statement = true; -// this.insert_new_line_before_finally_in_try_statement = true; this.insert_new_line_before_while_in_do_statement = true; this.insert_new_line_in_empty_block = true; // this.insert_new_line_in_empty_enum_declaration = true; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 12a1d383952..4335d6d62e3 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -531,4 +531,34 @@ public class CodeFormatterTest extends BaseUITestCase { Integer.toString(Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE | Alignment.M_INDENT_BY_ONE)); assertFormatterResult(); } + + //int foo(){try{}catch(...){}} + //float* bar(); + //templateclass basic_ios : public ios_base{public: + // // Types: + //}; + + //int + //foo() + //{ + // try + // { + // } + // catch (...) + // { + // } + //} + //float* + //bar(); + //template + // class basic_ios : public ios_base + // { + // public: + // // Types: + // }; + public void testGNUCodingStyleConformance_Bug192764() throws Exception { + fOptions= DefaultCodeFormatterOptions.getGNUSettings().getMap(); + assertFormatterResult(); + } + }