Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2010-01-14 14:36:01 +0000
committerAnton Leherbauer2010-01-14 14:36:01 +0000
commit511eec354d5c55ec616c19a79807f96d0338bd6e (patch)
tree2a503a6abe1f1c9945bf268e85365d2089c838f0
parent37bda68214b9b9c6ca1772c04577919f3782676f (diff)
downloadorg.eclipse.cdt-511eec354d5c55ec616c19a79807f96d0338bd6e.tar.gz
org.eclipse.cdt-511eec354d5c55ec616c19a79807f96d0338bd6e.tar.xz
org.eclipse.cdt-511eec354d5c55ec616c19a79807f96d0338bd6e.zip
Bug 298592 - Formatter causes wrong layout for #defines for classes with inheritance
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java15
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java10
2 files changed, 22 insertions, 3 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 e3e3b2ee517..4977b9aff1f 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
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Stack;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@@ -129,6 +130,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
+import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.internal.formatter.align.Alignment;
import org.eclipse.cdt.internal.formatter.align.AlignmentException;
import org.eclipse.cdt.internal.formatter.scanner.Scanner;
@@ -1450,9 +1452,16 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
// base specifiers
final List<ICPPASTBaseSpecifier> baseSpecifiers= Arrays.asList(node.getBaseSpecifiers());
if (baseSpecifiers.size() > 0) {
- scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_base_clause);
- if (preferences.insert_space_after_colon_in_base_clause) {
- scribe.space();
+ ICPPASTBaseSpecifier baseSpecifier = baseSpecifiers.get(0);
+ try {
+ if (baseSpecifier.getLeadingSyntax().getType() == IToken.tCOLON) {
+ scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_base_clause);
+ if (preferences.insert_space_after_colon_in_base_clause) {
+ scribe.space();
+ }
+ }
+ } catch (UnsupportedOperationException exc) {
+ } catch (ExpansionOverlapsBoundaryException exc) {
}
final ListAlignment align= new ListAlignment(preferences.alignment_for_base_clause_in_type_declaration);
align.fSpaceAfterComma= preferences.insert_space_after_comma_in_base_types;
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index 8ee066b26f8..68feb712ea5 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -1240,4 +1240,14 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
+ //#define MACRO(a) class b : public a
+ //MACRO(aClass){ int a;};
+
+ //#define MACRO(a) class b : public a
+ //MACRO(aClass) {
+ // int a;
+ //};
+ public void testCompositeTypeSpecAsMacro_Bug298592() throws Exception {
+ assertFormatterResult();
+ }
}

Back to the top