From 63365064b74c95a1201e20bcb8f56ac8acb6bab8 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 3 Nov 2010 11:16:26 +0000 Subject: [PATCH] Bug 329165 - Formatter corrupts code --- .../formatter/CodeFormatterVisitor.java | 10 ++++++++-- .../cdt/ui/tests/text/CodeFormatterTest.java | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 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 3ecf4a8a278..2b6728147cc 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 @@ -1063,15 +1063,19 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, private int visit(ICPPASTFunctionDeclarator node) { visit((IASTStandardFunctionDeclarator)node); - skipConstVolatileRestrict(); - + boolean needSpace = skipConstVolatileRestrict(); + final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification(); if (exceptionSpecification != null) { if (peekNextToken() == Token.t_throw) { formatExceptionSpecification(exceptionSpecification); + needSpace = false; } } // skip the rest (=0) + if (needSpace && scribe.printComment()) { + scribe.space(); + } skipNode(node); return PROCESS_SKIP; } @@ -1512,6 +1516,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } finally { endOfNode(declaration); } + } else { + skipNode(declaration); } if (preferences.indent_body_declarations_compare_to_access_specifier) { scribe.unIndent(); 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 86d09d68147..f26f87e6cf7 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 @@ -1382,6 +1382,25 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + ////#define throws /* */ + //struct Foo { + // void foo() const throws { + // } + // void bar() const throws { + // } + //}; + + ////#define throws /* */ + //struct Foo { + // void foo() const throws { + // } + // void bar() const throws { + // } + //}; + public void testCodeCorruptionWithIllegalKeyword_Bug329165() throws Exception { + assertFormatterResult(); + } + //void extend_terminal_bond_to_label(vector &atom, const vector &letters, int n_letters, const vector &bond, int n_bond, const vector &label, int n_label, double avg, double maxh, double max_dist_double_bond); //void extend_terminal_bond_to_label(vector &atom,