Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-09 13:01:21 -0400
committerJonah Graham2019-04-09 16:21:20 -0400
commit290cb246b6d708e1634e3d07f0f929768ae2d9b1 (patch)
tree69df3f81bb6f24e1a736fb9f3f71969cd3bd1497 /core/org.eclipse.cdt.core
parent5131b86d9a1d56141ed7d884a656335fb60b271d (diff)
downloadorg.eclipse.cdt-290cb246b6d708e1634e3d07f0f929768ae2d9b1.tar.gz
org.eclipse.cdt-290cb246b6d708e1634e3d07f0f929768ae2d9b1.tar.xz
org.eclipse.cdt-290cb246b6d708e1634e3d07f0f929768ae2d9b1.zip
Bug 449394 - Fix constructor init list formatting
Init list was always on new lines regardless user input about new line policy or wrapping policy. Change-Id: I1ac85611129c23e89d9b299ca87ced314ad542f3 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java12
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java10
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java13
3 files changed, 31 insertions, 4 deletions
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 3dc6712fd0..8f34e1811c 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
@@ -934,6 +934,18 @@ public class DefaultCodeFormatterConstants {
+ ".formatter.insert_new_line_before_colon_in_constructor_initializer_list"; //$NON-NLS-1$
/**
* <pre>
+ * FORMATTER / Option to insert a new line after colon in constructor initializer list.
+ * - option id: "org.eclipse.cdt.core.formatter.formatter.insert_new_line_after_colon_in_constructor_initializer_list"
+ * - possible values: { DO_NOT_INSERT, INSERT }
+ * - default: DO_NOT_INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ */
+ public static final String FORMATTER_INSERT_NEW_LINE_AFTER_COLON_IN_CONSTRUCTOR_INITIALIZER_LIST = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_new_line_after_colon_in_constructor_initializer_list"; //$NON-NLS-1$
+ /**
+ * <pre>
* FORMATTER / Option to insert a new line before the else keyword in if statement
* - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement"
* - possible values: { INSERT, DO_NOT_INSERT }
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java
index cb7b71516c..8a58c083d9 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java
@@ -143,6 +143,7 @@ public class DefaultCodeFormatterOptions {
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_colon_in_constructor_initializer_list;
+ public boolean insert_new_line_after_colon_in_constructor_initializer_list;
public boolean insert_new_line_before_else_in_if_statement;
public boolean insert_new_line_before_while_in_do_statement;
public boolean insert_new_line_before_identifier_in_function_declaration;
@@ -436,6 +437,9 @@ public class DefaultCodeFormatterOptions {
DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_COLON_IN_CONSTRUCTOR_INITIALIZER_LIST,
this.insert_new_line_before_colon_in_constructor_initializer_list ? CCorePlugin.INSERT
: CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_COLON_IN_CONSTRUCTOR_INITIALIZER_LIST,
+ this.insert_new_line_after_colon_in_constructor_initializer_list ? CCorePlugin.INSERT
+ : CCorePlugin.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_WHILE_IN_DO_STATEMENT,
@@ -1322,6 +1326,12 @@ public class DefaultCodeFormatterOptions {
this.insert_new_line_before_closing_brace_in_initializer_list = CCorePlugin.INSERT
.equals(insertNewLineBeforeClosingBraceInInitializerListOption);
}
+ final Object insertNewLineAfterColonInConstructorInitializerListOption = settings.get(
+ DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_COLON_IN_CONSTRUCTOR_INITIALIZER_LIST);
+ if (insertNewLineAfterColonInConstructorInitializerListOption != null) {
+ this.insert_new_line_after_colon_in_constructor_initializer_list = CCorePlugin.INSERT
+ .equals(insertNewLineAfterColonInConstructorInitializerListOption);
+ }
final Object insertNewLineBeforeColonInConstructorInitializerListOption = settings.get(
DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_COLON_IN_CONSTRUCTOR_INITIALIZER_LIST);
if (insertNewLineBeforeColonInConstructorInitializerListOption != null) {
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 78dca997d4..307faf2735 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
@@ -1399,17 +1399,22 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
scribe.printNextToken(Token.tCOLON,
!preferences.insert_new_line_before_colon_in_constructor_initializer_list);
- if (preferences.insert_new_line_before_colon_in_constructor_initializer_list) {
+ if (!preferences.insert_new_line_after_colon_in_constructor_initializer_list) {
scribe.space();
- } else {
+ }
+ if (preferences.insert_new_line_after_colon_in_constructor_initializer_list) {
scribe.printTrailingComment();
scribe.startNewLine();
- scribe.indentForContinuation();
+ if (!preferences.insert_new_line_before_colon_in_constructor_initializer_list)
+ scribe.indentForContinuation();
}
final ListOptions options = new ListOptions(preferences.alignment_for_constructor_initializer_list);
options.fTieBreakRule = Alignment.R_OUTERMOST;
formatList(Arrays.asList(constructorChain), options, false, false, null);
- scribe.unIndentForContinuation();
+ if (preferences.insert_new_line_after_colon_in_constructor_initializer_list
+ || preferences.insert_new_line_before_colon_in_constructor_initializer_list) {
+ scribe.unIndentForContinuation();
+ }
}
if (cppFunctionDefinition.isDefaulted() || cppFunctionDefinition.isDeleted()) {

Back to the top