Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-04-04 08:11:04 +0000
committerAnton Leherbauer2008-04-04 08:11:04 +0000
commitfc2be4a64b56d589ea7fbf9118afec99639d7467 (patch)
tree9b590c0f161f7a8f4c02edbb21de1b3109ba1d4d /core/org.eclipse.cdt.core
parent97170d3d09f60496ef3002490601cbc533e17402 (diff)
downloadorg.eclipse.cdt-fc2be4a64b56d589ea7fbf9118afec99639d7467.tar.gz
org.eclipse.cdt-fc2be4a64b56d589ea7fbf9118afec99639d7467.tar.xz
org.eclipse.cdt-fc2be4a64b56d589ea7fbf9118afec99639d7467.zip
Fix for 225326: Code formatter strips whitespace when it shouldn't
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java51
1 files changed, 36 insertions, 15 deletions
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 f23842f833c..fb71249cb16 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
@@ -970,6 +970,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
// declarator
final IASTFunctionDeclarator declarator= node.getDeclarator();
+ skipNonWhitespaceToNode(declarator);
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
@@ -1523,6 +1524,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.space();
}
+ final int headerIndent= scribe.numberOfIndentations;
scribe.printNextToken(Token.t_enum, true);
final IASTName name= node.getName();
if (name != null) {
@@ -1532,20 +1534,23 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
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 (preferences.insert_new_line_after_opening_brace_in_enumerator_list) {
-// scribe.printNewLine();
-// }
-// if (preferences.insert_space_after_opening_brace_in_enumerator_list) {
-// scribe.space();
-// }
-
+ if (true /* preferences.insert_new_line_after_opening_brace_in_enumerator_list */) {
+ scribe.startNewLine();
+ } else if (true /* preferences.insert_space_after_opening_brace_in_enumerator_list */) {
+ scribe.space();
+ }
+ if (braceIndent == headerIndent) {
+ scribe.indent();
+ }
+ final int enumIndent= scribe.numberOfIndentations;
final IASTEnumerator[] enumerators= node.getEnumerators();
final ListAlignment align= new ListAlignment(preferences.alignment_for_enumerator_list);
align.fSpaceBeforeComma= preferences.insert_space_before_comma_in_enum_declarations;
align.fSpaceAfterComma= preferences.insert_space_after_comma_in_enum_declarations;
- align.fContinuationIndentation= 1;
+ align.fContinuationIndentation= enumIndent == headerIndent ? 1 : 0;
formatList(Arrays.asList(enumerators), align, false, false);
// handle trailing comma
@@ -1556,13 +1561,14 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
}
-// if (preferences.insert_new_line_before_closing_brace_in_enumerator_list) {
-// scribe.startNewLine();
-// }
-// if (preferences.insert_space_before_closing_brace_in_enumerator_list) {
-// scribe.space();
-// }
- scribe.startNewLine();
+ if (enumIndent > braceIndent) {
+ scribe.unIndent();
+ }
+ if (true /* preferences.insert_new_line_before_closing_brace_in_enumerator_list */) {
+ scribe.startNewLine();
+ } else if (true /* preferences.insert_space_before_closing_brace_in_enumerator_list */) {
+ scribe.space();
+ }
formatClosingBrace(preferences.brace_position_for_type_declaration);
return PROCESS_SKIP;
}
@@ -2858,6 +2864,21 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
}
+ private void skipNonWhitespaceToNode(IASTNode node) {
+ final IASTNodeLocation fileLocation= node.getFileLocation();
+ if (fileLocation != null) {
+ final int startOffset= fileLocation.getNodeOffset();
+ final int nextTokenOffset= getNextTokenOffset();
+ if (nextTokenOffset < startOffset) {
+ final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1;
+ final int restLength= startOffset - currentOffset;
+ if (restLength > 0) {
+ scribe.printRaw(currentOffset, restLength);
+ }
+ }
+ }
+ }
+
/**
* Format an expression nested in parenthesis. If the operand is
* <code>null</code>, empty parenthesis are expected.

Back to the top