Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-05-26 04:26:32 -0400
committerMarco Stornelli2019-05-28 01:11:55 -0400
commita009b41021849d65c940e87112951cb4064723a3 (patch)
treed145cf194c6b0a44bcfe6088353119a12a14bddb /core/org.eclipse.cdt.core
parentdc62eb218dc16e5a422b6a343b42003bba78067f (diff)
downloadorg.eclipse.cdt-a009b41021849d65c940e87112951cb4064723a3.tar.gz
org.eclipse.cdt-a009b41021849d65c940e87112951cb4064723a3.tar.xz
org.eclipse.cdt-a009b41021849d65c940e87112951cb4064723a3.zip
Bug 268404 - Added options for label formatting
Change-Id: I192ede1c17d2b1929dcb6fb33158eb7628707598 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.java28
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java32
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java9
3 files changed, 68 insertions, 1 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 addd2a1d6a..8be16e9d2a 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
@@ -776,6 +776,21 @@ public class DefaultCodeFormatterConstants {
*/
public static final String FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_LINKAGE = CCorePlugin.PLUGIN_ID
+ ".formatter.indent_body_declarations_compare_to_linkage"; //$NON-NLS-1$
+
+ /**
+ * <pre>
+ * FORMATTER / Option to indent labels compare to statements where it is defined
+ * - option id: "org.eclipse.cdt.core.formatter.indent_label_compare_to_statements"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * @see #TRUE
+ * @see #FALSE
+ * @since 6.8
+ */
+ public static final String FORMATTER_INDENT_LABEL_COMPARE_TO_STATEMENTS = CCorePlugin.PLUGIN_ID
+ + ".formatter.indent_label_compare_to_statements"; //$NON-NLS-1$
+
/**
* <pre>
* FORMATTER / Option to indent breaks compare to cases
@@ -885,6 +900,19 @@ public class DefaultCodeFormatterConstants {
+ ".formatter.insert_new_line_after_opening_brace_in_array_initializer";//$NON-NLS-1$
/**
* <pre>
+ * FORMATTER / Option to insert a new line after a label
+ * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_after_label"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: DO_NOT_INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.8
+ */
+ public static final String FORMATTER_INSERT_NEW_LINE_AFTER_LABEL = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_new_line_after_label";//$NON-NLS-1$
+ /**
+ * <pre>
* 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 }
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 b6f77b62e3..6a21ac31e0 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
@@ -139,6 +139,10 @@ public class DefaultCodeFormatterOptions {
public boolean indent_empty_lines;
public boolean indent_switchstatements_compare_to_cases;
public boolean indent_switchstatements_compare_to_switch;
+ /**
+ * @since 6.8
+ */
+ public boolean indent_label_compare_to_statements;
public int indentation_size;
public boolean insert_new_line_after_opening_brace_in_initializer_list;
@@ -155,6 +159,10 @@ public class DefaultCodeFormatterOptions {
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;
+ /**
+ * @since 6.8
+ */
+ public boolean insert_new_line_after_label;
// public boolean insert_new_line_in_empty_method_body;
// public boolean insert_new_line_in_empty_type_declaration;
public boolean insert_space_after_assignment_operator;
@@ -442,6 +450,9 @@ public class DefaultCodeFormatterOptions {
options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_LINKAGE,
this.indent_body_declarations_compare_to_linkage ? DefaultCodeFormatterConstants.TRUE
: DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_LABEL_COMPARE_TO_STATEMENTS,
+ this.indent_label_compare_to_statements ? DefaultCodeFormatterConstants.TRUE
+ : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BREAKS_COMPARE_TO_CASES,
this.indent_breaks_compare_to_cases ? DefaultCodeFormatterConstants.TRUE
: DefaultCodeFormatterConstants.FALSE);
@@ -457,6 +468,8 @@ public class DefaultCodeFormatterOptions {
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_LABEL,
+ this.insert_new_line_after_label ? 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,
@@ -1321,6 +1334,12 @@ public class DefaultCodeFormatterOptions {
this.indent_body_declarations_compare_to_linkage = DefaultCodeFormatterConstants.TRUE
.equals(indentBodyDeclarationsCompareToLinkageOption);
}
+ final Object indentLabelCompareToStatementsOptions = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INDENT_LABEL_COMPARE_TO_STATEMENTS);
+ if (indentLabelCompareToStatementsOptions != null) {
+ this.indent_label_compare_to_statements = DefaultCodeFormatterConstants.TRUE
+ .equals(indentLabelCompareToStatementsOptions);
+ }
final Object indentBreaksCompareToCasesOption = settings
.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_BREAKS_COMPARE_TO_CASES);
if (indentBreaksCompareToCasesOption != null) {
@@ -1359,6 +1378,11 @@ public class DefaultCodeFormatterOptions {
this.insert_new_line_after_opening_brace_in_initializer_list = CCorePlugin.INSERT
.equals(insertNewLineAfterOpeningBraceInInitializerListOption);
}
+ final Object insertNewLineAfterLabelOption = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL);
+ if (insertNewLineAfterLabelOption != null) {
+ this.insert_new_line_after_label = CCorePlugin.INSERT.equals(insertNewLineAfterLabelOption);
+ }
final Object insertNewLineAfterTemplateDeclarationOption = settings
.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_TEMPLATE_DECLARATION);
if (insertNewLineAfterOpeningBraceInInitializerListOption != null) {
@@ -2253,6 +2277,7 @@ 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_linkage = false;
+ this.indent_label_compare_to_statements = true;
// 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;
@@ -2268,6 +2293,7 @@ public class DefaultCodeFormatterOptions {
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_after_label = false;
// this.insert_new_line_in_empty_method_body = true;
// this.insert_new_line_in_empty_type_declaration = true;
this.insert_space_after_assignment_operator = true;
@@ -2453,6 +2479,7 @@ 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_linkage = false;
+ this.indent_label_compare_to_statements = true;
// this.indent_body_declarations_compare_to_enum_declaration_header = true;
this.indent_breaks_compare_to_cases = true;
this.indent_empty_lines = false;
@@ -2465,6 +2492,7 @@ public class DefaultCodeFormatterOptions {
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_in_empty_block = true;
+ this.insert_new_line_after_label = false;
// 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;
@@ -2518,6 +2546,7 @@ public class DefaultCodeFormatterOptions {
this.indent_statements_compare_to_body = true;
this.indent_body_declarations_compare_to_namespace_header = true;
this.indent_body_declarations_compare_to_linkage = true;
+ this.indent_label_compare_to_statements = false;
// this.indent_body_declarations_compare_to_enum_declaration_header = true;
this.indent_declaration_compare_to_template_header = true;
this.indent_breaks_compare_to_cases = true;
@@ -2537,6 +2566,7 @@ public class DefaultCodeFormatterOptions {
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_after_label = false;
// 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;
@@ -2596,6 +2626,7 @@ public class DefaultCodeFormatterOptions {
this.indent_statements_compare_to_body = false;
this.indent_body_declarations_compare_to_namespace_header = false;
this.indent_body_declarations_compare_to_linkage = false;
+ this.indent_label_compare_to_statements = true;
this.indent_breaks_compare_to_cases = true;
this.indent_empty_lines = false;
this.indent_switchstatements_compare_to_cases = true;
@@ -2609,6 +2640,7 @@ public class DefaultCodeFormatterOptions {
this.insert_new_line_before_else_in_if_statement = true;
this.insert_new_line_before_while_in_do_statement = true;
this.insert_new_line_in_empty_block = true;
+ this.insert_new_line_after_label = false;
// 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;
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 d6518351cf..8de7f59fa7 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
@@ -3912,13 +3912,20 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
private int visit(IASTLabelStatement node) {
- // TLETODO [formatter] label indentation
+ int indentationLevel = scribe.indentationLevel;
+ if (!preferences.indent_label_compare_to_statements) {
+ scribe.indentationLevel = 0;
+ }
formatLeadingAttributes(node);
node.getName().accept(this);
scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_labeled_statement);
if (preferences.insert_space_after_colon_in_labeled_statement) {
scribe.space();
}
+ if (preferences.insert_new_line_after_label) {
+ scribe.startNewLine();
+ }
+ scribe.indentationLevel = indentationLevel;
node.getNestedStatement().accept(this);
return PROCESS_SKIP;
}

Back to the top