From a75cc9c45a9a1f335cb3f75f0d9d3b7262ba3f07 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 15 Jan 2010 11:37:35 +0000 Subject: [PATCH] Bug 285901 - Format function does not work properly when define constant to type cast --- .../cdt/internal/formatter/CodeFormatterVisitor.java | 11 +++++++++-- .../eclipse/cdt/ui/tests/text/CodeFormatterTest.java | 9 +++++++++ 2 files changed, 18 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 43b7ed48ba1..824fd2cd283 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 @@ -1886,8 +1886,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.space(); } node.getTypeId().accept(this); - scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast); - if (preferences.insert_space_after_closing_paren_in_cast) { + try { + if (node.getTypeId().getTrailingSyntax().getType() == IToken.tRPAREN) { + scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast); + if (preferences.insert_space_after_closing_paren_in_cast) { + scribe.space(); + } + } + } catch (UnsupportedOperationException exc) { + } catch (ExpansionOverlapsBoundaryException exc) { scribe.space(); } // operand 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 a123209585b..867bbf608d3 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 @@ -1347,4 +1347,13 @@ public class CodeFormatterTest extends BaseUITestCase { public void testWideStringLiteral_Bug292626() throws Exception { assertFormatterResult(); } + + //#define INT (int) + //int i = INT 1; + + //#define INT (int) + //int i = INT 1; + public void testCastAsMacro_Bug285901() throws Exception { + assertFormatterResult(); + } }