Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/src/org/eclipse/cdt')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java78
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java72
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java48
3 files changed, 196 insertions, 2 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 a4cfe659344..2557328d2e5 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
@@ -2470,6 +2470,84 @@ public class DefaultCodeFormatterConstants {
+ ".formatter.insert_space_between_empty_parens_in_exception_specification"; //$NON-NLS-1$
/**
* <pre>
+ * FORMATTER / Option to insert a space before the opening bracket of the name list in a structured binding declaration
+ * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_opening_structured_binding_name_list"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.9
+ */
+ public static final String FORMATTER_INSERT_SPACE_BEFORE_OPENING_STRUCTURED_BINDING_NAME_LIST = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_space_before_opening_structured_binding_name_list"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to insert a space after the opening bracket of the name list in a structured binding declaration
+ * - option id: "org.eclipse.cdt.core.formatter.insert_space_after_opening_structured_binding_name_list"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: DO_NOT_INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.9
+ */
+ public static final String FORMATTER_INSERT_SPACE_AFTER_OPENING_STRUCTURED_BINDING_NAME_LIST = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_space_after_opening_structured_binding_name_list"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to insert a space before the closing bracket of the name list in a structured binding declaration
+ * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_closing_structured_binding_name_list"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: DO_NOT_INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.9
+ */
+ public static final String FORMATTER_INSERT_SPACE_BEFORE_CLOSING_STRUCTURED_BINDING_NAME_LIST = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_space_before_closing_structured_binding_name_list"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to insert a space before a comma in the name list of a structured binding declaration
+ * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_comma_in_structured_binding_name_list"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: DO_NOT_INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.9
+ */
+ public static final String FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_STRUCTURED_BINDING_NAME_LIST = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_space_before_comma_in_structured_binding_name_list"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to insert a space after a comma in the name list of a structured binding declaration
+ * - option id: "org.eclipse.cdt.core.formatter.insert_space_after_comma_in_structured_binding_name_list"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.9
+ */
+ public static final String FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_STRUCTURED_BINDING_NAME_LIST = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_space_after_comma_in_structured_binding_name_list"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to insert a space before a reference qualifier in a structured binding declaration
+ * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_ref_qualifier_in_structured_binding"
+ * - possible values: { INSERT, DO_NOT_INSERT }
+ * - default: INSERT
+ * </pre>
+ * @see CCorePlugin#INSERT
+ * @see CCorePlugin#DO_NOT_INSERT
+ * @since 6.9
+ */
+ public static final String FORMATTER_INSERT_SPACE_BEFORE_REF_QUALIFIER_IN_STRUCTURED_BINDING = CCorePlugin.PLUGIN_ID
+ + ".formatter.insert_space_before_ref_qualifier_in_structured_binding"; //$NON-NLS-1$
+ /**
+ * <pre>
* FORMATTER / Option to keep else statement on the same line
* - option id: "org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line"
* - possible values: { TRUE, FALSE }
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 2db0bbd1290..dc6868739f5 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
@@ -301,6 +301,18 @@ public class DefaultCodeFormatterOptions {
public boolean insert_space_between_empty_parens_in_method_declaration;
public boolean insert_space_between_empty_parens_in_method_invocation;
public boolean insert_space_between_empty_parens_in_exception_specification;
+ /** @since 6.9 */
+ public boolean insert_space_before_opening_structured_binding_name_list;
+ /** @since 6.9 */
+ public boolean insert_space_after_opening_structured_binding_name_list;
+ /** @since 6.9 */
+ public boolean insert_space_before_closing_structured_binding_name_list;
+ /** @since 6.9 */
+ public boolean insert_space_before_comma_in_structured_binding_name_list;
+ /** @since 6.9 */
+ public boolean insert_space_after_comma_in_structured_binding_name_list;
+ /** @since 6.9 */
+ public boolean insert_space_before_ref_qualifier_in_structured_binding;
public boolean compact_else_if;
public boolean keep_guardian_clause_on_one_line;
public boolean keep_else_statement_on_same_line;
@@ -788,6 +800,24 @@ public class DefaultCodeFormatterOptions {
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_EXCEPTION_SPECIFICATION,
this.insert_space_between_empty_parens_in_exception_specification ? CCorePlugin.INSERT
: CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_STRUCTURED_BINDING_NAME_LIST,
+ this.insert_space_before_opening_structured_binding_name_list ? CCorePlugin.INSERT
+ : CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_STRUCTURED_BINDING_NAME_LIST,
+ this.insert_space_after_opening_structured_binding_name_list ? CCorePlugin.INSERT
+ : CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_STRUCTURED_BINDING_NAME_LIST,
+ this.insert_space_before_closing_structured_binding_name_list ? CCorePlugin.INSERT
+ : CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_STRUCTURED_BINDING_NAME_LIST,
+ this.insert_space_before_comma_in_structured_binding_name_list ? CCorePlugin.INSERT
+ : CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_STRUCTURED_BINDING_NAME_LIST,
+ this.insert_space_after_comma_in_structured_binding_name_list ? CCorePlugin.INSERT
+ : CCorePlugin.DO_NOT_INSERT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_REF_QUALIFIER_IN_STRUCTURED_BINDING,
+ this.insert_space_before_ref_qualifier_in_structured_binding ? CCorePlugin.INSERT
+ : CCorePlugin.DO_NOT_INSERT);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMPACT_ELSE_IF,
this.compact_else_if ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_GUARDIAN_CLAUSE_ON_ONE_LINE,
@@ -2130,6 +2160,42 @@ public class DefaultCodeFormatterOptions {
this.insert_space_between_empty_parens_in_exception_specification = CCorePlugin.INSERT
.equals(insertSpaceBetweenEmptyParensInExceptionSpecificationOption);
}
+ final Object insertSpaceBeforeOpeningStructuredBindingNameList = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_STRUCTURED_BINDING_NAME_LIST);
+ if (insertSpaceBeforeOpeningStructuredBindingNameList != null) {
+ this.insert_space_before_opening_structured_binding_name_list = CCorePlugin.INSERT
+ .equals(insertSpaceBeforeOpeningStructuredBindingNameList);
+ }
+ final Object insertSpaceAfterOpeningStructuredBindingNameList = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_STRUCTURED_BINDING_NAME_LIST);
+ if (insertSpaceAfterOpeningStructuredBindingNameList != null) {
+ this.insert_space_after_opening_structured_binding_name_list = CCorePlugin.INSERT
+ .equals(insertSpaceAfterOpeningStructuredBindingNameList);
+ }
+ final Object insertSpaceBeforeClosingStructuredBindingNameList = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_STRUCTURED_BINDING_NAME_LIST);
+ if (insertSpaceBeforeClosingStructuredBindingNameList != null) {
+ this.insert_space_before_closing_structured_binding_name_list = CCorePlugin.INSERT
+ .equals(insertSpaceBeforeClosingStructuredBindingNameList);
+ }
+ final Object insertSpaceBeforeCommaInStructuredBindingNameList = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_STRUCTURED_BINDING_NAME_LIST);
+ if (insertSpaceBeforeCommaInStructuredBindingNameList != null) {
+ this.insert_space_before_comma_in_structured_binding_name_list = CCorePlugin.INSERT
+ .equals(insertSpaceBeforeCommaInStructuredBindingNameList);
+ }
+ final Object insertSpaceAfterCommaInStructuredBindingNameList = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_STRUCTURED_BINDING_NAME_LIST);
+ if (insertSpaceAfterCommaInStructuredBindingNameList != null) {
+ this.insert_space_after_comma_in_structured_binding_name_list = CCorePlugin.INSERT
+ .equals(insertSpaceAfterCommaInStructuredBindingNameList);
+ }
+ final Object insertSpaceBeforeRefQualifierInStructuredBinding = settings
+ .get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_REF_QUALIFIER_IN_STRUCTURED_BINDING);
+ if (insertSpaceBeforeRefQualifierInStructuredBinding != null) {
+ this.insert_space_before_ref_qualifier_in_structured_binding = CCorePlugin.INSERT
+ .equals(insertSpaceBeforeRefQualifierInStructuredBinding);
+ }
final Object compactElseIfOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMPACT_ELSE_IF);
if (compactElseIfOption != null) {
this.compact_else_if = DefaultCodeFormatterConstants.TRUE.equals(compactElseIfOption);
@@ -2441,6 +2507,12 @@ public class DefaultCodeFormatterOptions {
this.insert_space_between_empty_parens_in_method_declaration = false;
this.insert_space_between_empty_parens_in_method_invocation = false;
this.insert_space_between_empty_parens_in_exception_specification = false;
+ this.insert_space_before_opening_structured_binding_name_list = true;
+ this.insert_space_after_opening_structured_binding_name_list = false;
+ this.insert_space_before_closing_structured_binding_name_list = false;
+ this.insert_space_before_comma_in_structured_binding_name_list = false;
+ this.insert_space_after_comma_in_structured_binding_name_list = true;
+ this.insert_space_before_ref_qualifier_in_structured_binding = false;
this.compact_else_if = true;
this.keep_guardian_clause_on_one_line = false;
this.keep_else_statement_on_same_line = false;
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 40ecad720dd..af013b73cf7 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
@@ -131,6 +131,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
@@ -149,6 +150,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTStructuredBindingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
@@ -1948,7 +1950,48 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP;
}
+ private int visit(ICPPASTStructuredBindingDeclaration node) {
+ formatLeadingAttributes(node);
+ IASTDeclSpecifier declSpec = node.getDeclSpecifier();
+ declSpec.accept(this);
+
+ RefQualifier refQualifier = node.getRefQualifier();
+ if (refQualifier != null) {
+ int expectedToken = refQualifier == RefQualifier.LVALUE ? Token.tAMPER : Token.tAND;
+ if (peekNextToken() == expectedToken) {
+ scribe.printNextToken(expectedToken,
+ preferences.insert_space_before_ref_qualifier_in_structured_binding);
+ }
+ }
+
+ IASTInitializer initializer = node.getInitializer();
+ if (peekNextToken() == Token.tLBRACKET) {
+ List<IASTName> names = Arrays.asList(node.getNames());
+ final ListOptions options = new ListOptions(preferences.alignment_for_declarator_list);
+ options.leftToken = Token.tLBRACKET;
+ options.rightToken = Token.tRBRACKET;
+ options.fSpaceBeforeOpeningParen = preferences.insert_space_before_opening_structured_binding_name_list;
+ options.fSpaceAfterOpeningParen = preferences.insert_space_after_opening_structured_binding_name_list;
+ options.fSpaceBeforeClosingParen = preferences.insert_space_before_closing_structured_binding_name_list;
+ options.fSpaceAfterSeparator = preferences.insert_space_after_comma_in_structured_binding_name_list;
+ options.fSpaceBeforeSeparator = preferences.insert_space_before_comma_in_structured_binding_name_list;
+ formatList(names, options, true, false, null);
+ } else if (initializer != null) {
+ skipToNode(initializer);
+ }
+ if (initializer != null) {
+ initializer.accept(this);
+ }
+ if (fExpectSemicolonAfterDeclaration && peekNextToken() == Token.tSEMI) {
+ scribe.printNextToken(Token.tSEMI);
+ }
+ return PROCESS_SKIP;
+ }
+
private int visit(IASTSimpleDeclaration node) {
+ if (node instanceof ICPPASTStructuredBindingDeclaration) {
+ return visit((ICPPASTStructuredBindingDeclaration) node);
+ }
formatLeadingAttributes(node);
IASTDeclSpecifier declSpec = node.getDeclSpecifier();
declSpec.accept(this);
@@ -2585,11 +2628,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
private void formatInlineDeclaration(final IASTDeclaration decl) {
+ boolean previousExpectSemicolonAfterDeclaration = fExpectSemicolonAfterDeclaration;
fExpectSemicolonAfterDeclaration = false;
try {
decl.accept(this);
} finally {
- fExpectSemicolonAfterDeclaration = true;
+ fExpectSemicolonAfterDeclaration = previousExpectSemicolonAfterDeclaration;
}
}
@@ -3660,7 +3704,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.space();
}
IASTDeclaration declaration = node.getDeclaration();
- declaration.accept(this);
+ formatInlineDeclaration(declaration);
scribe.printNextToken(Token.tCOLON, true /* preferences.insert_space_before_colon_in_for */);
final IASTInitializerClause initializer = node.getInitializerClause();
if (true /*preferences.insert_space_after_colon_in_for*/) {

Back to the top