mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 08:46:02 +02:00
Fix for 204575: [Formatter] Odd indentation effect with access specifiers and class members
This commit is contained in:
parent
2ece943ed1
commit
af01f4320d
2 changed files with 67 additions and 1 deletions
|
@ -1058,6 +1058,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
|
||||
// storage class and other modifiers
|
||||
scribe.printModifiers();
|
||||
final int headerIndent= scribe.numberOfIndentations;
|
||||
|
||||
switch (node.getKey()) {
|
||||
case IASTCompositeTypeSpecifier.k_struct:
|
||||
|
@ -1087,6 +1088,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
// member declarations
|
||||
formatLeftCurlyBrace(line, preferences.brace_position_for_type_declaration);
|
||||
formatOpeningBrace(preferences.brace_position_for_type_declaration, preferences.insert_space_before_opening_brace_in_type_declaration);
|
||||
final int braceIndent= scribe.numberOfIndentations;
|
||||
if (braceIndent > headerIndent) {
|
||||
scribe.unIndent();
|
||||
}
|
||||
if (preferences.indent_access_specifier_compare_to_type_header) {
|
||||
scribe.indent();
|
||||
}
|
||||
|
@ -1118,6 +1123,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
if (preferences.indent_access_specifier_compare_to_type_header) {
|
||||
scribe.unIndent();
|
||||
}
|
||||
if (scribe.numberOfIndentations < braceIndent) {
|
||||
scribe.indent();
|
||||
}
|
||||
formatClosingBrace(preferences.brace_position_for_type_declaration);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1899,6 +1907,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
|
||||
private int visit(IASTSwitchStatement node) {
|
||||
final int headerIndent= scribe.numberOfIndentations;
|
||||
scribe.printNextToken(Token.t_switch);
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_switch);
|
||||
|
||||
|
@ -1914,7 +1923,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
String switch_brace = preferences.brace_position_for_switch;
|
||||
formatOpeningBrace(switch_brace, preferences.insert_space_before_opening_brace_in_switch);
|
||||
scribe.startNewLine();
|
||||
|
||||
final int braceIndent= scribe.numberOfIndentations;
|
||||
if (braceIndent > headerIndent) {
|
||||
scribe.unIndent();
|
||||
}
|
||||
if (preferences.indent_switchstatements_compare_to_switch) {
|
||||
scribe.indent();
|
||||
}
|
||||
|
@ -2029,6 +2041,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
if (preferences.indent_switchstatements_compare_to_switch) {
|
||||
scribe.unIndent();
|
||||
}
|
||||
if (scribe.numberOfIndentations < braceIndent) {
|
||||
scribe.indent();
|
||||
}
|
||||
scribe.startNewLine();
|
||||
|
||||
formatClosingBrace(switch_brace);
|
||||
|
|
|
@ -223,4 +223,55 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//class A {
|
||||
//public:
|
||||
//A();
|
||||
//};
|
||||
|
||||
//class A
|
||||
// {
|
||||
//public:
|
||||
// A();
|
||||
// };
|
||||
public void testWhiteSmithsAccessSpecifierIndentation1_Bug204575() throws Exception {
|
||||
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, DefaultCodeFormatterConstants.FALSE);
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, DefaultCodeFormatterConstants.TRUE);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//class A {
|
||||
//public:
|
||||
//A();
|
||||
//};
|
||||
|
||||
//class A
|
||||
// {
|
||||
// public:
|
||||
// A();
|
||||
// };
|
||||
public void testWhiteSmithsAccessSpecifierIndentation2_Bug204575() throws Exception {
|
||||
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, DefaultCodeFormatterConstants.TRUE);
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, DefaultCodeFormatterConstants.FALSE);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//class A {
|
||||
//public:
|
||||
//A();
|
||||
//};
|
||||
|
||||
//class A
|
||||
// {
|
||||
// public:
|
||||
// A();
|
||||
// };
|
||||
public void testWhiteSmithsAccessSpecifierIndentation3_Bug204575() throws Exception {
|
||||
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, DefaultCodeFormatterConstants.TRUE);
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, DefaultCodeFormatterConstants.TRUE);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue